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
57 changes: 28 additions & 29 deletions src/compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end

"""
Return `e.args`, but with any parameters in SyntaxTree (flattened, source) order.
Parameters are expected to be as `e.args[pos]`.
Parameters are expected to be at `e.args[pos]`.

e.g. orderings of (a,b,c;d;e;f):
Expr: (tuple (parameters (parameters (parameters f) e) d) a b c)
Expand Down Expand Up @@ -463,36 +463,35 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
if e.args[1] isa Expr && e.args[1].head === :purity
st_k = K"meta"
child_exprs = [Expr(:quoted_symbol, :purity), Base.EffectsOverride(e.args[1].args...)]
else
@assert e.args[1] isa Symbol
if e.args[1] === :nospecialize
if nargs > 2
st_k = K"block"
# Kick the can down the road (should only be simple atoms?)
child_exprs = map(c->Expr(:meta, :nospecialize, c), child_exprs[2:end])
else
st_id, src = _insert_convert_expr(e.args[2], graph, src)
setmeta!(SyntaxTree(graph, st_id); nospecialize=true)
return st_id, src
end
elseif e.args[1] in (:inline, :noinline, :generated, :generated_only,
:max_methods, :optlevel, :toplevel, :push_loc, :pop_loc,
:no_constprop, :aggressive_constprop, :specialize, :compile, :infer,
:nospecializeinfer, :force_compile, :propagate_inbounds, :doc)
# TODO: Some need to be handled in lowering
for (i, ma) in enumerate(e.args)
if ma isa Symbol
# @propagate_inbounds becomes (meta inline
# propagate_inbounds), but usually(?) only args[1] is
# converted here
child_exprs[i] = Expr(:quoted_symbol, e.args[i])
end
elseif nargs === 0
# pass
elseif e.args[1] === :nospecialize
if nargs === 1
child_exprs[1] = Expr(:quoted_symbol, :nospecialize)
elseif nargs > 2
st_k = K"block"
# Kick the can down the road (should only be simple atoms?)
child_exprs = map(c->Expr(:meta, :nospecialize, c), child_exprs[2:end])
elseif nargs === 2
st_id, src = _insert_convert_expr(e.args[2], graph, src)
setmeta!(SyntaxTree(graph, st_id); nospecialize=true)
return st_id, src
end
elseif e.args[1] in (:inline, :noinline, :generated, :generated_only,
:max_methods, :optlevel, :toplevel, :push_loc, :pop_loc,
:no_constprop, :aggressive_constprop, :specialize, :compile, :infer,
:nospecializeinfer, :force_compile, :propagate_inbounds, :doc)
# TODO: Some need to be handled in lowering
for (i, ma) in enumerate(e.args)
if ma isa Symbol
# @propagate_inbounds becomes (meta inline propagate_inbounds)
child_exprs[i] = Expr(:quoted_symbol, e.args[i])
end
else
# Can't throw a hard error; it is explicitly tested that meta can take arbitrary keys.
@error("Unknown meta form at $src: `$e`\n$(sprint(dump, e))")
child_exprs[1] = Expr(:quoted_symbol, e.args[1])
end
else
# Can't throw a hard error; it is explicitly tested that meta can take arbitrary keys.
@error("Unknown meta form at $src: `$e`\n$(sprint(dump, e))")
child_exprs[1] = Expr(:quoted_symbol, e.args[1])
end
elseif e.head === :scope_layer
@assert nargs === 2
Expand Down
22 changes: 22 additions & 0 deletions test/macros_ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,25 @@ cmdmac`hello`
cmdmac`hello`12345
#---------------------
1 (return "hello from cmdmac with suffix 12345")

########################################
# @nospecialize (zero args)
function foo()
@nospecialize
end
#---------------------
1 (method TestMod.foo)
2 latestworld
3 TestMod.foo
4 (call core.Typeof %₃)
5 (call core.svec %₄)
6 (call core.svec)
7 SourceLocation::1:10
8 (call core.svec %₅ %₆ %₇)
9 --- method core.nothing %₈
slots: [slot₁/#self#(!read)]
1 (meta :nospecialize)
2 (return core.nothing)
10 latestworld
11 TestMod.foo
12 (return %₁₁)
7 changes: 5 additions & 2 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ function uncomment_description(desc)
end

function comment_description(desc)
replace(desc, r"^"m=>"# ")
lines = replace(split(desc, '\n')) do line
strip("# " * line)
end
join(lines, '\n')
end

function match_ir_test_case(case_str)
Expand Down Expand Up @@ -231,7 +234,7 @@ function refresh_ir_test_cases(filename, pattern=nothing)
else
ir = case.output
end
println(io,
(case == cases[end] ? print : println)(io,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks for fixing this :)

"""
########################################
$(comment_description(case.description))
Expand Down
Loading