Skip to content

Commit

Permalink
better implementations for unionlen/uniontypes (#55561)
Browse files Browse the repository at this point in the history
- unify the dispatch targets
- removed unnecessary `_uniontypes(::MustAlias)` method
  • Loading branch information
aviatesk authored Aug 23, 2024
1 parent 6866b11 commit 0c64283
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 0 additions & 2 deletions base/compiler/typelattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ end
MustAlias(var::SlotNumber, @nospecialize(vartyp), fldidx::Int, @nospecialize(fldtyp)) =
MustAlias(slot_id(var), vartyp, fldidx, fldtyp)

_uniontypes(x::MustAlias, ts) = _uniontypes(widenconst(x), ts)

"""
alias::InterMustAlias
Expand Down
14 changes: 10 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,17 @@ hasgenerator(m::Core.MethodInstance) = hasgenerator(m.def::Method)

# low-level method lookup functions used by the compiler

unionlen(x::Union) = unionlen(x.a) + unionlen(x.b)
unionlen(@nospecialize(x)) = 1
unionlen(@nospecialize(x)) = x isa Union ? unionlen(x.a) + unionlen(x.b) : 1

_uniontypes(x::Union, ts) = (_uniontypes(x.a,ts); _uniontypes(x.b,ts); ts)
_uniontypes(@nospecialize(x), ts) = (push!(ts, x); ts)
function _uniontypes(@nospecialize(x), ts::Array{Any,1})
if x isa Union
_uniontypes(x.a, ts)
_uniontypes(x.b, ts)
else
push!(ts, x)
end
return ts
end
uniontypes(@nospecialize(x)) = _uniontypes(x, Any[])

function _methods(@nospecialize(f), @nospecialize(t), lim::Int, world::UInt)
Expand Down

0 comments on commit 0c64283

Please sign in to comment.