Skip to content

Commit 870f45d

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

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
@@ -100,6 +100,8 @@ class Compiler {
100100
new TupleOptimizations, // Optimize generic operations on tuples
101101
new LetOverApply, // Lift blocks from receivers of applications
102102
new ArrayConstructors) :: // Intercept creation of (non-generic) arrays and intrinsify.
103+
List(new PreRecheck) ::
104+
List(new TestRecheck) ::
103105
List(new Erasure) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
104106
List(new ElimErasedValueType, // Expand erased value types to their underlying implmementation types
105107
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
@@ -321,6 +321,7 @@ private sealed trait YSettings:
321321
val YexplicitNulls: Setting[Boolean] = BooleanSetting("-Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
322322
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
323323
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
324+
val Yrecheck: Setting[Boolean] = BooleanSetting("-Yrecheck", "Run type rechecks (test only)")
324325

325326
/** Area-specific debug output */
326327
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
@@ -191,4 +191,24 @@ object NamerOps:
191191
cls.registeredCompanion = modcls
192192
modcls.registeredCompanion = cls
193193

194+
/** For secondary constructors, make it known in the context that their type parameters
195+
* are aliases of the class type parameters. This is done by (ab?)-using GADT constraints.
196+
* See pos/i941.scala
197+
*/
198+
def linkConstructorParams(sym: Symbol)(using Context): Context =
199+
if sym.isConstructor && !sym.isPrimaryConstructor then
200+
sym.rawParamss match
201+
case (tparams @ (tparam :: _)) :: _ if tparam.isType =>
202+
val rhsCtx = ctx.fresh.setFreshGADTBounds
203+
rhsCtx.gadt.addToConstraint(tparams)
204+
tparams.lazyZip(sym.owner.typeParams).foreach { (psym, tparam) =>
205+
val tr = tparam.typeRef
206+
rhsCtx.gadt.addBound(psym, tr, isUpper = false)
207+
rhsCtx.gadt.addBound(psym, tr, isUpper = true)
208+
}
209+
rhsCtx
210+
case _ =>
211+
ctx
212+
else ctx
213+
194214
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
@@ -751,6 +751,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
751751
false
752752
}
753753
compareClassInfo
754+
case tp2: SkolemType =>
755+
ctx.phase.widenSkolems && recur(tp1, tp2.info) || fourthTry
754756
case _ =>
755757
fourthTry
756758
}
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)