Skip to content

Commit 7616094

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

18 files changed

+454
-17
lines changed

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

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

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

+1
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

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

303304
/** Area-specific debug output */
304305
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

+20
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,24 @@ object NamerOps:
177177
cls.registeredCompanion = modcls
178178
modcls.registeredCompanion = cls
179179

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

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

+3
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ object Phases {
295295
/** If set, implicit search is enabled */
296296
def allowsImplicitSearch: Boolean = false
297297

298+
/** If set equate Skolem types with underlying types */
299+
def widenSkolems: Boolean = false
300+
298301
/** List of names of phases that should precede this phase */
299302
def runsAfter: Set[String] = Set.empty
300303

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

+2
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
745745
false
746746
}
747747
compareClassInfo
748+
case tp2: SkolemType =>
749+
ctx.phase.widenSkolems && recur(tp1, tp2.info) || fourthTry
748750
case _ =>
749751
fourthTry
750752
}
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)