From 4c34a0a433b2ec8afbabd1141d75977d6bf8ae64 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 23 Sep 2026 09:07:29 +0200 Subject: [PATCH 1/2] Remove a quirk that never applies Base.Checked.throw_overflowerr_negation takes a single argument on every supported version of Julia, so the three-argument override never matched. --- src/device/quirks.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/device/quirks.jl b/src/device/quirks.jl index 1d151f1b..7f500630 100644 --- a/src/device/quirks.jl +++ b/src/device/quirks.jl @@ -22,8 +22,6 @@ end # checked.jl @device_override @noinline Base.Checked.throw_overflowerr_binaryop(op, x, y) = @print_and_throw "Binary operation overflowed" -@device_override @noinline Base.Checked.throw_overflowerr_negation(op, x, y) = - @print_and_throw "Negation overflowed" # boot.jl @device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} = From 9faa426bcadb2ff89129a0f39689a47cfd3235bb Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 23 Sep 2026 16:12:57 +0200 Subject: [PATCH 2/2] Pass the exception type to @gputhrow (#639) --- src/device/quirks.jl | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/device/quirks.jl b/src/device/quirks.jl index 7f500630..59b9e4f2 100644 --- a/src/device/quirks.jl +++ b/src/device/quirks.jl @@ -1,39 +1,40 @@ -macro print_and_throw(args...) +# throw a device-side exception of type `name`, printing the type and `reason` +macro gputhrow(name::String, reason::String) quote - @println "ERROR: " $(args...) "." + @println "ERROR: " $name ": " $reason "." throw(nothing) end end # math.jl @device_override @noinline Base.Math.throw_complex_domainerror(f::Symbol, x) = - @print_and_throw "This operation requires a complex input to return a complex result" + @gputhrow "DomainError" "This operation requires a complex input to return a complex result" @device_override @noinline Base.Math.throw_exp_domainerror(x) = - @print_and_throw "Exponentiation yielding a complex result requires a complex argument" + @gputhrow "DomainError" "Exponentiation yielding a complex result requires a complex argument" # intfuncs.jl @device_override @noinline Base.throw_domerr_powbysq(::Any, p) = - @print_and_throw "Cannot raise an integer to a negative power" + @gputhrow "DomainError" "Cannot raise an integer to a negative power" @device_override @noinline Base.throw_domerr_powbysq(::Integer, p) = - @print_and_throw "Cannot raise an integer to a negative power" + @gputhrow "DomainError" "Cannot raise an integer to a negative power" @device_override @noinline Base.throw_domerr_powbysq(::AbstractMatrix, p) = - @print_and_throw "Cannot raise an integer to a negative power" + @gputhrow "DomainError" "Cannot raise an integer to a negative power" # checked.jl @device_override @noinline Base.Checked.throw_overflowerr_binaryop(op, x, y) = - @print_and_throw "Binary operation overflowed" + @gputhrow "OverflowError" "Binary operation overflowed" # boot.jl @device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} = - @print_and_throw "Inexact conversion" + @gputhrow "InexactError" "Inexact conversion" # abstractarray.jl @device_override @noinline Base.throw_boundserror(A, I) = - @print_and_throw "Out-of-bounds array access" + @gputhrow "BoundsError" "Out-of-bounds array access" # trig.jl @device_override @noinline Base.Math.sincos_domain_error(x) = - @print_and_throw "sincos(x) is only defined for finite x." + @gputhrow "DomainError" "sincos(x) is only defined for finite x" # diagonal.jl # Base's version throws an ArgumentError; this one prints the reason @@ -43,7 +44,7 @@ import LinearAlgebra if i == j @inbounds D.diag[i] = v elseif !iszero(v) - @print_and_throw "cannot set off-diagonal entry to a nonzero value" + @gputhrow "ArgumentError" "cannot set off-diagonal entry to a nonzero value" end return v end @@ -52,7 +53,7 @@ end # Base's version throws a BoundsError; this one prints the reason @device_override @inline function Base.getindex(x::Number, I::Integer...) @boundscheck all(isone, I) || - @print_and_throw "Out-of-bounds access of scalar value" + @gputhrow "BoundsError" "Out-of-bounds access of scalar value" x end