Skip to content

Commit 07a60d7

Browse files
committed
Merge pull request #12971 from dotty-staging/add-rechecker
Add recheck phase
1 parent fdd43d7 commit 07a60d7

18 files changed

+446
-12
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class Compiler {
103103
new TupleOptimizations, // Optimize generic operations on tuples
104104
new LetOverApply, // Lift blocks from receivers of applications
105105
new ArrayConstructors) :: // Intercept creation of (non-generic) arrays and intrinsify.
106+
List(new PreRecheck) ::
107+
List(new TestRecheck) ::
106108
List(new Erasure) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
107109
List(new ElimErasedValueType, // Expand erased value types to their underlying implmementation types
108110
new PureStats, // Remove pure stats from blocks

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ object Printers {
3838
val pickling = noPrinter
3939
val quotePickling = noPrinter
4040
val plugins = noPrinter
41+
val recheckr = noPrinter
4142
val refcheck = noPrinter
4243
val simplify = noPrinter
4344
val staging = noPrinter

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ private sealed trait YSettings:
314314
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
315315
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
316316
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
317+
val Yrecheck: Setting[Boolean] = BooleanSetting("-Yrecheck", "Run type rechecks (test only)")
317318

318319
/** Area-specific debug output */
319320
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,24 @@ object NamerOps:
182182
cls.registeredCompanion = modcls
183183
modcls.registeredCompanion = cls
184184

185+
/** For secondary constructors, make it known in the context that their type parameters
186+
* are aliases of the class type parameters. This is done by (ab?)-using GADT constraints.
187+
* See pos/i941.scala
188+
*/
189+
def linkConstructorParams(sym: Symbol)(using Context): Context =
190+
if sym.isConstructor && !sym.isPrimaryConstructor then
191+
sym.rawParamss match
192+
case (tparams @ (tparam :: _)) :: _ if tparam.isType =>
193+
val rhsCtx = ctx.fresh.setFreshGADTBounds
194+
rhsCtx.gadt.addToConstraint(tparams)
195+
tparams.lazyZip(sym.owner.typeParams).foreach { (psym, tparam) =>
196+
val tr = tparam.typeRef
197+
rhsCtx.gadt.addBound(psym, tr, isUpper = false)
198+
rhsCtx.gadt.addBound(psym, tr, isUpper = true)
199+
}
200+
rhsCtx
201+
case _ =>
202+
ctx
203+
else ctx
204+
185205
end NamerOps

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ object Phases {
298298
/** If set, implicit search is enabled */
299299
def allowsImplicitSearch: Boolean = false
300300

301+
/** If set equate Skolem types with underlying types */
302+
def widenSkolems: Boolean = false
303+
301304
/** List of names of phases that should precede this phase */
302305
def runsAfter: Set[String] = Set.empty
303306

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
739739
false
740740
}
741741
compareClassInfo
742+
case tp2: SkolemType =>
743+
ctx.phase.widenSkolems && recur(tp1, tp2.info) || fourthTry
742744
case _ =>
743745
fourthTry
744746
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package dotty.tools.dotc
2+
package transform
3+
4+
import core.Phases.Phase
5+
import core.DenotTransformers.IdentityDenotTransformer
6+
import core.Contexts.{Context, ctx}
7+
8+
/** A phase that precedes the rechecker and that allows installing
9+
* new types for local symbols.
10+
*/
11+
class PreRecheck extends Phase, IdentityDenotTransformer:
12+
13+
def phaseName: String = "preRecheck"
14+
15+
override def isEnabled(using Context) = next.isEnabled
16+
17+
override def changesBaseTypes: Boolean = true
18+
19+
def run(using Context): Unit = ()
20+
21+
override def isCheckable = false

0 commit comments

Comments
 (0)