Skip to content

Commit

Permalink
Merge pull request #12971 from dotty-staging/add-rechecker
Browse files Browse the repository at this point in the history
Add recheck phase
  • Loading branch information
odersky committed Feb 25, 2022
1 parent 29e4b05 commit 74bdcf5
Show file tree
Hide file tree
Showing 18 changed files with 446 additions and 12 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class Compiler {
new TupleOptimizations, // Optimize generic operations on tuples
new LetOverApply, // Lift blocks from receivers of applications
new ArrayConstructors) :: // Intercept creation of (non-generic) arrays and intrinsify.
List(new PreRecheck) ::
List(new TestRecheck) ::
List(new Erasure) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
List(new ElimErasedValueType, // Expand erased value types to their underlying implmementation types
new PureStats, // Remove pure stats from blocks
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object Printers {
val pickling = noPrinter
val quotePickling = noPrinter
val plugins = noPrinter
val recheckr = noPrinter
val refcheck = noPrinter
val simplify = noPrinter
val staging = noPrinter
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private sealed trait YSettings:
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
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"))
val Yrecheck: Setting[Boolean] = BooleanSetting("-Yrecheck", "Run type rechecks (test only)")

/** Area-specific debug output */
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
Expand Down
20 changes: 20 additions & 0 deletions compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,24 @@ object NamerOps:
cls.registeredCompanion = modcls
modcls.registeredCompanion = cls

/** For secondary constructors, make it known in the context that their type parameters
* are aliases of the class type parameters. This is done by (ab?)-using GADT constraints.
* See pos/i941.scala
*/
def linkConstructorParams(sym: Symbol)(using Context): Context =
if sym.isConstructor && !sym.isPrimaryConstructor then
sym.rawParamss match
case (tparams @ (tparam :: _)) :: _ if tparam.isType =>
val rhsCtx = ctx.fresh.setFreshGADTBounds
rhsCtx.gadt.addToConstraint(tparams)
tparams.lazyZip(sym.owner.typeParams).foreach { (psym, tparam) =>
val tr = tparam.typeRef
rhsCtx.gadt.addBound(psym, tr, isUpper = false)
rhsCtx.gadt.addBound(psym, tr, isUpper = true)
}
rhsCtx
case _ =>
ctx
else ctx

end NamerOps
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ object Phases {
/** If set, implicit search is enabled */
def allowsImplicitSearch: Boolean = false

/** If set equate Skolem types with underlying types */
def widenSkolems: Boolean = false

/** List of names of phases that should precede this phase */
def runsAfter: Set[String] = Set.empty

Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
false
}
compareClassInfo
case tp2: SkolemType =>
ctx.phase.widenSkolems && recur(tp1, tp2.info) || fourthTry
case _ =>
fourthTry
}
Expand Down
21 changes: 21 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/PreRecheck.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dotty.tools.dotc
package transform

import core.Phases.Phase
import core.DenotTransformers.IdentityDenotTransformer
import core.Contexts.{Context, ctx}

/** A phase that precedes the rechecker and that allows installing
* new types for local symbols.
*/
class PreRecheck extends Phase, IdentityDenotTransformer:

def phaseName: String = "preRecheck"

override def isEnabled(using Context) = next.isEnabled

override def changesBaseTypes: Boolean = true

def run(using Context): Unit = ()

override def isCheckable = false
Loading

0 comments on commit 74bdcf5

Please sign in to comment.