Skip to content
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
8 changes: 0 additions & 8 deletions JuliaLowering/src/ast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,6 @@ end
# the middle of a pass.
const CompileHints = Base.ImmutableDict{Symbol,Any}

function CompileHints(d::Dict{Symbol, Any})
id = CompileHints()
for (k, v) in d
id = CompileHints(id, k, v)
end
id
end

function setmeta!(ex::SyntaxTree; kws...)
@assert length(kws) == 1 # todo relax later ?
key = first(keys(kws))
Expand Down
2 changes: 0 additions & 2 deletions JuliaLowering/src/kinds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ function _register_kinds()
"Symbol"
# QuoteNode; not quasiquote
"inert"
# Compiler metadata hints
"meta"
# TODO: Use `meta` for inbounds and loopinfo etc?
"inbounds"
"boundscheck"
Expand Down
6 changes: 5 additions & 1 deletion JuliaLowering/src/linear_ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,12 @@ function compile_lambda(outer_ctx, ex)
slot_rewrites[id] = i
end
code = renumber_body(ctx, ctx.code, slot_rewrites)
meta = CompileHints()
for (k, v) in ctx.meta
meta = CompileHints(meta, k, v)
end
@ast ctx ex [K"code_info"(is_toplevel_thunk=ex.is_toplevel_thunk,
slots=slots, meta=CompileHints(ctx.meta))
slots=slots, meta=meta)
[K"block"(ex[3])
code...
]
Expand Down
75 changes: 36 additions & 39 deletions JuliaLowering/test/hooks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,46 @@ const JL = JuliaLowering
@test Core.eval(test_mod, lwr) === 2
end

if isdefined(Core, :_lower)
function jeval(str)
prog = parseall(Expr, str)
local out
try
JL.activate!()
out = Core.eval(test_mod, prog)
finally
JL.activate!(false)
end
function jeval(str)
prog = parseall(Expr, str)
local out
try
JL.activate!()
out = Core.eval(test_mod, prog)
finally
JL.activate!(false)
end
@testset "integration: `JuliaLowering.activate!`" begin
out = jeval("global asdf = 1")
@test out === 1
@test isdefined(test_mod, :asdf)
end
@testset "integration: `JuliaLowering.activate!`" begin
out = jeval("global asdf = 1")
@test out === 1
@test isdefined(test_mod, :asdf)

out = jeval("module M; x = 1; end")
@test out isa Module
@test isdefined(test_mod, :M)
@test isdefined(test_mod.M, :x)
out = jeval("module M; x = 1; end")
@test out isa Module
@test isdefined(test_mod, :M)
@test isdefined(test_mod.M, :x)

@test jeval("@ccall jl_value_ptr(nothing::Any)::Ptr{Cvoid}") isa Ptr{Cvoid}
@test jeval("@ccall jl_value_ptr(nothing::Any)::Ptr{Cvoid}") isa Ptr{Cvoid}

# Tricky cases with symbols
out = jeval("""module M2
# Tricky cases with symbols
out = jeval("""module M2
Base.@constprop :aggressive function f(x); x; end
const what = ccall(:jl_value_ptr, Ptr{Cvoid}, (Any,), Core.nothing)
end""")
@test out isa Module
@test isdefined(test_mod, :M2)
@test isdefined(test_mod.M2, :f)
@test isdefined(test_mod.M2, :what)
@test out isa Module
@test isdefined(test_mod, :M2)
@test isdefined(test_mod.M2, :f)
@test isdefined(test_mod.M2, :what)

out = jeval(""" "docstring" module M3 end """)
@test out isa Module
@test isdefined(test_mod, :M3)
out = jeval(""" "docstring" module M3 end """)
@test out isa Module
@test isdefined(test_mod, :M3)

# Macros may produce toplevel expressions. Note that julia handles
# this case badly (macro expansion replaces M5_inner with a
# globalref) and we handle esc(:M5_inner) badly
out = jeval("""module M5
# Macros may produce toplevel expressions. Note that julia handles
# this case badly (macro expansion replaces M5_inner with a
# globalref) and we handle esc(:M5_inner) badly
out = jeval("""module M5
macro newmod()
return quote
let a = 1
Expand All @@ -76,13 +75,11 @@ const JL = JuliaLowering
end
@newmod()
end""")
@test out isa Module
@test isdefined(test_mod, :M5)
@test isdefined(test_mod.M5, :M5_inner)
@test isdefined(test_mod.M5.M5_inner, :asdf)
@test out isa Module
@test isdefined(test_mod, :M5)
@test isdefined(test_mod.M5, :M5_inner)
@test isdefined(test_mod.M5.M5_inner, :asdf)

# TODO: broken, commented to prevent error logging
# @test jeval("Base.@propagate_inbounds @inline meta_double_quote_issue(x) = x") isa Function
end
@test jeval("Base.@propagate_inbounds @inline meta_double_quote_issue(x) = x") isa Function
end
end
7 changes: 7 additions & 0 deletions JuliaSyntax/src/integration/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ end
args[i] = Symbol(".", arg.args[1])
end
end
elseif k == K"meta"
# Expr uses plain identifiers, but JuliaSyntax uses quoted (Symbol) identifiers
for (i, a) in enumerate(args)
if a isa QuoteNode && a.value isa Symbol
args[i] = a.value
end
end
end

return retexpr
Expand Down
1 change: 1 addition & 0 deletions JuliaSyntax/src/julia/kinds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ register_kinds!(JuliaSyntax, 0, [
"vect"
"parens"
"importpath"
"meta"
# Concatenation syntax
"braces"
"bracescat"
Expand Down