Skip to content

Commit 18dd371

Browse files
mlechuKristofferC
authored andcommitted
Fix lowering failure with type parameter in opaque closure (#58307)
(cherry picked from commit 7b64cec)
1 parent 331cb3f commit 18dd371

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/julia-syntax.scm

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,11 +2583,13 @@
25832583
(typ-svec (caddr sig-svec))
25842584
(tvars (cddr (cadddr sig-svec)))
25852585
(argtypes (cdddr typ-svec))
2586-
(functionloc (cadr (caddddr sig-svec))))
2587-
(let* ((argtype (foldl (lambda (var ex) `(call (core UnionAll) ,var ,ex))
2588-
(expand-forms `(curly (core Tuple) ,@argtypes))
2589-
(reverse tvars))))
2590-
`(_opaque_closure ,(or argt argtype) ,rt_lb ,rt_ub ,isva ,(length argtypes) ,allow-partial ,functionloc ,lam))))
2586+
(functionloc (cadr (caddddr sig-svec)))
2587+
(argtype (foldl (lambda (var ex) `(call (core UnionAll) ,var ,ex))
2588+
(expand-forms `(curly (core Tuple) ,@argtypes))
2589+
(reverse tvars)))
2590+
(argtype (or argt argtype))
2591+
(argtype (if (null? stmts) argtype `(block ,@stmts ,argtype))))
2592+
`(_opaque_closure ,argtype ,rt_lb ,rt_ub ,isva ,(length argtypes) ,allow-partial ,functionloc ,lam)))
25912593

25922594
'block
25932595
(lambda (e)
@@ -5175,6 +5177,14 @@ f(x) = yt(x)
51755177
(define (set-lineno! lineinfo num)
51765178
(set-car! (cddr lineinfo) num))
51775179

5180+
;; note that the 'list and 'block atoms make all lists 1-indexed.
5181+
;; returns a 5-element vector containing:
5182+
;; code: `(block ,@(n expressions))
5183+
;; locs: list of line-table index, where code[i] has lineinfo line-table[locs[i]]
5184+
;; line-table: list of `(lineinfo file.jl 123 0)'
5185+
;; ssavalue-table: table of (ssa-num . code-index)
5186+
;; where ssavalue references in `code` need this remapping
5187+
;; label-table: table of (label . code-index)
51785188
(define (compact-ir body file line)
51795189
(let ((code '(block))
51805190
(locs '(list))
@@ -5281,7 +5291,7 @@ f(x) = yt(x)
52815291
e)
52825292
((ssavalue? e)
52835293
(let ((idx (get ssavalue-table (cadr e) #f)))
5284-
(if (not idx) (begin (prn e) (prn lam) (error "ssavalue with no def")))
5294+
(if (not idx) (error "internal bug: ssavalue with no def"))
52855295
`(ssavalue ,idx)))
52865296
((eq? (car e) 'goto)
52875297
`(goto ,(get label-table (cadr e))))

test/opaque_closure.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,6 @@ let f = f54357(+, Tuple{Int,Int})
407407
@test g isa Core.OpaqueClosure
408408
@test g(32.0, 34.0) === 66.0
409409
end
410+
411+
# 49659: signature-scoped typevar shouldn't fail in lowering
412+
@test_throws "must be a tuple type" @opaque ((x::T,y::T) where {T}) -> 123

0 commit comments

Comments
 (0)