Skip to content

Mangle a Vararg whose length is still a TypeVar - #921

Open
vchuravy wants to merge 1 commit into
mainfrom
vc/mangle-typevar-vararg
Open

Mangle a Vararg whose length is still a TypeVar#921
vchuravy wants to merge 1 commit into
mainfrom
vc/mangle-typevar-vararg

Conversation

@vchuravy

@vchuravy vchuravy commented Sep 4, 2026

Copy link
Copy Markdown
Member

mangle_param repeats the element type N times for an NTuple, but N is a TypeVar rather than an integer whenever the length is still parametric — which is exactly what the UnionAll branch just above it leaves behind after unwrap_unionall. 1:t.N then throws:

MethodError: no method matching (::Colon)(::Int64, ::TypeVar)
  [1] mangle_param(t::Any, substitutions::Vector{Any}, top::Bool)
    @ GPUCompiler src/mangling.jl:126
  ...
  [8] mangle_sig(sig::Any)
    @ GPUCompiler src/mangling.jl:189
  [9] relocation_namespace
    @ src/relocation.jl:326 [inlined]
 [10] collect_julia_value_relocations!(job, mod, gv_to_value)
    @ GPUCompiler src/relocation.jl:338
 [11] irgen(job::GPUCompiler.CompilerJob)

Such a type is == to the unbounded Vararg{T}, so this mangles it the same way — NTuple{N,Int} where N and Tuple{Vararg{Int}} both give Tuple<>. A concrete count is unaffected.

This became reachable from any job once relocation_namespace started mangling every job's signature rather than only a kernel's: Enzyme.jl hits it on GPUCompiler 2.x (EnzymeAD/Enzyme.jl#3512) while compiling a signature that carries one of these types.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XmMWGrDGbAaajpehN7cAhW

`mangle_param` repeats the element type `N` times for an `NTuple`, but `N`
is a `TypeVar` rather than an integer whenever the length is still
parametric — which is exactly what the `UnionAll` branch above leaves
behind after `unwrap_unionall`. `1:t.N` then throws
`MethodError: (::Colon)(::Int64, ::TypeVar)`.

Such a type is `==` to the unbounded `Vararg{T}`, so mangle it the same
way: `NTuple{N,Int} where N` and `Tuple{Vararg{Int}}` both give
`Tuple<>`. A concrete count is unaffected.

This is reachable from any job now that `relocation_namespace` mangles
every job's signature, not just a kernel's: Enzyme.jl hits it on
GPUCompiler 2.x compiling a signature that carries such a type.

Assisted-by: Claude Code (Opus 5)
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.42%. Comparing base (78fa65e) to head (87a6e40).

Files with missing lines Patch % Lines
src/mangling.jl 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #921   +/-   ##
=======================================
  Coverage   85.41%   85.42%           
=======================================
  Files          29       29           
  Lines        5582     5583    +1     
=======================================
+ Hits         4768     4769    +1     
  Misses        814      814           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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