From 7630606f16a3c35c54ed151d6cc31fcdb4e6def2 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Sun, 22 Jan 2023 00:37:04 -0500 Subject: [PATCH] Further tweaks to LimitedAccuracy lattice operations (#48126) As discussed in #48045: 1. Switch the order of `causes` inclusion to make wider elements have fewer causes. 2. Fix two typos 3. Restore property that equal ulimited types will be preserved (though with potentially updated `causes` lists). --- base/compiler/typelattice.jl | 2 +- base/compiler/typelimits.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base/compiler/typelattice.jl b/base/compiler/typelattice.jl index 831219e70a29c..33d4d37e9c936 100644 --- a/base/compiler/typelattice.jl +++ b/base/compiler/typelattice.jl @@ -415,7 +415,7 @@ function ⊑(lattice::InferenceLattice, @nospecialize(a), @nospecialize(b)) # a and b's unlimited types are equal. isa(a, LimitedAccuracy) || return false # b is limited, so ε smaller - return a.causes ⊆ b.causes + return b.causes ⊆ a.causes end function ⊑(lattice::OptimizerLattice, @nospecialize(a), @nospecialize(b)) diff --git a/base/compiler/typelimits.jl b/base/compiler/typelimits.jl index c09cf4e5d0f91..ed9db007bdbc8 100644 --- a/base/compiler/typelimits.jl +++ b/base/compiler/typelimits.jl @@ -422,8 +422,7 @@ end # Approximated types are lattice equal. Merge causes. if suba && subb - causes = merge_causes(causesa, causesb) - issimplertype(lattice, typeb, typea) && return LimitedAccuracy(typeb, causesb) + return LimitedAccuracy(typeb, merge_causes(causesa, causesb)) elseif suba issimplertype(lattice, typeb, typea) && return LimitedAccuracy(typeb, causesb) causes = causesb @@ -453,6 +452,7 @@ end subb = ⊑(lattice, typeb, typea) end + suba && subb && return LimitedAccuracy(typea, causes) subb && issimplertype(lattice, typea, typeb) && return LimitedAccuracy(typea, causes) return LimitedAccuracy(tmerge(widenlattice(lattice), typea, typeb), causes) end