diff --git a/src/compat.jl b/src/compat.jl index e9800d0..133fb55 100644 --- a/src/compat.jl +++ b/src/compat.jl @@ -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) @@ -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 diff --git a/test/macros_ir.jl b/test/macros_ir.jl index 183dce3..2889023 100644 --- a/test/macros_ir.jl +++ b/test/macros_ir.jl @@ -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 %₁₁) diff --git a/test/utils.jl b/test/utils.jl index 3460ecd..16f2f30 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -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) @@ -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, """ ######################################## $(comment_description(case.description))