Skip to content

Do not rely on @nospecialize argument names being unhygienic - #728

Open
KristofferC wants to merge 1 commit into
JuliaDiff:mainfrom
KristofferC:kc/nospecialize-kwargs-hygiene
Open

KristofferC wants to merge 1 commit into
JuliaDiff:mainfrom
KristofferC:kc/nospecialize-kwargs-hygiene

Conversation

@KristofferC

@KristofferC KristofferC commented Dec 2, 2026 •

Copy link
Copy Markdown

The kwcall method generated by @non_differentiable declares its gensym'd kwargs argument unescaped inside @nospecialize(...) but refers to it from escaped code. That only works because the old macro expander does not rename arguments wrapped in @nospecialize; with the new lowering on Julia 1.15 it gives UndefVarError: `##kwargs#NNN` not defined (two test errors in test/rule_definition_tools.jl).

@nospecialize($(esc(kwargs))::Any) is rejected on older Julia versions ("not a valid function argument name"), so the argument is escaped and marked through a meta expression in the body instead. Tests pass on 1.10 and nightly, and the method's nospecialize bits are unchanged on 1.10 and 1.12.

Found via PkgEval on Julia nightly. Written with Claude Code (Fable 5.2)

🤖 Generated with Claude Code

The kwcall method of `@non_differentiable` declared its gensym'd kwargs
argument unescaped inside `@nospecialize(...)` but referred to it from
escaped code. That only works because the flisp macro expander does not
rename arguments wrapped in `@nospecialize`, and fails on Julia 1.15.

Assisted-by: Claude Code (Fable 5.2)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant