Skip to content

Commit 602e5df

Browse files
authored
Fix conversion from K"meta" to Expr (#60163)
A small tweak: JuliaLowering uses quoted symbols in meta forms, where Expr does not. Miscellaneous test fixes are also included (`CompileHints` was overwriting a constructor, and `isdefined(Core, :_lower)` isn't so necessary in this repository)
1 parent 625e8c7 commit 602e5df

File tree

6 files changed

+49
-50
lines changed

6 files changed

+49
-50
lines changed

JuliaLowering/src/ast.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,6 @@ end
538538
# the middle of a pass.
539539
const CompileHints = Base.ImmutableDict{Symbol,Any}
540540

541-
function CompileHints(d::Dict{Symbol, Any})
542-
id = CompileHints()
543-
for (k, v) in d
544-
id = CompileHints(id, k, v)
545-
end
546-
id
547-
end
548-
549541
function setmeta!(ex::SyntaxTree; kws...)
550542
@assert length(kws) == 1 # todo relax later ?
551543
key = first(keys(kws))

JuliaLowering/src/kinds.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ function _register_kinds()
2121
"Symbol"
2222
# QuoteNode; not quasiquote
2323
"inert"
24-
# Compiler metadata hints
25-
"meta"
2624
# TODO: Use `meta` for inbounds and loopinfo etc?
2725
"inbounds"
2826
"boundscheck"

JuliaLowering/src/linear_ir.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,12 @@ function compile_lambda(outer_ctx, ex)
11031103
slot_rewrites[id] = i
11041104
end
11051105
code = renumber_body(ctx, ctx.code, slot_rewrites)
1106+
meta = CompileHints()
1107+
for (k, v) in ctx.meta
1108+
meta = CompileHints(meta, k, v)
1109+
end
11061110
@ast ctx ex [K"code_info"(is_toplevel_thunk=ex.is_toplevel_thunk,
1107-
slots=slots, meta=CompileHints(ctx.meta))
1111+
slots=slots, meta=meta)
11081112
[K"block"(ex[3])
11091113
code...
11101114
]

JuliaLowering/test/hooks.jl

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,46 @@ const JL = JuliaLowering
2424
@test Core.eval(test_mod, lwr) === 2
2525
end
2626

27-
if isdefined(Core, :_lower)
28-
function jeval(str)
29-
prog = parseall(Expr, str)
30-
local out
31-
try
32-
JL.activate!()
33-
out = Core.eval(test_mod, prog)
34-
finally
35-
JL.activate!(false)
36-
end
27+
function jeval(str)
28+
prog = parseall(Expr, str)
29+
local out
30+
try
31+
JL.activate!()
32+
out = Core.eval(test_mod, prog)
33+
finally
34+
JL.activate!(false)
3735
end
38-
@testset "integration: `JuliaLowering.activate!`" begin
39-
out = jeval("global asdf = 1")
40-
@test out === 1
41-
@test isdefined(test_mod, :asdf)
36+
end
37+
@testset "integration: `JuliaLowering.activate!`" begin
38+
out = jeval("global asdf = 1")
39+
@test out === 1
40+
@test isdefined(test_mod, :asdf)
4241

43-
out = jeval("module M; x = 1; end")
44-
@test out isa Module
45-
@test isdefined(test_mod, :M)
46-
@test isdefined(test_mod.M, :x)
42+
out = jeval("module M; x = 1; end")
43+
@test out isa Module
44+
@test isdefined(test_mod, :M)
45+
@test isdefined(test_mod.M, :x)
4746

48-
@test jeval("@ccall jl_value_ptr(nothing::Any)::Ptr{Cvoid}") isa Ptr{Cvoid}
47+
@test jeval("@ccall jl_value_ptr(nothing::Any)::Ptr{Cvoid}") isa Ptr{Cvoid}
4948

50-
# Tricky cases with symbols
51-
out = jeval("""module M2
49+
# Tricky cases with symbols
50+
out = jeval("""module M2
5251
Base.@constprop :aggressive function f(x); x; end
5352
const what = ccall(:jl_value_ptr, Ptr{Cvoid}, (Any,), Core.nothing)
5453
end""")
55-
@test out isa Module
56-
@test isdefined(test_mod, :M2)
57-
@test isdefined(test_mod.M2, :f)
58-
@test isdefined(test_mod.M2, :what)
54+
@test out isa Module
55+
@test isdefined(test_mod, :M2)
56+
@test isdefined(test_mod.M2, :f)
57+
@test isdefined(test_mod.M2, :what)
5958

60-
out = jeval(""" "docstring" module M3 end """)
61-
@test out isa Module
62-
@test isdefined(test_mod, :M3)
59+
out = jeval(""" "docstring" module M3 end """)
60+
@test out isa Module
61+
@test isdefined(test_mod, :M3)
6362

64-
# Macros may produce toplevel expressions. Note that julia handles
65-
# this case badly (macro expansion replaces M5_inner with a
66-
# globalref) and we handle esc(:M5_inner) badly
67-
out = jeval("""module M5
63+
# Macros may produce toplevel expressions. Note that julia handles
64+
# this case badly (macro expansion replaces M5_inner with a
65+
# globalref) and we handle esc(:M5_inner) badly
66+
out = jeval("""module M5
6867
macro newmod()
6968
return quote
7069
let a = 1
@@ -76,13 +75,11 @@ const JL = JuliaLowering
7675
end
7776
@newmod()
7877
end""")
79-
@test out isa Module
80-
@test isdefined(test_mod, :M5)
81-
@test isdefined(test_mod.M5, :M5_inner)
82-
@test isdefined(test_mod.M5.M5_inner, :asdf)
78+
@test out isa Module
79+
@test isdefined(test_mod, :M5)
80+
@test isdefined(test_mod.M5, :M5_inner)
81+
@test isdefined(test_mod.M5.M5_inner, :asdf)
8382

84-
# TODO: broken, commented to prevent error logging
85-
# @test jeval("Base.@propagate_inbounds @inline meta_double_quote_issue(x) = x") isa Function
86-
end
83+
@test jeval("Base.@propagate_inbounds @inline meta_double_quote_issue(x) = x") isa Function
8784
end
8885
end

JuliaSyntax/src/integration/expr.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@ end
634634
args[i] = Symbol(".", arg.args[1])
635635
end
636636
end
637+
elseif k == K"meta"
638+
# Expr uses plain identifiers, but JuliaSyntax uses quoted (Symbol) identifiers
639+
for (i, a) in enumerate(args)
640+
if a isa QuoteNode && a.value isa Symbol
641+
args[i] = a.value
642+
end
643+
end
637644
end
638645

639646
return retexpr

JuliaSyntax/src/julia/kinds.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ register_kinds!(JuliaSyntax, 0, [
10321032
"vect"
10331033
"parens"
10341034
"importpath"
1035+
"meta"
10351036
# Concatenation syntax
10361037
"braces"
10371038
"bracescat"

0 commit comments

Comments
 (0)