Skip to content

Commit 95f8a84

Browse files
committed
Get rid of bindingTree and ownerSym in TypeVars
1 parent a6e1d19 commit 95f8a84

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ object Trees {
573573
s"TypeTree${if (hasType) s"[$typeOpt]" else ""}"
574574
}
575575

576+
/** A type tree that defines a new type variable. Its type is always a TypeVar.
577+
* Every TypeVar is created as the type of one TypeVarBinder.
578+
*/
579+
class TypeVarBinder[-T >: Untyped] extends TypeTree
580+
576581
/** ref.type */
577582
case class SingletonTypeTree[-T >: Untyped] private[ast] (ref: Tree[T])
578583
extends DenotingTree[T] with TypTree[T] {

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,14 +3354,11 @@ object Types {
33543354
*
33553355
* @param origin The parameter that's tracked by the type variable.
33563356
* @param creatorState The typer state in which the variable was created.
3357-
* @param bindingTree The TypeTree which introduces the type variable, or EmptyTree
3358-
* if the type variable does not correspond to a source term.
3359-
* @paran owner The current owner if the context where the variable was created.
33603357
*
33613358
* `owningTree` and `owner` are used to determine whether a type-variable can be instantiated
33623359
* at some given point. See `Inferencing#interpolateUndetVars`.
33633360
*/
3364-
final class TypeVar(val origin: TypeParamRef, creatorState: TyperState, var bindingTree: untpd.Tree, val owner: Symbol) extends CachedProxyType with ValueType {
3361+
final class TypeVar(val origin: TypeParamRef, creatorState: TyperState) extends CachedProxyType with ValueType {
33653362

33663363
/** The permanent instance type of the variable, or NoType is none is given yet */
33673364
private[this] var myInst: Type = NoType

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ object Inferencing {
166166
@tailrec def boundVars(tree: Tree, acc: List[TypeVar]): List[TypeVar] = tree match {
167167
case Apply(fn, _) => boundVars(fn, acc)
168168
case TypeApply(fn, targs) =>
169-
val tvars = targs.tpes.collect {
169+
val tvars = targs.filter(_.isInstanceOf[TypeVarBinder[_]]).tpes.collect {
170170
case tvar: TypeVar
171171
if !tvar.isInstantiated &&
172-
targs.contains(tvar.bindingTree) &&
173172
ctx.typerState.ownedVars.contains(tvar) &&
174173
!locked.contains(tvar) => tvar
175174
}

compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ object ProtoTypes {
394394
def newTypeVars(tl: TypeLambda): List[TypeTree] =
395395
for (n <- (0 until tl.paramNames.length).toList)
396396
yield {
397-
val tt = new TypeTree().withPos(owningTree.pos)
398-
val tvar = new TypeVar(tl.paramRefs(n), state, tt, ctx.owner)
397+
val tt = new TypeVarBinder().withPos(owningTree.pos)
398+
val tvar = new TypeVar(tl.paramRefs(n), state)
399399
state.ownedVars += tvar
400400
tt.withType(tvar)
401401
}

0 commit comments

Comments
 (0)