Skip to content

Commit 7bb1747

Browse files
committed
Fix @nospecialize with zero args
1 parent 2c8a478 commit 7bb1747

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/compat.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ end
8282

8383
"""
8484
Return `e.args`, but with any parameters in SyntaxTree (flattened, source) order.
85-
Parameters are expected to be as `e.args[pos]`.
85+
Parameters are expected to be at `e.args[pos]`.
8686
8787
e.g. orderings of (a,b,c;d;e;f):
8888
Expr: (tuple (parameters (parameters (parameters f) e) d) a b c)
@@ -461,11 +461,13 @@ function _insert_convert_expr(@nospecialize(e), graph::SyntaxGraph, src::SourceA
461461
elseif nargs === 0
462462
# pass
463463
elseif e.args[1] === :nospecialize
464-
if nargs > 2
464+
if nargs === 1
465+
child_exprs[1] = Expr(:quoted_symbol, :nospecialize)
466+
elseif nargs > 2
465467
st_k = K"block"
466468
# Kick the can down the road (should only be simple atoms?)
467469
child_exprs = map(c->Expr(:meta, :nospecialize, c), child_exprs[2:end])
468-
else
470+
elseif nargs === 2
469471
st_id, src = _insert_convert_expr(e.args[2], graph, src)
470472
setmeta!(SyntaxTree(graph, st_id); nospecialize=true)
471473
return st_id, src

test/macros_ir.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,25 @@ cmdmac`hello`
186186
cmdmac`hello`12345
187187
#---------------------
188188
1 (return "hello from cmdmac with suffix 12345")
189+
190+
########################################
191+
# @nospecialize (zero args)
192+
function foo()
193+
@nospecialize
194+
end
195+
#---------------------
196+
1 (method TestMod.foo)
197+
2 latestworld
198+
3 TestMod.foo
199+
4 (call core.Typeof %₃)
200+
5 (call core.svec %₄)
201+
6 (call core.svec)
202+
7 SourceLocation::1:10
203+
8 (call core.svec %%%₇)
204+
9 --- method core.nothing %
205+
slots: [slot₁/#self#(!read)]
206+
1 (meta :nospecialize)
207+
2 (return core.nothing)
208+
10 latestworld
209+
11 TestMod.foo
210+
12 (return %₁₁)

test/utils.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ function uncomment_description(desc)
112112
end
113113

114114
function comment_description(desc)
115-
replace(desc, r"^"m=>"# ")
115+
lines = replace(split(desc, '\n')) do line
116+
strip("# " * line)
117+
end
118+
join(lines, '\n')
116119
end
117120

118121
function match_ir_test_case(case_str)
@@ -228,7 +231,7 @@ function refresh_ir_test_cases(filename, pattern=nothing)
228231
else
229232
ir = case.output
230233
end
231-
println(io,
234+
(case == cases[end] ? print : println)(io,
232235
"""
233236
########################################
234237
$(comment_description(case.description))

0 commit comments

Comments
 (0)