Skip to content

Commit 948747e

Browse files
committed
Removed CheckTrees
It was unmaintained and superseded by TreeChecker. The only needed bit, escapingRefs, got moved to Typer.
1 parent 78a29a4 commit 948747e

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import core._
66
import dotty.tools.dotc.transform.TypeUtils
77
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
88
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._
9-
import CheckTrees._, Denotations._, Decorators._
9+
import Denotations._, Decorators._
1010
import config.Printers._
1111
import typer.ErrorReporting._
1212

@@ -134,7 +134,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
134134
TypeTree(original.tpe, original)
135135

136136
def TypeTree(tp: Type, original: Tree = EmptyTree)(implicit ctx: Context): TypeTree =
137-
untpd.TypeTree(original).withType(tp).checked
137+
untpd.TypeTree(original).withType(tp)
138138

139139
def SingletonTypeTree(ref: Tree)(implicit ctx: Context): SingletonTypeTree =
140140
ta.assignType(untpd.SingletonTypeTree(ref), ref)
@@ -237,7 +237,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
237237
val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy)
238238
.orElse(ctx.newLocalDummy(cls))
239239
val impl = untpd.Template(constr, parents, selfType, newTypeParams ++ body)
240-
.withType(localDummy.termRef).checked
240+
.withType(localDummy.termRef)
241241
ta.assignType(untpd.TypeDef(Modifiers(cls), cls.name, impl), cls)
242242
}
243243

@@ -354,11 +354,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
354354
case _ => false
355355
}
356356

357-
def checked(implicit ctx: Context): ThisTree = {
358-
if (ctx.settings.YcheckTypedTrees.value) checkType(tree)
359-
tree
360-
}
361-
362357
def shallowFold[T](z: T)(op: (T, tpd.Tree) => T) =
363358
new ShallowFolder(op).apply(z, tree)
364359

src/dotty/tools/dotc/typer/CheckVariances.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ class VarianceChecker(implicit ctx: Context) {
114114
ctx.debuglog(s"Skipping variance check of ${sym.showDcl}")
115115
case tree: TypeDef =>
116116
checkVariance(sym)
117-
super.traverse(tree)
117+
foldOver((), tree)
118118
case tree: ValDef =>
119119
checkVariance(sym)
120120
case DefDef(_, _, tparams, vparamss, _, _) =>
121121
checkVariance(sym)
122122
tparams foreach traverse
123123
vparamss foreach (_ foreach traverse)
124124
case Template(_, _, _, body) =>
125-
super.traverse(tree)
125+
foldOver((), tree)
126126
case _ =>
127127
}
128128
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,28 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
397397
ensureNoLocalRefs(assignType(cpy.Block(tree, stats1, expr1), stats1, expr1), pt)
398398
}
399399

400+
def escapingRefs(block: Block)(implicit ctx: Context): collection.Set[NamedType] = {
401+
var hoisted: Set[Symbol] = Set()
402+
lazy val locals = ctx.typeAssigner.localSyms(block.stats).toSet
403+
def isLocal(sym: Symbol): Boolean =
404+
(locals contains sym) && !isHoistableClass(sym)
405+
def isHoistableClass(sym: Symbol) =
406+
sym.isClass && {
407+
(hoisted contains sym) || {
408+
hoisted += sym
409+
!classLeaks(sym.asClass)
410+
}
411+
}
412+
def leakingTypes(tp: Type): collection.Set[NamedType] =
413+
tp namedPartsWith (tp => isLocal(tp.symbol))
414+
def typeLeaks(tp: Type): Boolean = leakingTypes(tp).nonEmpty
415+
def classLeaks(sym: ClassSymbol): Boolean =
416+
(ctx.owner is Method) || // can't hoist classes out of method bodies
417+
(sym.info.parents exists typeLeaks) ||
418+
(sym.decls.toList exists (t => typeLeaks(t.info)))
419+
leakingTypes(block.tpe)
420+
}
421+
400422
/** Check that block's type can be expressed without references to locally defined
401423
* symbols. The following two remedies are tried before giving up:
402424
* 1. If the expected type of the block is fully defined, pick it as the
@@ -406,7 +428,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
406428
*/
407429
protected def ensureNoLocalRefs(block: Block, pt: Type, forcedDefined: Boolean = false)(implicit ctx: Context): Tree = {
408430
val Block(stats, expr) = block
409-
val leaks = CheckTrees.escapingRefs(block)
431+
val leaks = escapingRefs(block)
410432
if (leaks.isEmpty) block
411433
else if (isFullyDefined(pt, ForceDegree.all)) {
412434
val expr1 = Typed(expr, TypeTree(pt))

0 commit comments

Comments
 (0)