Skip to content

Throw a KernelError for non-singleton type arguments - #954

Merged
maleadt merged 1 commit into
mainfrom
tb/type-arg-error
Sep 25, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/type-arg-error

Conversation

@maleadt

@maleadt maleadt commented Sep 25, 2026

Copy link
Copy Markdown
Member

On Julia 1.13 and earlier, Core.Compiler.isconstType(Type{T}) is only true when T has a unique representation. That excludes unions and UnionAlls, so a kernel argument like Type{Union{Missing, Bool}} or Type{Vector} falls through check_invocation to fieldcount, which throws:

ERROR: ArgumentError: type does not have a definite number of fields
  [1] fieldcount(t::Any)
  [2] check_invocation(job::GPUCompiler.CompilerJob)

Such an argument can't work there anyway, because Julia's codegen passes it as a boxed host pointer. This PR reports it as a KernelError:

KernelError: passing a non-singleton type argument

Argument 3 to your kernel function is the type Vector, which
cannot be passed to a GPU kernel on this version of Julia.
Pass `Val(Vector)` instead, or a value of that type.

On Julia with Core.TypeEgal (JuliaLang/julia#62001), methodinstance already turns these into TypeEgal{T} singletons, so the check never fires there. The test covers both cases.

This came up in JuliaGPU/KernelAbstractions.jl#791, where the POCL back-end's zeros(::POCLBackend, Union{Missing, Bool}, ...) passed the element type to a kernel. That is fixed on the KA side in JuliaGPU/KernelAbstractions.jl#795.

Before `Core.TypeEgal`, `Type{T}` is only a singleton when `T` has a unique
representation, so an argument like `Type{Union{Missing, Bool}}` or `Type{Vector}`
fell through to `fieldcount`, which threw an unhelpful `ArgumentError`. Report it as a
`KernelError` suggesting `Val(T)` instead.
@maleadt
maleadt merged commit 87076e0 into main Sep 25, 2026
30 of 33 checks passed
@maleadt
maleadt deleted the tb/type-arg-error branch September 25, 2026 13:22
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.41%. Comparing base (8496909) to head (bf13c3e).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #954   +/-   ##
=======================================
  Coverage   86.41%   86.41%           
=======================================
  Files          29       29           
  Lines        5674     5676    +2     
=======================================
+ Hits         4903     4905    +2     
  Misses        771      771           

☔ 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