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

compiler: eliminate Core.Compiler. qualifier #52790

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
compiler: eliminate Core.Compiler. qualifier
  • Loading branch information
aviatesk committed Jan 7, 2024
commit b799e84f4b3ed78a7b238c13614ca2bd38ce7c34
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(𝕃)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the Compiler.:βŠ‘ is okay, just not Core to make it global. Or this very annoying syntax with let global to rebind it:

julia> using Core.Compiler: βŠ‘

julia> f(𝕃) = (βŠ‘ = let; global βŠ‘; βŠ‘(𝕃); end)
f (generic function with 1 method)

julia> f(𝕃)

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think whether βŠ‘ = partialorder(𝕃) is clearer than βŠ‘ = Compiler.:βŠ‘(𝕃). In the same vein, I'm also thinking about replacing tmerge with βŠ” = join(𝕃). What do you think?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems fine too. Though maybe a bit confusing that it is not an optimal join on the 𝕃 (that would be Union), but rather on the complexity co-lattice

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Then, we might consider refactoring to switch to the 2-arg form using partialorder(𝕃) or widening(𝕃) (or weakjoin(𝕃)?). This could turn into a significant refactor, so it might be best to undertake it after finishing the upcoming expected refactors.
Anyway, I would like to move this PR forward for now. @Keno please let me know if you have a preference for the current 3-arg form.

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