Test: add @test_hygienic macro for checking macro hygiene#61500
Draft
IanButterworth wants to merge 1 commit intoJuliaLang:masterfrom
Draft
Test: add @test_hygienic macro for checking macro hygiene#61500IanButterworth wants to merge 1 commit intoJuliaLang:masterfrom
IanButterworth wants to merge 1 commit intoJuliaLang:masterfrom
Conversation
Add a new macro `@test_hygienic` that verifies a macro expansion does not contain unhygienic names — either leaked bindings or captured variable references. After macroexpand, any plain Symbol (no gensym `#`) that appears outside `hygienic-scope` blocks and wasn't in the original user expression is flagged as unhygienic. The implementation correctly handles compiler special forms (ccall, cglobal), qualified names (Expr(:.)), compiler directives (inbounds, boundscheck), keyword argument names, and QuoteNodes. Supports `broken` and `skip` keyword arguments consistent with other Test macros. Co-Authored-By: Claude <claude@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft claude-generated proposal (opening as a proof of concept), but it seems to work in the test cases, and it discovered three hygiene issues:
Passed:
@time,@elapsed,@allocated,@allocations,@timed,@assert,@show,@info,@warn,@error,@debug,@lock,@enum,@inline,@noinline,@boundscheck,@inbounds,@label,@goto,@static,@eval,@isdefined,@invoke,@invokelatest,@view,@views,@async,@sync,@atomic,@ccall,@kwdef,@deprecate,@task,@threadcall,@fastmath,@polly,@simd,@test,@test_throws,@test_broken,@test_skip,@test_warn,@test_nowarn,@test_logs,@testset,@logmsg,@sprintfFailed:
Threads.@threads→:onethread—onethread = "hello"gets shadowed by macro's kwargonethread = falseThreads: remove deadonethreadinternal from@threads#61501i.e.
The implementation may be easier once JuliaLowering lands?
Developed with Claude:
Add a new macro
@test_hygienicthat verifies a macro expansion does not contain unhygienic names — either leaked bindings or captured variable references. After macroexpand, any plain Symbol (no gensym#) that appears outsidehygienic-scopeblocks and wasn't in the original user expression is flagged as unhygienic.The implementation correctly handles compiler special forms (ccall, cglobal), qualified names (Expr(:.)), compiler directives (inbounds, boundscheck), keyword argument names, and QuoteNodes.
Supports
brokenandskipkeyword arguments consistent with other Test macros.