[JuliaLowering] Fix @nospecialize multi-arg and add 0-arg#61021
[JuliaLowering] Fix @nospecialize multi-arg and add 0-arg#61021topolarity merged 4 commits intomasterfrom
@nospecialize multi-arg and add 0-arg#61021Conversation
|
This should also include tests for the added support, but otherwise LGTM |
cdcec6b to
6562322
Compare
| # @nospecialize with default value in signature | ||
| @test JuliaLowering.include_string(test_mod, """ | ||
| begin | ||
| function f_nospecialize_default(x, @nospecialize(y=1)) |
There was a problem hiding this comment.
Would be good to add a broken test for the body form (which doesn't work, as noted in
julia/JuliaLowering/src/desugaring.jl
Line 2582 in 3a3289a
A kwargs example would also be good (and is similarly broken for the body form). Sorry to make you add so many tests, but it seems prudent when we run into loose ends like this.
There was a problem hiding this comment.
Added. Regarding keyword argument methods, it hasn't been decided yet how @nospecialize should be propagated, so it might be better to decide that before writing tests.
Even if we add @nospecialize to the keyword methods themselves, we might not get the desired effect unless we also @nospecialize the NamedTuple argument that kwcall receives.
There was a problem hiding this comment.
To clarify, the bug applies to the positional arguments as well, which don't propagate through the helper method either.
There was a problem hiding this comment.
Yeah, I added a new broken test case for that.
There was a problem hiding this comment.
I mean this case:
function f_body_nospecialize_default(x; y=1)
@nospecialize x
(x, y)
end
(f_body_nospecialize_default(10; y = 20), f_body_nospecialize_default(30))flisp labels x as nospecialize in both the "body" and "wrapper" functions.
There was a problem hiding this comment.
Ok, added that case too. Let me elaborate my thinking on this part a bit
Regarding keyword argument methods, it hasn't been decided yet how @nospecialize should be propagated, so it might be better to decide that before writing tests.
So in order to correctly nospecialize the keyword arguments, I believe we need to add nospecialize for the NamedTuple argument of the keyword sorter method as well as their corresponding arguments of the keyword body method, but we currently don't implement this. The keyword body method nospecialization would just be fine, but adding @nospecialize for the NamedTuple means we won't specialize the entire keyword arguments set of the keyword sorter method, so some caution might be needed.
42290e1 to
51cb4e2
Compare
Split the single `@nospecialize(ctx, ex, exs...)` method into properly typed variants: - 0-arg: emits `[K"meta" "nospecialize"]` for blanket usage - 1-arg: applies `_apply_nospecialize` to the argument - 2+-arg: applies `_apply_nospecialize` to all arguments The previous implementation only processed the first argument when multiple were given (the rest were silently ignored). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com>
Fix body-level `@nospecialize x z` not setting the nospecialize bits on `Method.nospecialize`. The macro sets `:nospecialize` metadata on identifiers, but this was not propagated to the binding during scope analysis. Now `_resolve_scopes` checks for this metadata on argument references and sets `is_nospecialize` on the binding. Add tests for missing `@nospecialize` forms: - Body-level multi-arg (`@nospecialize a c d`) - Body-level single-arg (`@nospecialize b`) - Body-level zero-arg (blanket `@nospecialize`) - Signature-level with default value (`@nospecialize(y=1)`) - IR-level tests for body-level single and multi-arg Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51cb4e2 to
b625cb0
Compare
Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com>
Split the single
@nospecialize(ctx, ex, exs...)method into properly typed variants:[K"meta" "nospecialize"]for blanket usage_apply_nospecializeto the argument_apply_nospecializeto all argumentsThe previous implementation only processed the first argument when multiple were given (the rest were silently ignored).