Skip to content

Commit

Permalink
compiler: eliminate Core.Compiler. qualifier (JuliaLang#52790)
Browse files Browse the repository at this point in the history
To avoid symbol name clashes, this commit defines and uses
`partialorder(𝕃::AbstractLattice) = βŠ‘(𝕃)`. While I have a preference for
a 2-arg binary operator for lattice operations, it's currently
coexisting with a 3-arg version, suggesting that a unification might be
beneficial.
  • Loading branch information
aviatesk committed Jan 9, 2024
1 parent 4b64203 commit c0c676b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
9 changes: 6 additions & 3 deletions base/compiler/abstractlattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ has_extended_unionsplit(::AnyMustAliasesLattice) = true
has_extended_unionsplit(::JLTypeLattice) = false

# Curried versions
βŠ‘(lattice::AbstractLattice) = (@nospecialize(a), @nospecialize(b)) -> βŠ‘(lattice, a, b)
⊏(lattice::AbstractLattice) = (@nospecialize(a), @nospecialize(b)) -> ⊏(lattice, a, b)
β‹€(lattice::AbstractLattice) = (@nospecialize(a), @nospecialize(b)) -> β‹€(lattice, a, b)
βŠ‘(𝕃::AbstractLattice) = (@nospecialize(a), @nospecialize(b)) -> βŠ‘(𝕃, a, b)
⊏(𝕃::AbstractLattice) = (@nospecialize(a), @nospecialize(b)) -> ⊏(𝕃, a, b)
β‹€(𝕃::AbstractLattice) = (@nospecialize(a), @nospecialize(b)) -> β‹€(𝕃, a, b)
partialorder(𝕃::AbstractLattice) = βŠ‘(𝕃)
strictpartialorder(𝕃::AbstractLattice) = ⊏(𝕃)
strictneqpartialorder(𝕃::AbstractLattice) = β‹€(𝕃)

# Fallbacks for external packages using these methods
const fallback_lattice = InferenceLattice(BaseInferenceLattice.instance)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ function find_ssavalue_uses1(compact::IncrementalCompact)
end

function _oracle_check(compact::IncrementalCompact)
(observed_used_ssas, observed_used_newssas) = Core.Compiler.find_ssavalue_uses1(compact)
(observed_used_ssas, observed_used_newssas) = find_ssavalue_uses1(compact)
for i = 1:length(observed_used_ssas)
if observed_used_ssas[i] != compact.used_ssas[i]
return (observed_used_ssas, observed_used_newssas, SSAValue(i))
Expand Down
33 changes: 17 additions & 16 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ end
add_tfunc(Core.ifelse, 3, 3, ifelse_tfunc, 1)

@nospecs function ifelse_nothrow(𝕃::AbstractLattice, cond, x, y)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
return cond βŠ‘ Bool
end

Expand Down Expand Up @@ -380,7 +380,7 @@ function isdefined_nothrow(𝕃::AbstractLattice, argtypes::Vector{Any})
return isdefined_nothrow(𝕃, argtypes[1], argtypes[2])
end
@nospecs function isdefined_nothrow(𝕃::AbstractLattice, x, name)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
isvarargtype(x) && return false
isvarargtype(name) && return false
if hasintersect(widenconst(x), Module)
Expand Down Expand Up @@ -600,7 +600,8 @@ add_tfunc(svec, 0, INT_INF, @nospecs((𝕃::AbstractLattice, args...)->SimpleVec
end
return TypeVar
end
@nospecs function typebound_nothrow(b)
@nospecs function typebound_nothrow(𝕃::AbstractLattice, b)
βŠ‘ = partialorder(𝕃)
b = widenconst(b)
(b βŠ‘ TypeVar) && return true
if isType(b)
Expand All @@ -609,10 +610,10 @@ end
return false
end
@nospecs function typevar_nothrow(𝕃::AbstractLattice, n, lb, ub)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
n βŠ‘ Symbol || return false
typebound_nothrow(lb) || return false
typebound_nothrow(ub) || return false
typebound_nothrow(𝕃, lb) || return false
typebound_nothrow(𝕃, ub) || return false
return true
end
add_tfunc(Core._typevar, 3, 3, typevar_tfunc, 100)
Expand Down Expand Up @@ -813,7 +814,7 @@ end
add_tfunc(typeassert, 2, 2, typeassert_tfunc, 4)

@nospecs function typeassert_nothrow(𝕃::AbstractLattice, v, t)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
# ty, exact = instanceof_tfunc(t, true)
# return exact && v βŠ‘ ty
if (isType(t) && !has_free_typevars(t) && v βŠ‘ t.parameters[1]) ||
Expand Down Expand Up @@ -859,7 +860,7 @@ end
add_tfunc(isa, 2, 2, isa_tfunc, 1)

@nospecs function isa_nothrow(𝕃::AbstractLattice, obj, typ)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
return typ βŠ‘ Type
end

Expand All @@ -882,7 +883,7 @@ end
add_tfunc(<:, 2, 2, subtype_tfunc, 10)

@nospecs function subtype_nothrow(𝕃::AbstractLattice, lty, rty)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
return lty βŠ‘ Type && rty βŠ‘ Type
end

Expand Down Expand Up @@ -981,7 +982,7 @@ end
isa(name, Const) || return false
end

βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)

# If we have s00 being a const, we can potentially refine our type-based analysis above
if isa(s00, Const) || isconstType(s00)
Expand Down Expand Up @@ -1340,7 +1341,6 @@ end
return setfield!_nothrow(𝕃, s00, name, v)
end
@nospecs function setfield!_nothrow(𝕃::AbstractLattice, s00, name, v)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
s0 = widenconst(s00)
s = unwrap_unionall(s0)
if isa(s, Union)
Expand All @@ -1357,6 +1357,7 @@ end
isconst(s, field) && return false
isfieldatomic(s, field) && return false # TODO: currently we're only testing for ordering === :not_atomic
v_expected = fieldtype(s0, field)
βŠ‘ = partialorder(𝕃)
return v βŠ‘ v_expected
end
return false
Expand Down Expand Up @@ -1431,7 +1432,7 @@ add_tfunc(replacefield!, 4, 6, replacefield!_tfunc, 3)

@nospecs function fieldtype_nothrow(𝕃::AbstractLattice, s0, name)
s0 === Bottom && return true # unreachable
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
if s0 === Any || s0 === Type || DataType βŠ‘ s0 || UnionAll βŠ‘ s0
# We have no idea
return false
Expand Down Expand Up @@ -2090,7 +2091,7 @@ end
elemtype_expected = memoryref_elemtype(memtype)
elemtype_expected === Union{} && return false
# Check that the element type is compatible with the element we're assigning
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
elemtype βŠ‘ elemtype_expected || return false
return true
end
Expand Down Expand Up @@ -2149,13 +2150,13 @@ function memoryrefop_builtin_common_nothrow(𝕃::AbstractLattice, argtypes::Vec
end

@nospecs function memoryref_builtin_common_typecheck(𝕃::AbstractLattice, boundscheck, memtype, order)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
return boundscheck βŠ‘ Bool && memtype βŠ‘ GenericMemoryRef && order βŠ‘ Symbol
end

# Query whether the given builtin is guaranteed not to throw given the argtypes
@nospecs function _builtin_nothrow(𝕃::AbstractLattice, f, argtypes::Vector{Any}, rt)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
if f === memoryref
return memoryref_builtin_common_nothrow(argtypes)
elseif f === memoryrefoffset
Expand Down Expand Up @@ -3108,7 +3109,7 @@ end
add_tfunc(Core.get_binding_type, 2, 2, get_binding_type_tfunc, 0)

@nospecs function get_binding_type_nothrow(𝕃::AbstractLattice, M, s)
βŠ‘ = Core.Compiler.:βŠ‘(𝕃)
βŠ‘ = partialorder(𝕃)
return M βŠ‘ Module && s βŠ‘ Symbol
end

Expand Down

0 comments on commit c0c676b

Please sign in to comment.