Skip to content

Commit af6542e

Browse files
committed
Core.Compiler is not a stable API to rely upon
1 parent a62acdf commit af6542e

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

base/iterators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ else
12661266
# fixpoint.
12671267
approx_iter_type(itrT::Type) = _approx_iter_type(itrT, Base._return_type(iterate, Tuple{itrT}))
12681268
# Not actually called, just passed to return type to avoid
1269-
# having to typesubtract
1269+
# having to typesplit on Nothing
12701270
function doiterate(itr, valstate::Union{Nothing, Tuple{Any, Any}})
12711271
valstate === nothing && return nothing
12721272
val, st = valstate

base/missing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Any
3636
!!! compat "Julia 1.3"
3737
This function is exported as of Julia 1.3.
3838
"""
39-
nonmissingtype(::Type{T}) where {T} = Core.Compiler.typesubtract(T, Missing)
39+
nonmissingtype(::Type{T}) where {T} = typesplit(T, Missing)
4040

4141
function nonmissingtype_checked(T::Type)
4242
R = nonmissingtype(T)

base/promotion.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ function typejoin(@nospecialize(a), @nospecialize(b))
121121
return Any
122122
end
123123

124+
# return an upper-bound on type `a` with type `b` removed
125+
# such that `return <: a` && `Union{return, b} == Union{a, b}`
126+
# WARNING: this is wrong for some objects for which subtyping is broken
127+
# (Core.Compiler.isnotbrokensubtype), use only simple types for `b`
128+
function typesplit(@nospecialize(a), @nospecialize(b))
129+
@_pure_meta
130+
if a <: b
131+
return Bottom
132+
end
133+
if isa(a, Union)
134+
return Union{typesplit(a.a, b),
135+
typesplit(a.b, b)}
136+
end
137+
return a
138+
end
139+
140+
124141
"""
125142
promote_typejoin(T, S)
126143
@@ -132,7 +149,7 @@ function promote_typejoin(@nospecialize(a), @nospecialize(b))
132149
c = typejoin(_promote_typesubtract(a), _promote_typesubtract(b))
133150
return Union{a, b, c}::Type
134151
end
135-
_promote_typesubtract(@nospecialize(a)) = Core.Compiler.typesubtract(a, Union{Nothing, Missing})
152+
_promote_typesubtract(@nospecialize(a)) = typesplit(a, Union{Nothing, Missing})
136153

137154

138155
# Returns length, isfixed

base/set.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ promote_valuetype(x::Pair{K, V}, y::Pair...) where {K, V} =
570570
# Subtract singleton types which are going to be replaced
571571
function subtract_singletontype(::Type{T}, x::Pair{K}) where {T, K}
572572
if issingletontype(K)
573-
Core.Compiler.typesubtract(T, K)
573+
typesplit(T, K)
574574
else
575575
T
576576
end

base/some.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Some(::Type{T}) where {T} = Some{Type{T}}(T)
1616

1717
promote_rule(::Type{Some{T}}, ::Type{Some{S}}) where {T, S<:T} = Some{T}
1818

19-
nonnothingtype(::Type{T}) where {T} = Core.Compiler.typesubtract(T, Nothing)
19+
nonnothingtype(::Type{T}) where {T} = typesplit(T, Nothing)
2020
promote_rule(T::Type{Nothing}, S::Type) = Union{S, Nothing}
2121
function promote_rule(T::Type{>:Nothing}, S::Type)
2222
R = nonnothingtype(T)

0 commit comments

Comments
 (0)