Assertion error `argextype only works on argument-position values` in optimizer when testing Checkpointing package on master
https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_hash/f4801ff_vs_7b39515/Checkpointing.primary.log
Internal error: encountered unexpected error in runtime:
AssertionError(msg="argextype only works on argument-position values")
argextype at ./compiler/optimize.jl:371
argextype at ./compiler/optimize.jl:353 [inlined]
argextype at ./compiler/optimize.jl:353 [inlined]
stmt_effect_flags at ./compiler/optimize.jl:220
finish at ./compiler/optimize.jl:433
optimize at ./compiler/optimize.jl:523 [inlined]
_typeinf at ./compiler/typeinfer.jl:257
typeinf at ./compiler/typeinfer.jl:213
typeinf_edge at ./compiler/typeinfer.jl:914
abstract_call_method at ./compiler/abstractinterpretation.jl:605
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:166
abstract_call_known at ./compiler/abstractinterpretation.jl:1744
abstract_call at ./compiler/abstractinterpretation.jl:1813
abstract_call at ./compiler/abstractinterpretation.jl:1792
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1934
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2284
typeinf_local at ./compiler/abstractinterpretation.jl:2461
typeinf_nocycle at ./compiler/abstractinterpretation.jl:2559
_typeinf at ./compiler/typeinfer.jl:230
typeinf at ./compiler/typeinfer.jl:213
typeinf_ext at ./compiler/typeinfer.jl:1038
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1071
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1067
jfptr_typeinf_ext_toplevel_11977 at /Users/noemivitos/juliamaster/usr/lib/julia/sys.dylib (unknown line)
_jl_invoke at /Users/noemivitos/juliamaster/src/gf.c:2374
ijl_apply_generic at /Users/noemivitos/juliamaster/src/gf.c:2575
jl_apply at /Users/noemivitos/juliamaster/src/./julia.h:1846 [inlined]
jl_type_infer at /Users/noemivitos/juliamaster/src/gf.c:317
jl_generate_fptr_impl at /Users/noemivitos/juliamaster/src/jitlayers.cpp:345
Depends on Diffractor and Enzyme (with comments like https://github.com/Argonne-National-Laboratory/Checkpointing.jl/blob/a180e7cbee764e71ed64972fc228fc334f7e2511/test/runtests.jl#L35-L39=) so I'm not sure if Julia's to blame here.
Okay, that seems bad enough for them to debug it themselves.
This happens on a simple using Enzyme on 1.9, while Enzyme does many fishy things just loading it's precompilation file shouldn't cause something like this.
cc: @aviatesk
So running this in a full debug mode I first hit Expr(:call, Main.cglobal, Expr(:call, Core.tuple, :(:_ZN4llvm24DisableABIBreakingChecksE), Ex pr(:call, Base.libllvm_path)), Main.Cvoid), which is #46837
Reduced to:
function foo()
cglobal((a, ))
ccall(0, Cvoid, (Nothing,), b)
end
julia> code_typed(foo, ())
ERROR: LoadError: AssertionError: argextype only works on argument-position values
Stacktrace:
[1] argextype(x::Any, src::Core.Compiler.IRCode, sptypes::Vector{Any}, slottypes::Vector{Any})
@ Core.Compiler ./compiler/optimize.jl:341
[2] argextype (repeats 2 times)
@ ./compiler/optimize.jl:323 [inlined]
[3] stmt_effect_flags(lattice::Core.Compiler.OptimizerLattice, stmt::Any, rt::Any, src::Core.Compiler.IRCode)
@ Core.Compiler ./compiler/optimize.jl:249
[4] finish(interp::Core.Compiler.NativeInterpreter, opt::Core.Compiler.OptimizationState, params::Core.Compiler.OptimizationParams, ir::Core.Compiler.IRCode, caller::Core.Compiler.InferenceResult)
@ Core.Compiler ./compiler/optimize.jl:403
[5] optimize
@ ./compiler/optimize.jl:493 [inlined]
[6] _typeinf(interp::Core.Compiler.NativeInterpreter, frame::Core.Compiler.InferenceState)
@ Core.Compiler ./compiler/typeinfer.jl:259
[7] typeinf(interp::Core.Compiler.NativeInterpreter, frame::Core.Compiler.InferenceState)
@ Core.Compiler ./compiler/typeinfer.jl:215
[8] typeinf_frame(interp::Core.Compiler.NativeInterpreter, method::Method, atype::Any, sparams::Core.SimpleVector, run_optimizer::Bool)
@ Core.Compiler ./compiler/typeinfer.jl:1003
[9] typeinf_code(interp::Core.Compiler.NativeInterpreter, method::Method, atype::Any, sparams::Core.SimpleVector, run_optimizer::Bool)
@ Core.Compiler ./compiler/typeinfer.jl:955
[10] code_typed_by_type(tt::Type; optimize::Bool, debuginfo::Symbol, world::UInt64, interp::Core.Compiler.NativeInterpreter)
@ Base ./reflection.jl:1271
[11] #code_typed#24
@ ./reflection.jl:1230 [inlined]
[12] code_typed
@ ./reflection.jl:1221 [inlined]
Turns out this is pretty similar to https://github.com/JuliaLang/julia/pull/47068, but instead of the verifier it's the new statement effects that don't deal with non-linearized cglobal. I've added the fix to https://github.com/JuliaLang/julia/pull/47068.