Skip to content

Commit 5f41931

Browse files
committed
Fix off-by-one in generator nospecialize
I had an off-by-one in #50556, since the argument slots actually start at 2 and `iota` starts at `0`. This was breaking StaticArrays precompiles, which attempts to precompile a generator with its abstract signature and without the nospecialize, those signatures are not compileable.
1 parent 7141e73 commit 5f41931

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/julia-syntax.scm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@
296296
(if (eq? n '|#self#|) (gensy) n))
297297
arg-names))))
298298
(let ((body (insert-after-meta body ;; don't specialize on generator arguments
299-
`((meta nospecialize ,@(map (lambda (idx) `(slot ,(+ idx 1))) (iota (length arg-names))))))))
299+
;; arg-names slots start at 2 (after name)
300+
`((meta nospecialize ,@(map (lambda (idx) `(slot ,(+ idx 2))) (iota (length arg-names))))))))
300301
`(block
301302
(global ,name)
302303
(function (call ,name ,@arg-names) ,body)))))

test/precompile.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,20 @@ precompile_test_harness("Issue #48391") do load_path
17711771
@test_throws ErrorException isless(x, x)
17721772
end
17731773

1774+
precompile_test_harness("Generator nospecialize") do load_path
1775+
write(joinpath(load_path, "GenNoSpec.jl"),
1776+
"""
1777+
module GenNoSpec
1778+
@generated function f(x...)
1779+
:((\$(Base.Meta.quot(x)),))
1780+
end
1781+
@assert precompile(Tuple{typeof(which(f, (Any,Any)).generator.gen), Any, Any})
1782+
end
1783+
""")
1784+
ji, ofile = Base.compilecache(Base.PkgId("GenNoSpec"))
1785+
@eval using GenNoSpec
1786+
end
1787+
17741788
empty!(Base.DEPOT_PATH)
17751789
append!(Base.DEPOT_PATH, original_depot_path)
17761790
empty!(Base.LOAD_PATH)

0 commit comments

Comments
 (0)