Skip to content

Commit 7d335a0

Browse files
author
KristofferC
committed
Revert "fix JuliaLang#47658, state stack overflow on unions containing typevars (JuliaLang#48221)"
This reverts commit 25bad18.
1 parent a82477b commit 7d335a0

File tree

2 files changed

+1
-57
lines changed

2 files changed

+1
-57
lines changed

src/subtype.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,19 +1174,6 @@ static int subtype_tuple(jl_datatype_t *xd, jl_datatype_t *yd, jl_stenv_t *e, in
11741174
return ans;
11751175
}
11761176

1177-
static int equal_unions(jl_uniontype_t *x, jl_uniontype_t *y, jl_stenv_t *e)
1178-
{
1179-
jl_value_t *saved=NULL; jl_savedenv_t se;
1180-
JL_GC_PUSH1(&saved);
1181-
save_env(e, &saved, &se);
1182-
int eq = forall_exists_equal(x->a, y->a, e) && forall_exists_equal(x->b, y->b, e);
1183-
if (!eq)
1184-
restore_env(e, saved, &se);
1185-
free_env(&se);
1186-
JL_GC_POP();
1187-
return eq;
1188-
}
1189-
11901177
// `param` means we are currently looking at a parameter of a type constructor
11911178
// (as opposed to being outside any type constructor, or comparing variable bounds).
11921179
// this is used to record the positions where type variables occur for the
@@ -1376,27 +1363,6 @@ static int forall_exists_equal(jl_value_t *x, jl_value_t *y, jl_stenv_t *e)
13761363
(is_definite_length_tuple_type(x) && is_indefinite_length_tuple_type(y)))
13771364
return 0;
13781365

1379-
if (jl_is_uniontype(x) && jl_is_uniontype(y)) {
1380-
// For 2 unions, try a more efficient greedy algorithm that compares the unions
1381-
// componentwise. If it returns `false`, we forget it and proceed with the usual
1382-
// algorithm. If it returns `true` we try returning `true`, but need to come back
1383-
// here to try the usual algorithm if subtyping later fails.
1384-
jl_unionstate_t *state = &e->Runions;
1385-
jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, state);
1386-
if (state->depth >= state->used) {
1387-
statestack_set(state, state->used, 0);
1388-
state->used++;
1389-
}
1390-
int ui = statestack_get(state, state->depth);
1391-
state->depth++;
1392-
if (ui == 0) {
1393-
state->more = state->depth; // memorize that this was the deepest available choice
1394-
if (equal_unions((jl_uniontype_t*)x, (jl_uniontype_t*)y, e))
1395-
return 1;
1396-
pop_unionstate(state, &oldRunions);
1397-
}
1398-
}
1399-
14001366
jl_saved_unionstate_t oldLunions; push_unionstate(&oldLunions, &e->Lunions);
14011367
e->Lunions.used = 0;
14021368
int sub;

test/subtype.jl

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,16 +2241,6 @@ let S = Tuple{T2, V2} where {T2, N2, V2<:(Array{S2, N2} where {S2 <: T2})},
22412241
@testintersect(S, T, !Union{})
22422242
end
22432243

2244-
@test only(intersection_env(Val{Union{Val{Val{T}} where {T},Int}}, Val{Union{T,Int}} where T)[2]) === Val{Val{T}} where {T}
2245-
2246-
# issue 47654
2247-
Vec47654{T} = Union{AbstractVector{T}, AbstractVector{Union{T,Nothing}}}
2248-
struct Wrapper47654{T, V<:Vec47654{T}}
2249-
v::V
2250-
end
2251-
abstract type P47654{A} end
2252-
@test Wrapper47654{P47654, Vector{Union{P47654,Nothing}}} <: Wrapper47654
2253-
22542244
@testset "known subtype/intersect issue" begin
22552245
#issue 45874
22562246
# Causes a hang due to jl_critical_error calling back into malloc...
@@ -2288,7 +2278,7 @@ abstract type P47654{A} end
22882278
@test_broken typeintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T, Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T) <: Any
22892279

22902280
# issue 24333
2291-
@test (Type{Union{Ref,Cvoid}} <: Type{Union{T,Cvoid}} where T)
2281+
@test_broken (Type{Union{Ref,Cvoid}} <: Type{Union{T,Cvoid}} where T)
22922282

22932283
# issue 22123
22942284
t1 = Ref{Ref{Ref{Union{Int64, T}}} where T}
@@ -2299,16 +2289,4 @@ abstract type P47654{A} end
22992289
@test_broken (Tuple{T1,T1} where T1<:(Val{T2} where T2)) <: (Tuple{Val{S},Val{S}} where S)
23002290
end
23012291

2302-
# issue #47658
2303-
let T = Ref{NTuple{8, Ref{Union{Int, P}}}} where P,
2304-
S = Ref{NTuple{8, Ref{Union{Int, P}}}} where P
2305-
# note T and S are identical but we need 2 copies to avoid being fooled by pointer equality
2306-
@test T <: Union{Int, S}
2307-
end
2308-
2309-
# try to fool a greedy algorithm that picks X=Int, Y=String here
2310-
@test Tuple{Ref{Union{Int,String}}, Ref{Union{Int,String}}} <: Tuple{Ref{Union{X,Y}}, Ref{X}} where {X,Y}
2311-
# this slightly more complex case has been broken since 1.0 (worked in 0.6)
2312-
@test_broken Tuple{Ref{Union{Int,String,Missing}}, Ref{Union{Int,String}}} <: Tuple{Ref{Union{X,Y}}, Ref{X}} where {X,Y}
2313-
23142292
@test !(Tuple{Any, Any, Any} <: Tuple{Any, Vararg{T}} where T)

0 commit comments

Comments
 (0)