Skip to content

Commit 7b64cec

Browse files
authored
Fix lowering failure with type parameter in opaque closure (#58307)
1 parent 1237a9c commit 7b64cec

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
@@ -2599,11 +2599,13 @@
25992599
(typ-svec (caddr sig-svec))
26002600
(tvars (cddr (cadddr sig-svec)))
26012601
(argtypes (cdddr typ-svec))
2602-
(functionloc (cadr (caddddr sig-svec))))
2603-
(let* ((argtype (foldl (lambda (var ex) `(call (core UnionAll) ,var ,ex))
2604-
(expand-forms `(curly (core Tuple) ,@argtypes))
2605-
(reverse tvars))))
2606-
`(_opaque_closure ,(or argt argtype) ,rt_lb ,rt_ub ,isva ,(length argtypes) ,allow-partial ,functionloc ,lam))))
2602+
(functionloc (cadr (caddddr sig-svec)))
2603+
(argtype (foldl (lambda (var ex) `(call (core UnionAll) ,var ,ex))
2604+
(expand-forms `(curly (core Tuple) ,@argtypes))
2605+
(reverse tvars)))
2606+
(argtype (or argt argtype))
2607+
(argtype (if (null? stmts) argtype `(block ,@stmts ,argtype))))
2608+
`(_opaque_closure ,argtype ,rt_lb ,rt_ub ,isva ,(length argtypes) ,allow-partial ,functionloc ,lam)))
26072609

26082610
'block
26092611
(lambda (e)
@@ -5232,6 +5234,14 @@ f(x) = yt(x)
52325234
(define (set-lineno! lineinfo num)
52335235
(set-car! (cddr lineinfo) num))
52345236

5237+
;; note that the 'list and 'block atoms make all lists 1-indexed.
5238+
;; returns a 5-element vector containing:
5239+
;; code: `(block ,@(n expressions))
5240+
;; locs: list of line-table index, where code[i] has lineinfo line-table[locs[i]]
5241+
;; line-table: list of `(lineinfo file.jl 123 0)'
5242+
;; ssavalue-table: table of (ssa-num . code-index)
5243+
;; where ssavalue references in `code` need this remapping
5244+
;; label-table: table of (label . code-index)
52355245
(define (compact-ir body file line)
52365246
(let ((code '(block))
52375247
(locs '(list))
@@ -5338,7 +5348,7 @@ f(x) = yt(x)
53385348
e)
53395349
((ssavalue? e)
53405350
(let ((idx (get ssavalue-table (cadr e) #f)))
5341-
(if (not idx) (begin (prn e) (prn lam) (error "ssavalue with no def")))
5351+
(if (not idx) (error "internal bug: ssavalue with no def"))
53425352
`(ssavalue ,idx)))
53435353
((eq? (car e) 'goto)
53445354
`(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)