Skip to content

Leaner Context objects #3136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ object Contexts {
final def withPhaseNoEarlier(phase: Phase) =
if (phase.exists && ctx.phase.id < phase.id) withPhase(phase) else ctx

// `creationTrace`-related code. To enable, uncomment the code below and the
// call to `setCreationTrace()` in this file.
/*
/** If -Ydebug is on, the top of the stack trace where this context
* was created, otherwise `null`.
*/
Expand All @@ -281,6 +284,7 @@ object Contexts {
}
println("=== end context creation trace ===")
}
*/

/** The current reporter */
def reporter: Reporter = typerState.reporter
Expand Down Expand Up @@ -414,7 +418,8 @@ object Contexts {
this.implicitsCache = null
this.phasedCtx = this
this.phasedCtxs = null
setCreationTrace()
// See comment related to `creationTrace` in this file
// setCreationTrace()
this
}

Expand Down
10 changes: 0 additions & 10 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
private def isLegalPrefix(pre: Type)(implicit ctx: Context) =
pre.isStable || !ctx.phase.isTyper

/** Approximate a type `tp` with a type that does not contain skolem types. */
object deskolemize extends ApproximatingTypeMap {
def apply(tp: Type) = /*ctx.traceIndented(i"deskolemize($tp) at $variance", show = true)*/ {
tp match {
case tp: SkolemType => range(tp.bottomType, atVariance(1)(apply(tp.info)))
case _ => mapOver(tp)
}
}
}

/** Implementation of Types#simplified */
final def simplify(tp: Type, theMap: SimplifyMap): Type = tp match {
case tp: NamedType =>
Expand Down
13 changes: 12 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,18 @@ class Namer { typer: Typer =>

val rhsCtx = ctx.addMode(Mode.InferringReturnType)
def rhsType = typedAheadExpr(mdef.rhs, inherited orElse rhsProto)(rhsCtx).tpe
def cookedRhsType = ctx.deskolemize(dealiasIfUnit(widenRhs(rhsType)))

// Approximate a type `tp` with a type that does not contain skolem types.
val deskolemize = new ApproximatingTypeMap {
def apply(tp: Type) = /*ctx.traceIndented(i"deskolemize($tp) at $variance", show = true)*/ {
tp match {
case tp: SkolemType => range(tp.bottomType, atVariance(1)(apply(tp.info)))
case _ => mapOver(tp)
}
}
}

def cookedRhsType = deskolemize(dealiasIfUnit(widenRhs(rhsType)))
lazy val lhsType = fullyDefinedType(cookedRhsType, "right-hand side", mdef.pos)
//if (sym.name.toString == "y") println(i"rhs = $rhsType, cooked = $cookedRhsType")
if (inherited.exists)
Expand Down