Skip to content

Commit 129cfdf

Browse files
committed
Remove use of simplified in MT reduction
I gave match type's redux an extension to the normalize algorithm, in order to make the test suite pass, as well as add an extra recursion to the simplify algorithm. A few neg tests tweaked and some other code changes could be dropped.
1 parent 9726e1a commit 129cfdf

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,15 +3136,15 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
31363136
case param @ TypeParamRef(b, n) if b eq caseLambda =>
31373137
insts(n) =
31383138
if canApprox then
3139-
approximation(param, fromBelow = variance >= 0, Int.MaxValue).simplified
3139+
approximation(param, fromBelow = variance >= 0, Int.MaxValue).normalized
31403140
else constraint.entry(param) match
31413141
case entry: TypeBounds =>
31423142
val lo = fullLowerBound(param)
31433143
val hi = fullUpperBound(param)
3144-
if !poisoned(param) && isSubType(hi, lo) then lo.simplified else Range(lo, hi)
3144+
if !poisoned(param) && isSubType(hi, lo) then lo.normalized else Range(lo, hi)
31453145
case inst =>
31463146
assert(inst.exists, i"param = $param\nconstraint = $constraint")
3147-
if !poisoned(param) then inst.simplified else Range(inst, inst)
3147+
if !poisoned(param) then inst.normalized else Range(inst, inst)
31483148
insts
31493149
case _ =>
31503150
foldOver(insts, t)
@@ -3166,6 +3166,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
31663166
}
31673167
}
31683168

3169+
def normalizeHard(tp: Type): Type = tp.tryNormalize.orElse(tp match {
3170+
case tp: AppliedType => tp.map(normalizeHard)
3171+
case _ => tp
3172+
})
3173+
31693174
/** Match a single case. */
31703175
def matchCase(cas: Type): MatchResult = trace(i"$scrut match ${MatchTypeTrace.caseText(cas)}", matchTypes, show = true) {
31713176
val cas1 = cas match {
@@ -3229,7 +3234,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
32293234
MatchTypeTrace.noInstance(scrut, cas, fails)
32303235
NoType
32313236
case MatchResult.Reduced(tp) =>
3232-
tp.simplified
3237+
normalizeHard(tp)
32333238
case Nil =>
32343239
val casesText = MatchTypeTrace.noMatchesText(scrut, cases)
32353240
ErrorType(reporting.MatchTypeNoCases(casesText))

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ object TypeOps:
184184
else tp.derivedAnnotatedType(parent1, annot)
185185
case _: MatchType =>
186186
val normed = tp.tryNormalize
187-
if (normed.exists) normed else mapOver
187+
if (normed.exists) simplify(normed, theMap) else mapOver
188188
case tp: MethodicType =>
189189
// See documentation of `Types#simplified`
190190
val addTypeVars = new TypeMap with IdempotentCaptRefMap:

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ object Types {
359359
* (since these are relevant for inference or resolution) but never consider prefixes
360360
* (since these often do not constrain the search space anyway).
361361
*/
362-
def unusableForInference(using Context): Boolean = try widenDealias match
362+
def unusableForInference(using Context): Boolean = widenDealias match
363363
case AppliedType(tycon, args) => tycon.unusableForInference || args.exists(_.unusableForInference)
364364
case RefinedType(parent, _, rinfo) => parent.unusableForInference || rinfo.unusableForInference
365365
case TypeBounds(lo, hi) => lo.unusableForInference || hi.unusableForInference
@@ -369,7 +369,6 @@ object Types {
369369
case CapturingType(parent, refs) => parent.unusableForInference || refs.elems.exists(_.unusableForInference)
370370
case _: ErrorType => true
371371
case _ => false
372-
catch case ex: Throwable => handleRecursive("unusableForInference", show, ex)
373372

374373
/** Does the type carry an annotation that is an instance of `cls`? */
375374
@tailrec final def hasAnnotation(cls: ClassSymbol)(using Context): Boolean = stripTypeVar match {

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ object Inferencing {
198198
case tp => foldOver(x, tp)
199199
}
200200
catch case ex: Throwable =>
201-
handleRecursive("check fully defined", tp.showSummary(20), ex)
201+
handleRecursive("check fully defined", tp.show, ex)
202202
}
203203

204204
def process(tp: Type): Boolean =

tests/neg-custom-args/isInstanceOf/i17435.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ object Test:
1414
type JsonArray = mutable.Buffer[Json]
1515

1616
def encode(x: Json): Int = x match
17-
case str: String => 1 // error
18-
case b: Boolean => 2 // error
19-
case i: Int => 3 // error
20-
case d: Double => 4 // error
17+
case str: String => 1
18+
case b: Boolean => 2
19+
case i: Int => 3
20+
case d: Double => 4
2121
case arr: JsonArray => 5 // error
2222
case obj: JsonObject => 6 // error
2323
case _ => 7

tests/neg/i15158.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ class Spec {
3838
JsonPrimitive
3939
]
4040

41-
val arr = new mutable.ArrayBuffer[Json](8) // error
41+
val arr = new mutable.ArrayBuffer[Json](8)
4242
}
4343
}

0 commit comments

Comments
 (0)