Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error: during type inference of promote_typeof(Base.UnitRange{Int64}, Base.UnitRange{Int64}, Array{Any, 1}, Base.UnitRange{Int64}, Base.UnitRange{Int64}...) #56913

Closed
nsajko opened this issue Dec 27, 2024 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference regression Regression in behavior compared to a previous version regression 1.12 Regression in the 1.12 release
Milestone

Comments

@nsajko
Copy link
Contributor

nsajko commented Dec 27, 2024

MWE:

Base.promote_typeof(8:10, 1:3, [], 4:23, 1:9)

Error:

julia> Base.promote_typeof(8:10, 1:3, [], 4:23, 1:9)
Internal error: during type inference of
promote_typeof(Base.UnitRange{Int64}, Base.UnitRange{Int64}, Array{Any, 1}, Base.UnitRange{Int64}, Base.UnitRange{Int64}...)
Encountered unexpected error in runtime:
BoundsError(a=Type{AbstractArray{var"#s175", 1} where var"#s175"}, i=1)
ijl_bounds_error at /cache/build/builder-amdci5-6/julialang/julia-master/src/rtutils.c:178
get_fieldtype at /cache/build/builder-amdci5-6/julialang/julia-master/src/builtins.c:1253
tmerge_partial_struct at ./../usr/share/julia/Compiler/src/typelimits.jl:611
tmerge at ./../usr/share/julia/Compiler/src/typelimits.jl:660
tmerge at ./../usr/share/julia/Compiler/src/typelimits.jl:570 [inlined]
tmerge at ./../usr/share/julia/Compiler/src/typelimits.jl:490
update_bestguess! at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:3765
typeinf_local at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:3964
jfptr_typeinf_local_53040.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/lib/julia/sys.so (unknown line)
typeinf at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:4228
const_prop_call at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:1359
abstract_call_method_with_const_args at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:909
abstract_call_method_with_const_args at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:879
handle1 at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:178
jfptr_handle1_51229.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/lib/julia/sys.so (unknown line)
doworkloop at ./../usr/share/julia/Compiler/src/inferencestate.jl:1192
jfptr_doworkloop_49769.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/lib/julia/sys.so (unknown line)
typeinf at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:4218
typeinf_ext at ./../usr/share/julia/Compiler/src/typeinfer.jl:1147
typeinf_ext_toplevel at ./../usr/share/julia/Compiler/src/typeinfer.jl:1218 [inlined]
typeinf_ext_toplevel at ./../usr/share/julia/Compiler/src/typeinfer.jl:1216
jfptr_typeinf_ext_toplevel_53430.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-amdci5-6/julialang/julia-master/src/julia.h:2244 [inlined]
jl_type_infer at /cache/build/builder-amdci5-6/julialang/julia-master/src/gf.c:395
jl_compile_method_internal at /cache/build/builder-amdci5-6/julialang/julia-master/src/gf.c:2877
_jl_invoke at /cache/build/builder-amdci5-6/julialang/julia-master/src/gf.c:3351 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-6/julialang/julia-master/src/gf.c:3547
jl_apply at /cache/build/builder-amdci5-6/julialang/julia-master/src/julia.h:2244 [inlined]
do_call at /cache/build/builder-amdci5-6/julialang/julia-master/src/interpreter.c:125
eval_value at /cache/build/builder-amdci5-6/julialang/julia-master/src/interpreter.c:243
eval_stmt_value at /cache/build/builder-amdci5-6/julialang/julia-master/src/interpreter.c:194 [inlined]
eval_body at /cache/build/builder-amdci5-6/julialang/julia-master/src/interpreter.c:691
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-6/julialang/julia-master/src/interpreter.c:896
top-level scope at REPL[2]:1
jl_toplevel_eval_flex at /cache/build/builder-amdci5-6/julialang/julia-master/src/toplevel.c:1070
__repl_entry_eval_expanded_with_loc at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:341
jl_apply at /cache/build/builder-amdci5-6/julialang/julia-master/src/julia.h:2244 [inlined]
jl_f__call_latest at /cache/build/builder-amdci5-6/julialang/julia-master/src/builtins.c:883
#invokelatest#1 at ./essentials.jl:1056 [inlined]
invokelatest at ./essentials.jl:1052 [inlined]
toplevel_eval_with_hooks at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:348
toplevel_eval_with_hooks at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:352
toplevel_eval_with_hooks at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:345 [inlined]
eval_user_input at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:370
repl_backend_loop at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:482
#start_repl_backend#41 at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:467
start_repl_backend at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:464 [inlined]
#run_repl#48 at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:690
run_repl at /cache/build/builder-amdci5-6/julialang/julia-master/usr/share/julia/stdlib/v1.12/REPL/src/REPL.jl:676
jfptr_run_repl_24558.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/share/julia/compiled/v1.12/REPL/u0gqU_tJ38k.so (unknown line)
run_std_repl at ./client.jl:490
jfptr_run_std_repl_108104.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-amdci5-6/julialang/julia-master/src/julia.h:2244 [inlined]
jl_f__call_latest at /cache/build/builder-amdci5-6/julialang/julia-master/src/builtins.c:883
#invokelatest#1 at ./essentials.jl:1056 [inlined]
invokelatest at ./essentials.jl:1052 [inlined]
run_main_repl at ./client.jl:511
repl_main at ./client.jl:593 [inlined]
_start at ./client.jl:568
jfptr__start_108161.1 at /home/nsajko/tmp/jl/jl/nightly_normal/julia-cab11bbd2d/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-amdci5-6/julialang/julia-master/src/julia.h:2244 [inlined]
true_main at /cache/build/builder-amdci5-6/julialang/julia-master/src/jlapi.c:922
jl_repl_entrypoint at /cache/build/builder-amdci5-6/julialang/julia-master/src/jlapi.c:1081
main at /cache/build/builder-amdci5-6/julialang/julia-master/cli/loader_exe.c:58
unknown function (ip: 0x7fd85a449e07) at /usr/lib/libc.so.6
__libc_start_main at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8) at /workspace/srcdir/glibc-2.17/csu/../sysdeps/x86_64/start.S
AbstractVector (alias for AbstractArray{<:Any, 1})

I bisected this to #55741 🤷

@nsajko nsajko added bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference regression Regression in behavior compared to a previous version regression 1.12 Regression in the 1.12 release labels Dec 27, 2024
@nsajko nsajko added this to the 1.12 milestone Dec 27, 2024
@nsajko
Copy link
Contributor Author

nsajko commented Dec 28, 2024

Reduced to:

Base.infer_return_type(Base.promote_typeof, Tuple{UnitRange{Int64}, UnitRange{Int64}, Vector{Any}, Vararg{UnitRange{Int64}}})

Error message:

ERROR: BoundsError: attempt to access DataType at index [1]
Stacktrace:
  [1] tmerge_partial_struct(𝕃::Compiler.PartialsLattice{Compiler.ConstsLattice}, typea::Any, typeb::Any)
    @ Compiler ./../usr/share/julia/Compiler/src/typelimits.jl:611
  [2] tmerge(lattice::Compiler.PartialsLattice{Compiler.ConstsLattice}, typea::Any, typeb::Any)
    @ Compiler ./../usr/share/julia/Compiler/src/typelimits.jl:660
  [3] tmerge
    @ ./../usr/share/julia/Compiler/src/typelimits.jl:570 [inlined]
  [4] tmerge(lattice::Compiler.InferenceLattice{Compiler.InterConditionalsLattice{Compiler.PartialsLattice{Compiler.ConstsLattice}}}, typea::Any, typeb::Any)
    @ Compiler ./../usr/share/julia/Compiler/src/typelimits.jl:490
  [5] update_bestguess!(interp::Compiler.NativeInterpreter, frame::Compiler.InferenceState, currstate::Vector{Compiler.VarState}, rt::Any)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:3765
  [6] typeinf_local(interp::Compiler.NativeInterpreter, frame::Compiler.InferenceState, nextresult::Compiler.CurrentState)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:3964
  [7] typeinf(interp::Compiler.NativeInterpreter, frame::Compiler.InferenceState)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:4228
  [8] const_prop_call(interp::Compiler.NativeInterpreter, mi::Core.MethodInstance, result::Compiler.MethodCallResult, arginfo::Compiler.ArgInfo, sv::Compiler.InferenceState, concrete_eval_result::Nothing)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:1359
  [9] abstract_call_method_with_const_args(interp::Compiler.NativeInterpreter, result::Compiler.MethodCallResult, f::Any, arginfo::Compiler.ArgInfo, si::Compiler.StmtInfo, match::Core.MethodMatch, sv::Compiler.InferenceState, invokecall::Nothing)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:909
 [10] abstract_call_method_with_const_args(interp::Compiler.NativeInterpreter, result::Compiler.MethodCallResult, f::Any, arginfo::Compiler.ArgInfo, si::Compiler.StmtInfo, match::Core.MethodMatch, sv::Compiler.InferenceState)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:879
 [11] (::Compiler.var"#handle1#abstract_call_gf_by_type##1"{Int64, Compiler.Future{Compiler.MethodCallResult}, Int64, Vector{Union{Nothing, Core.CodeInstance}}, Core.MethodMatch, Compiler.ArgInfo, Compiler.StmtInfo, Compiler.CallInferenceState, Vector{Any}, Compiler.var"#tmerge##0#tmerge##1"{Compiler.InferenceLattice{Compiler.ConditionalsLattice{Compiler.PartialsLattice{Compiler.ConstsLattice}}}}, Compiler.var"#tmerge##0#tmerge##1"{Compiler.InferenceLattice{Compiler.InterConditionalsLattice{Compiler.PartialsLattice{Compiler.ConstsLattice}}}}, Compiler.var"#⊑##0#⊑##1"{Compiler.InferenceLattice{Compiler.InterConditionalsLattice{Compiler.PartialsLattice{Compiler.ConstsLattice}}}}, Compiler.InferenceLattice{Compiler.ConditionalsLattice{Compiler.PartialsLattice{Compiler.ConstsLattice}}}, Compiler.InferenceLattice{Compiler.InterConditionalsLattice{Compiler.PartialsLattice{Compiler.ConstsLattice}}}})(interp::Compiler.NativeInterpreter, sv::Compiler.InferenceState)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:178
 [12] doworkloop(interp::Compiler.NativeInterpreter, sv::Compiler.InferenceState)
    @ Compiler ./../usr/share/julia/Compiler/src/inferencestate.jl:1192
 [13] typeinf(interp::Compiler.NativeInterpreter, frame::Compiler.InferenceState)
    @ Compiler ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:4218
 [14] typeinf_type(interp::Compiler.NativeInterpreter, mi::Core.MethodInstance)
    @ Compiler ./../usr/share/julia/Compiler/src/typeinfer.jl:1209
 [15] typeinf_type(interp::Compiler.NativeInterpreter, match::Core.MethodMatch)
    @ Compiler ./../usr/share/julia/Compiler/src/typeinfer.jl:1181
 [16] invoke_in_typeinf_world(::Function, ::Vararg{Any})
    @ Base ./reflection.jl:341
 [17] invoke_default_compiler(::Symbol, ::Compiler.NativeInterpreter, ::Vararg{Any})
    @ Base ./reflection.jl:346
 [18] invoke_interp_compiler(::Nothing, ::Symbol, ::Compiler.NativeInterpreter, ::Vararg{Any})
    @ Base ./reflection.jl:354
 [19] infer_return_type(f::Any, types::Any; world::UInt64, interp::Nothing)
    @ Base ./reflection.jl:691
 [20] infer_return_type(f::Any, types::Any)
    @ Base ./reflection.jl:675
 [21] top-level scope
    @ none:1
 [22] eval(m::Module, e::Any)
    @ Core ./boot.jl:485
 [23] exec_options(opts::Base.JLOptions)
    @ Base ./client.jl:295
 [24] _start()
    @ Base ./client.jl:558

@nsajko
Copy link
Contributor Author

nsajko commented Dec 28, 2024

Possibly reduces to:

Compiler = Core.Compiler
s = AbstractArray{T, 1} where {T}
t = AbstractArray{<:Any, 1}
cs = Core.Const(s)
ct = Core.Const(t)
lattice = Compiler.PartialsLattice{Compiler.ConstsLattice}(Compiler.ConstsLattice())
Compiler.tmerge(lattice, cs, ct)

Not sure if the above is supposed to work though, the snippet throws a BoundsError even on v1.9.

(s !== t) && (s == t) is what seems to cause the issue.

Error message:

ERROR: BoundsError: attempt to access DataType at index [1]
Stacktrace:
 [1] tmerge_partial_struct(𝕃::Compiler.PartialsLattice{Compiler.ConstsLattice}, typea::Any, typeb::Any)
   @ Compiler ~/tmp/jl/julia-git/i/Compiler/src/typelimits.jl:611
 [2] tmerge(lattice::Compiler.PartialsLattice{Compiler.ConstsLattice}, typea::Any, typeb::Any)
   @ Compiler ~/tmp/jl/julia-git/i/Compiler/src/typelimits.jl:660
 [3] top-level scope
   @ REPL[7]:1

@vtjnash
Copy link
Member

vtjnash commented Jan 5, 2025

Fixed by #56915

julia> Base.promote_typeof(8:10, 1:3, [], 4:23, 1:9)
AbstractVector (alias for AbstractArray{<:Any, 1})

@vtjnash vtjnash closed this as completed Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference regression Regression in behavior compared to a previous version regression 1.12 Regression in the 1.12 release
Projects
None yet
Development

No branches or pull requests

2 participants