Skip to content

Commit 74bdcf5

Browse files
committed
Merge pull request #12971 from dotty-staging/add-rechecker
Add recheck phase
1 parent 29e4b05 commit 74bdcf5

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
@@ -174,4 +174,24 @@ object NamerOps:
174174
cls.registeredCompanion = modcls
175175
modcls.registeredCompanion = cls
176176

177+
/** For secondary constructors, make it known in the context that their type parameters
178+
* are aliases of the class type parameters. This is done by (ab?)-using GADT constraints.
179+
* See pos/i941.scala
180+
*/
181+
def linkConstructorParams(sym: Symbol)(using Context): Context =
182+
if sym.isConstructor && !sym.isPrimaryConstructor then
183+
sym.rawParamss match
184+
case (tparams @ (tparam :: _)) :: _ if tparam.isType =>
185+
val rhsCtx = ctx.fresh.setFreshGADTBounds
186+
rhsCtx.gadt.addToConstraint(tparams)
187+
tparams.lazyZip(sym.owner.typeParams).foreach { (psym, tparam) =>
188+
val tr = tparam.typeRef
189+
rhsCtx.gadt.addBound(psym, tr, isUpper = false)
190+
rhsCtx.gadt.addBound(psym, tr, isUpper = true)
191+
}
192+
rhsCtx
193+
case _ =>
194+
ctx
195+
else ctx
196+
177197
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
@@ -738,6 +738,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
738738
false
739739
}
740740
compareClassInfo
741+
case tp2: SkolemType =>
742+
ctx.phase.widenSkolems && recur(tp1, tp2.info) || fourthTry
741743
case _ =>
742744
fourthTry
743745
}
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)