Skip to content

Commit

Permalink
Use GlobalRef of Core.CodeInfo in @generated (#43823)
Browse files Browse the repository at this point in the history
Co-authored-by: Simeon Schaub <schaub@mit.edu>
(cherry picked from commit 8536522)
  • Loading branch information
devmotion authored and staticfloat committed Dec 22, 2022
1 parent 0918b98 commit 9ae969d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,16 @@ macro generated(f)
if isa(f, Expr) && (f.head === :function || is_short_function_def(f))
body = f.args[2]
lno = body.args[1]
tmp = gensym("tmp")
return Expr(:escape,
Expr(f.head, f.args[1],
Expr(:block,
lno,
Expr(:if, Expr(:generated),
# https://github.com/JuliaLang/julia/issues/25678
Expr(:block,
:(local tmp = $body),
:(if tmp isa Core.CodeInfo; return tmp; else tmp; end)),
:(local $tmp = $body),
:(if $tmp isa $(GlobalRef(Core, :CodeInfo)); return $tmp; else $tmp; end)),
Expr(:block,
Expr(:meta, :generated_only),
Expr(:return, nothing))))))
Expand Down
15 changes: 15 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,21 @@ end
@eval f39705(x) = $(Expr(:||)) && x
@test f39705(1) === false

# issue 25678: module of name `Core`
# https://github.com/JuliaLang/julia/pull/40778/files#r784416018
@test @eval Module() begin
Core = 1
@generated f() = 1
f() == 1
end

# issue 25678: argument of name `tmp`
# https://github.com/JuliaLang/julia/pull/43823#discussion_r785365312
@test @eval Module() begin
@generated f(tmp) = tmp
f(1) === Int
end

# issue 42220
macro m42220()
return quote
Expand Down

0 comments on commit 9ae969d

Please sign in to comment.