Skip to content

@report_trim / @report_opt report no issues despite --trim failure #758

@topolarity

Description

@topolarity

from https://github.com/JuliaComputing/CthulhuJETWorkshop/blob/main/examples/specialization.jl

@noinline transformed_random_sum(f::Function) = sum(f, randn(10))

function @main(ARGS::Vector{String})

    # compute a random norm
    rand_norm = transformed_random_sum(abs2)

    # print it to the user
    println(Core.stdout, rand_norm)

    return 0
end

If we ask JET about this:

julia> @report_opt main(String[])
No errors detected


julia> @report_trim main(String[])
No errors detected

However, --trim does not agree:

$ julia ../path/to/julia/contrib/juliac/juliac.jl --experimental --trim=safe --output-exe specialization ./examples/specialization.jl
Verifier error #1: unresolved call from statement Base.mapreduce(f::Function, Base.add_sum, a::Vector{Float64})::Any
Stacktrace:
 [1] _sum(f::Function, a::Vector{Float64}, ::Colon; kw::@Kwargs{})
   @ Base reducedim.jl:984
 [2] sum(f::Function, a::Vector{Float64}; dims::Colon, kw::@Kwargs{})
   @ Base reducedim.jl:980 [inlined]
 [3] transformed_random_sum(f::Function)
   @ Main ~/repos/CthulhuJETWorkshop/examples/specialization.jl:1
 [4] main(ARGS::Vector{String})
   @ Main ~/repos/CthulhuJETWorkshop/examples/specialization.jl:6 [inlined]
 [5] _main(argc::Int32, argv::Ptr{Ptr{Int8}})
   @ Main ~/repos/julia/contrib/juliac/juliac-buildscript.jl:33

Verifier error #2: unresolved call from statement Base.mapreduce(f::Function, Base.add_sum, a::Vector{Float64})::Any
Stacktrace:
 [1] _sum(f::Function, a::Vector{Float64}, ::Colon; kw::@Kwargs{})
   @ Base reducedim.jl:984
 [2] sum(f::Function, a::Vector{Float64}; dims::Colon, kw::@Kwargs{})
   @ Base reducedim.jl:980 [inlined]
 [3] transformed_random_sum(f::Function)
   @ Main ~/repos/CthulhuJETWorkshop/examples/specialization.jl:1
 [4] main(ARGS::Vector{String})
   @ Main ~/repos/CthulhuJETWorkshop/examples/specialization.jl:6 [inlined]
 [5] _main(argc::Int32, argv::Ptr{Ptr{Int8}})
   @ Main ~/repos/julia/contrib/juliac/juliac-buildscript.jl:33

Trim verify finished with 2 errors, 0 warnings.

I suspect what is going on here is that type-inference is exploring transformed_random_sum(::typeof(abs2)) (since the function is not marked @nospecializeinfer) but this means that inference is inherently more precise than what codegen is willing to explore, which is transformed_random_sum(::Function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions