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

Retry constraint.replace after constraint.updateEntry #20399

Merged
merged 4 commits into from
May 16, 2024
Merged
Changes from 1 commit
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
22 changes: 14 additions & 8 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,18 @@ trait ConstraintHandling {
false
else
val bound = legalBound(param, rawBound, isUpper)
lazy val recBound = bound.existsPart(_ eq param, StopAt.Static)

// If the narrowed bounds are equal and not recursive,
// we can remove `param` from the constraint.
def tryReplace(lo: Type, hi: Type): Boolean =
val equalBounds = (if isUpper then lo else hi) eq bound
val canReplace = equalBounds && !recBound
if canReplace then constraint = constraint.replace(param, bound)
canReplace

val oldBounds @ TypeBounds(lo, hi) = constraint.nonParamBounds(param)
val equalBounds = (if isUpper then lo else hi) eq bound
if equalBounds && !bound.existsPart(_ eq param, StopAt.Static) then
// The narrowed bounds are equal and not recursive,
// so we can remove `param` from the constraint.
constraint = constraint.replace(param, bound)
true
else
tryReplace(lo, hi) || locally:
// Narrow one of the bounds of type parameter `param`
// If `isUpper` is true, ensure that `param <: `bound`, otherwise ensure
// that `param >: bound`.
Expand All @@ -328,7 +332,9 @@ trait ConstraintHandling {
|| {
constraint = c1
val TypeBounds(lo, hi) = constraint.entry(param): @unchecked
isSub(lo, hi)
val isSat = isSub(lo, hi)
if isSat then tryReplace(lo, hi) // isSub may have introduced new constraints
EugeneFlesselle marked this conversation as resolved.
Show resolved Hide resolved
isSat
}
end addOneBound

Expand Down
Loading