Skip to content

Commit

Permalink
lowering: preserve handler order in (pop-handler-list ...)
Browse files Browse the repository at this point in the history
This was reversing the list of handlers on accident.
  • Loading branch information
topolarity committed Sep 25, 2024
1 parent 2943833 commit 0e7d9ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4436,15 +4436,16 @@ f(x) = yt(x)
(define (pop-handler-list src-tokens dest-tokens lab)
(if (eq? src-tokens dest-tokens)
#f
(let loop ((s src-tokens)
(l '()))
(if (not (pair? s))
(if (null? lab)
(error "Attempt to jump into catch block")
(error (string "cannot goto label \"" lab "\" inside try/catch block"))))
(if (eq? (cdr s) dest-tokens)
(cons (car s) l)
(loop (cdr s) (cons (car s) l))))))
(reverse
(let loop ((s src-tokens)
(l '()))
(if (not (pair? s))
(if (null? lab)
(error "Attempt to jump into catch block")
(error (string "cannot goto label \"" lab "\" inside try/catch block"))))
(if (eq? (cdr s) dest-tokens)
(cons (car s) l)
(loop (cdr s) (cons (car s) l)))))))
(define (emit-return tail x)
(define (emit- x)
(let* ((tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x)
Expand Down
23 changes: 23 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3865,6 +3865,29 @@ end
end
end

let src = Meta.@lower let
try
try
return 1
catch
end
finally
nothing
end
end
code = src.args[1].code
for stmt in code
if Meta.isexpr(stmt, :leave) && length(stmt.args) > 1
# Expr(:leave, ...) should list the arguments to pop from
# inner-most scope to outer-most
@test issorted(Int[
(arg::Core.SSAValue).id
for arg in stmt.args
]; rev=true)
end
end
end

# Test that globals can be `using`'d even if they are not yet defined
module UndefGlobal54954
global theglobal54954::Int
Expand Down

0 comments on commit 0e7d9ce

Please sign in to comment.