Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GlobalRef of Core.CodeInfo in @generated #43823

Merged
merged 2 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,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")
simeonschaub marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -2981,6 +2981,21 @@ end
@generated g25678(x) = return :x
@test g25678(7) === 7

# 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 #19012
@test Meta.parse("\U2200", raise=false) == Symbol("∀")
@test Meta.parse("\U2203", raise=false) == Symbol("∃")
Expand Down