Skip to content

Commit 98bc26d

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

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
@@ -311,6 +311,7 @@ private sealed trait YSettings:
311311
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
312312
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
313313
val YscalaRelease: Setting[String] = ChoiceSetting("-Yscala-release", "release", "Emit TASTy files that can be consumed by specified version of the compiler. The compilation will fail if for any reason valid TASTy cannot be produced (e.g. the code contains references to some parts of the standard library API that are missing in the older stdlib or uses language features unexpressible in the older version of TASTy format)", ScalaSettings.supportedScalaReleaseVersions, "", aliases = List("--Yscala-release"))
314+
val Yrecheck: Setting[Boolean] = BooleanSetting("-Yrecheck", "Run type rechecks (test only)")
314315

315316
/** Area-specific debug output */
316317
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
@@ -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

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)