Skip to content

Adopt Base.Math.throw_finite_domainerror once JuliaLang/julia#62842 lands #1043

Description

@luraess

src/device/quirks.jl copies Base's sind and cosd bodies verbatim (#1041) so that the inline DomainError, which boxes its untyped val field and drags in the malloc hostcall, can be replaced with @gpu_throw. Base had no overridable helper for those two, so copying was the only lever.

JuliaLang/julia#62842 adds a shared throw_finite_domainerror(f::Symbol, x) in base/math.jl and routes all ten "only defined for finite x" trig sites through it: sin, cos, tan, sincos, sinpi, cospi, sincospi, tanpi, sind and cosd. Once it merges, the copied bodies and our existing sincos_domain_error override collapse into one method:

@static if isdefined(Base.Math, :throw_finite_domainerror)
    @device_override Base.Math.throw_finite_domainerror(f::Symbol, x) =
        @gpu_throw "DomainError: argument is not finite"
else
    # current copied bodies plus the sincos_domain_error override
end

The reason string has to stay a literal: @gpu_throw maps its prefix to an ExceptionCode at macro expansion time and falls back to UNKNOWN for anything interpolated, so the function name cannot be spliced into it.

Feature detection rather than a VERSION check, so it keeps working if the change is ever backported.

The helper lands in 1.14, so the copied bodies stay until our compat floor passes 1.14. The @static branch gets exercised by the Julia nightly CI step as soon as the Base PR merges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions