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

julia type inference crashes (typeerror) #41908

Closed
maartenvd opened this issue Aug 17, 2021 · 8 comments · Fixed by #41976
Closed

julia type inference crashes (typeerror) #41908

maartenvd opened this issue Aug 17, 2021 · 8 comments · Fixed by #41976
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference types and dispatch Types, subtyping and method dispatch

Comments

@maartenvd
Copy link

my tests started crashing with the stacktrace:

Internal error: encountered unexpected error in runtime:
TypeError(func=:AbstractTensorMap, context="S", expected=S<:(TensorKit.ElementarySpace{𝕜} where 𝕜), got=TensorKit.HomSpace{TensorKit.GradedSpace{Main.PlanarTrivial, Tuple{Int64}}, TensorKit.ProductSpace{TensorKit.GradedSpace{Main.PlanarTrivial, Tuple{Int64}}, 0}, TensorKit.ProductSpace{TensorKit.GradedSpace{Main.PlanarTrivial, Tuple{Int64}}, 0}})
jl_type_error_rt at /home/maarten/julia/src/rtutils.c:119
check_datatype_parameters at /home/maarten/julia/src/jltypes.c:1229
inst_datatype_inner at /home/maarten/julia/src/jltypes.c:1392
...

happens at least on julia 1.6.2, and also on master.

I wasn't able to really reduce it down very far, as it's a reasonably large codebase. To run it, you need my fork of TensorKit.jl, and the planocalypse branch of MPSKit.jl . I will try to reduce it down further, but so far I didn't have much luck.

using TensorKit,MPSKit;

#define some new sectortype - with the property that braiding is forbidden
struct PlanarTrivial <: TensorKit.Sector end
struct 𝔹 end
Base.:^(::Type{𝔹}, d::Int) = GradedSpace(PlanarTrivial()=>d);

Base.one(::Type{PlanarTrivial})  = PlanarTrivial();
Base.conj(c::PlanarTrivial) = PlanarTrivial();
TensorKit.:⊗(c1::PlanarTrivial, c2::PlanarTrivial) = (PlanarTrivial(),)

Base.IteratorSize(::Type{TensorKit.SectorValues{PlanarTrivial}}) = TensorKit.HasLength()
Base.length(::TensorKit.SectorValues{PlanarTrivial}) = 1
Base.iterate(::TensorKit.SectorValues{PlanarTrivial}, i = 0) = i==0 ? (PlanarTrivial(),1) : nothing;
Base.getindex(::TensorKit.SectorValues{PlanarTrivial}, i::Int) = i == 1 ? PlanarTrivial() : ArgumentError("lol");
TensorKit.findindex(::TensorKit.SectorValues{PlanarTrivial}, c::PlanarTrivial)  = 1
Base.isless(::PlanarTrivial, ::PlanarTrivial) = false;
TensorKit.BraidingStyle(::Type{PlanarTrivial}) = TensorKit.NoBraiding();
TensorKit.FusionStyle(::Type{PlanarTrivial}) = TensorKit.UniqueFusion();
TensorKit.Fsymbol(args::Vararg{PlanarTrivial,6}) = 1
TensorKit.Nsymbol(args::Vararg{PlanarTrivial,3}) = 1


# use mpskit
alg = GradientGrassmann(verbosity=0,maxiter=1);
mpo = InfiniteMPO([TensorMap(rand,ComplexF64,𝔹^2*𝔹^2,𝔹^2*𝔹^2)]);
state = InfiniteMPS([𝔹^2],[𝔹^10]);
(state,envs) = leading_boundary(state,mpo,alg);

@maartenvd
Copy link
Author

Is there a tool that would allow me to debug this myself? I tried sprinkling in println's in some compiler/*.jl files but not only did compilation appear to hang, this will also take a really long time to get to the bottom off, with all that recompilation.

@vtjnash
Copy link
Member

vtjnash commented Aug 17, 2021

Can you post the full stack trace? If I could see which line of base/compiler/*.jl was throwing the error, it could likely be fixed easily, and an example case generated, from knowing that

@maartenvd
Copy link
Author

Internal error: encountered unexpected error in runtime:
TypeError(func=:AbstractTensorMap, context="S", expected=S<:(TensorKit.ElementarySpace{𝕜} where 𝕜), got=TensorKit.HomSpace{TensorKit.GradedSpace{Main.PlanarTrivial, Tuple{Int64}}, TensorKit.ProductSpace{TensorKit.GradedSpace{Main.PlanarTrivial, Tuple{Int64}}, 0}, TensorKit.ProductSpace{TensorKit.GradedSpace{Main.PlanarTrivial, Tuple{Int64}}, 0}})
jl_type_error_rt at /home/maarten/julia/src/rtutils.c:119
check_datatype_parameters at /home/maarten/julia/src/jltypes.c:1229
inst_datatype_inner at /home/maarten/julia/src/jltypes.c:1392
inst_type_w_ at /home/maarten/julia/src/jltypes.c:1784
inst_type_w_ at /home/maarten/julia/src/jltypes.c:1720
inst_type_w_ at /home/maarten/julia/src/jltypes.c:1720
inst_tuple_w_ at /home/maarten/julia/src/jltypes.c:1677
inst_type_w_ at /home/maarten/julia/src/jltypes.c:1769
jl_instantiate_unionall at /home/maarten/julia/src/jltypes.c:1042
jl_apply_type at /home/maarten/julia/src/jltypes.c:974
subst_trivial_bounds at ./compiler/utilities.jl:159
subst_trivial_bounds at ./compiler/utilities.jl:161
normalize_typevars at ./compiler/utilities.jl:169
specialize_method at ./compiler/utilities.jl:181
specialize_method at ./compiler/utilities.jl:180 [inlined]
typeinf_edge at ./compiler/typeinfer.jl:774 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1877
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1877
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1877
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1877
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1877
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_edge at ./compiler/typeinfer.jl:817 [inlined]
abstract_call_method at ./compiler/abstractinterpretation.jl:507
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:105
abstract_call_known at ./compiler/abstractinterpretation.jl:1309
abstract_call at ./compiler/abstractinterpretation.jl:1364
abstract_call at ./compiler/abstractinterpretation.jl:1349
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1503
typeinf_local at ./compiler/abstractinterpretation.jl:1895
typeinf_nocycle at ./compiler/abstractinterpretation.jl:1985
_typeinf at ./compiler/typeinfer.jl:226
typeinf at ./compiler/typeinfer.jl:209
typeinf_ext at ./compiler/typeinfer.jl:903
typeinf_ext_toplevel at ./compiler/typeinfer.jl:936
typeinf_ext_toplevel at ./compiler/typeinfer.jl:932
jfptr_typeinf_ext_toplevel_14839 at /home/maarten/julia/usr/lib/julia/sys.so (unknown line)
_jl_invoke at /home/maarten/julia/src/gf.c:2245 [inlined]
jl_apply_generic at /home/maarten/julia/src/gf.c:2427
jl_apply at /home/maarten/julia/src/julia.h:1771 [inlined]
jl_type_infer at /home/maarten/julia/src/gf.c:295
jl_generate_fptr at /home/maarten/julia/src/jitlayers.cpp:336
jl_compile_method_internal at /home/maarten/julia/src/gf.c:1978
jl_compile_method_internal at /home/maarten/julia/src/gf.c:2244 [inlined]
_jl_invoke at /home/maarten/julia/src/gf.c:2237 [inlined]
jl_apply_generic at /home/maarten/julia/src/gf.c:2427
jl_apply at /home/maarten/julia/src/julia.h:1771 [inlined]
do_call at /home/maarten/julia/src/interpreter.c:125
eval_value at /home/maarten/julia/src/interpreter.c:214
eval_stmt_value at /home/maarten/julia/src/interpreter.c:165 [inlined]
eval_body at /home/maarten/julia/src/interpreter.c:597
jl_interpret_toplevel_thunk at /home/maarten/julia/src/interpreter.c:727
top-level scope at /home/maarten/projects/minimalfailure.jl:28
jl_toplevel_eval_flex at /home/maarten/julia/src/toplevel.c:885
jl_toplevel_eval_flex at /home/maarten/julia/src/toplevel.c:830
jl_toplevel_eval_flex at /home/maarten/julia/src/toplevel.c:830
jl_toplevel_eval_in at /home/maarten/julia/src/toplevel.c:944
eval at ./boot.jl:373 [inlined]
include_string at ./loading.jl:1207
_jl_invoke at /home/maarten/julia/src/gf.c:2245 [inlined]
jl_apply_generic at /home/maarten/julia/src/gf.c:2427
_include at ./loading.jl:1264
include at ./Base.jl:420
_jl_invoke at /home/maarten/julia/src/gf.c:2245 [inlined]
jl_apply_generic at /home/maarten/julia/src/gf.c:2427
exec_options at ./client.jl:292
_start at ./client.jl:495
jfptr__start_18860 at /home/maarten/julia/usr/lib/julia/sys.so (unknown line)
_jl_invoke at /home/maarten/julia/src/gf.c:2245 [inlined]
jl_apply_generic at /home/maarten/julia/src/gf.c:2427
jl_apply at /home/maarten/julia/src/julia.h:1771 [inlined]
true_main at /home/maarten/julia/src/jlapi.c:548
jl_repl_entrypoint at /home/maarten/julia/src/jlapi.c:690
main at julia (unknown line)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
_start at julia (unknown line)

@maartenvd
Copy link
Author

this should have been the stack trace for julia master

@martinholters
Copy link
Member

Heh, trying to find a simple reproducer I stumbled upon a different but likely similar issue:

using LinearAlgebra
function foo()
    x = Any[1][1]
    x = x::(Diagonal{Int, T} where Int<:T<:Int)
    size(x)  
end
foo()

Works (=only throws a runtime-error) on 1.6, but fails on 1.7 and master. Worth its own issue given that it is a regression?

@vtjnash
Copy link
Member

vtjnash commented Aug 18, 2021

They are slightly different, but I think we can keep them both in this issue, since they make sense to fix together.

original:

julia> bar(x::Diagonal{Int, T}) where {Int<:T<:Int} = 1
julia> foo() = bar(Any[1][1])
julia> foo()
Internal error: encountered unexpected error in runtime:
TypeError(func=:Diagonal, context="V", expected=V<:AbstractArray{T, 1}, got=Int64)
jl_type_error_rt at /Users/jameson/julia1/src/rtutils.c:119
check_datatype_parameters at /Users/jameson/julia1/src/jltypes.c:1205
inst_datatype_inner at /Users/jameson/julia1/src/jltypes.c:1368
inst_type_w_ at /Users/jameson/julia1/src/jltypes.c:1760
inst_tuple_w_ at /Users/jameson/julia1/src/jltypes.c:1653
jl_instantiate_unionall at /Users/jameson/julia1/src/jltypes.c:1018 [inlined]
jl_apply_type at /Users/jameson/julia1/src/jltypes.c:972
subst_trivial_bounds at ./compiler/utilities.jl:159
normalize_typevars at ./compiler/utilities.jl:169
specialize_method at ./compiler/utilities.jl:181
specialize_method at ./compiler/utilities.jl:180 [inlined]
typeinf_edge at ./compiler/typeinfer.jl:780 [inlined]

and yours I see as "works" on master too:

julia> foo()
Internal error: encountered unexpected error in runtime:
TypeError(func=:Diagonal, context="V", expected=V<:AbstractArray{T, 1}, got=Int64)
jl_type_error_rt at /Users/jameson/julia1/src/rtutils.c:119
check_datatype_parameters at /Users/jameson/julia1/src/jltypes.c:1205
inst_datatype_inner at /Users/jameson/julia1/src/jltypes.c:1368
inst_type_w_ at /Users/jameson/julia1/src/jltypes.c:1760
jl_instantiate_unionall at /Users/jameson/julia1/src/jltypes.c:1018 [inlined]
normalize_unionalls at /Users/jameson/julia1/src/jltypes.c:1313
inst_datatype_inner at /Users/jameson/julia1/src/jltypes.c:1330
jl_apply_tuple_type_v_ at /Users/jameson/julia1/src/jltypes.c:1538 [inlined]
jl_apply_tuple_type_v at /Users/jameson/julia1/src/jltypes.c:1548
_jl_invoke at /Users/jameson/julia1/src/gf.c:0 [inlined]
jl_apply_generic at /Users/jameson/julia1/src/gf.c:2427
jl_apply at /Users/jameson/julia1/src/./julia.h:1768 [inlined]
do_apply at /Users/jameson/julia1/src/builtins.c:713
argtypes_to_type at ./compiler/typeutils.jl:53 [inlined]

@vtjnash vtjnash added bug Indicates an unexpected problem or unintended behavior compiler:inference Type inference types and dispatch Types, subtyping and method dispatch labels Aug 18, 2021
@martinholters
Copy link
Member

Looks like the OP can pragmatically be solved with

diff --git a/base/compiler/utilities.jl b/base/compiler/utilities.jl
index 5d4d52172a..852ec1e216 100644
--- a/base/compiler/utilities.jl
+++ b/base/compiler/utilities.jl
@@ -166,7 +166,11 @@ end
 #   f(x::S) where S<:Int
 # gets cached and matches a concrete dispatch case.
 function normalize_typevars(method::Method, @nospecialize(atypes), sparams::SimpleVector)
-    at2 = subst_trivial_bounds(atypes)
+    try
+        at2 = subst_trivial_bounds(atypes)
+    catch
+        return atypes, sparams
+    end
     if at2 !== atypes && at2 == atypes
         atypes = at2
         sp_ = ccall(:jl_type_intersection_with_env, Any, (Any, Any), at2, method.sig)::SimpleVector

(Is there a nice way of finding out whether atypes{v.ub} would throw without actually trying?)

The other case is slightly trickier as

julia> Tuple{LinearAlgebra.Diagonal{Int64, T} where Int64<:T<:Int64}
ERROR: TypeError: in Diagonal, in V, expected V<:AbstractArray{T, 1}, got Type{Int64}

I guess we would want to actually form that type? (Alternatively, maybe we should forbid LinearAlgebra.Diagonal{Int64, T} where Int64<:T<:Int64 in the first place, bit that might be too breaking to do now.)

@JeffBezanson
Copy link
Member

Ah, I already needed that patch in #41795.

@JeffBezanson JeffBezanson self-assigned this Aug 23, 2021
JeffBezanson added a commit that referenced this issue Aug 25, 2021
Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
KristofferC pushed a commit that referenced this issue Aug 25, 2021
Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
(cherry picked from commit e2aeefb)
KristofferC pushed a commit that referenced this issue Oct 29, 2021
Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
(cherry picked from commit e2aeefb)
KristofferC pushed a commit that referenced this issue Nov 11, 2021
Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
(cherry picked from commit e2aeefb)
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Feb 22, 2022
…ng#41976)

Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Mar 8, 2022
…ng#41976)

Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
staticfloat pushed a commit that referenced this issue Dec 23, 2022
Co-authored-by: Martin Holters <martin.holters@hsu-hh.de>
(cherry picked from commit e2aeefb)
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 types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants