Skip to content

Commit 09ca850

Browse files
committed
Change Config flag
The Config flag (renamed to `checkedLevelsOnConstraints`) now picks between original level checking (as implemented in #14026) and instantiation checking.
1 parent 7385fba commit 09ca850

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ object Config {
227227
*/
228228
inline val reuseSymDenotations = true
229229

230-
/** If true, check levels of type variables and create fresh ones as needed.
231-
* This is necessary for soundness (see 3ab18a9), but also causes several
232-
* regressions that should be fixed before turning this on.
230+
/** If true, check levels of type variables and create fresh ones as needed
231+
* when bounds are first entered intot he constraint. If false, allow
232+
* level-incorrect constraints but fix levels on type variable instantiation.
233233
*/
234-
inline val checkLevels = false
234+
inline val checkLevelsOnConstraints = false
235+
235236
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ trait ConstraintHandling {
103103
* of `1`. So the lower bound is `1 | x.M` and when we level-avoid that we
104104
* get `1 | Int & String`, which simplifies to `Int`.
105105
*/
106-
protected var trustBounds = true
106+
private var myTrustBounds = true
107107

108108
inline def withUntrustedBounds(op: => Type): Type =
109-
val saved = trustBounds
110-
trustBounds = false
111-
try op finally trustBounds = saved
109+
val saved = myTrustBounds
110+
myTrustBounds = false
111+
try op finally myTrustBounds = saved
112+
113+
def trustBounds: Boolean =
114+
Config.checkLevelsOnConstraints || myTrustBounds
112115

113116
def checkReset() =
114117
assert(addConstraintInvocations == 0)
@@ -131,7 +134,7 @@ trait ConstraintHandling {
131134
level <= maxLevel
132135
|| ctx.isAfterTyper || !ctx.typerState.isCommittable // Leaks in these cases shouldn't break soundness
133136
|| level == Int.MaxValue // See `nestingLevel` above.
134-
|| !Config.checkLevels
137+
|| !Config.checkLevelsOnConstraints
135138

136139
/** If `param` is nested deeper than `maxLevel`, try to instantiate it to a
137140
* fresh type variable of level `maxLevel` and return the new variable.
@@ -518,7 +521,7 @@ trait ConstraintHandling {
518521
if !fromBelow then variance = -1
519522
def toAvoid(tp: NamedType) = needsFix(tp)
520523

521-
if ctx.isAfterTyper then tp
524+
if Config.checkLevelsOnConstraints || ctx.isAfterTyper then tp
522525
else
523526
val needsLeveling = NeedsLeveling()
524527
if needsLeveling(false, tp) then

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class TreePickler(pickler: TastyPickler) {
206206
}
207207
else if (tpe.prefix == NoPrefix) {
208208
writeByte(if (tpe.isType) TYPEREFdirect else TERMREFdirect)
209-
if Config.checkLevels && !symRefs.contains(sym) && !sym.isPatternBound && !sym.hasAnnotation(defn.QuotedRuntimePatterns_patternTypeAnnot) then
209+
if Config.checkLevelsOnConstraints && !symRefs.contains(sym) && !sym.isPatternBound && !sym.hasAnnotation(defn.QuotedRuntimePatterns_patternTypeAnnot) then
210210
report.error(i"pickling reference to as yet undefined $tpe with symbol ${sym}", sym.srcPos)
211211
pickleSymRef(sym)
212212
}

0 commit comments

Comments
 (0)