From 2b0fe937ad40f78549b29c04a0f6366da50c19f6 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 25 Sep 2024 11:27:36 -0400 Subject: [PATCH] lowering: preserve handler order in `(pop-handler-list ...)` This was reversing the list of handlers on accident. --- src/julia-syntax.scm | 4 ++-- test/syntax.jl | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index f1acb9c3250e1..d9df5705a6d37 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -4443,8 +4443,8 @@ f(x) = yt(x) (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)))))) + (append l (car s)) + (loop (cdr s) (append l (car s))))))) (define (emit-return tail x) (define (emit- x) (let* ((tmp (if ((if (null? catch-token-stack) valid-ir-return? simple-atom?) x) diff --git a/test/syntax.jl b/test/syntax.jl index c19721b5c54b3..1f9d1d592931b 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -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