Skip to content

Fix #7374: Introduce This Types #7376

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

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {

case ApplyDynamic(qual, args) => sys.error("No invokedynamic support yet.")

case This(qual) =>
case ThisRef(qual) =>
val symIsModuleClass = tree.symbol.isModuleClass
assert(tree.symbol == claszSymbol || symIsModuleClass,
s"Trying to access the this of another class: tree.symbol = ${tree.symbol}, class symbol = $claszSymbol compilation unit: $cunit")
Expand Down Expand Up @@ -409,7 +409,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
genLoad(expr, expectedType)
else genBlock(blck, expectedType)

case Typed(Super(_, _), _) => genLoad(This(claszSymbol), expectedType)
case Typed(Super(_, _), _) => genLoad(ThisRef(claszSymbol), expectedType)

case Typed(expr, _) => genLoad(expr, expectedType)

Expand Down Expand Up @@ -1027,7 +1027,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
assert(args.length == params.length, s"Wrong number of arguments in call to label at: $gotoPos")

def isTrivial(kv: (Tree, Symbol)) = kv match {
case (This(_), p) if p.name == nme_THIS => true
case (ThisRef(_), p) if p.name == nme_THIS => true
case (arg @ Ident(_), p) if arg.symbol == p => true
case _ => false
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/BackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
type Typed >: Null <: Tree
type ArrayValue >: Null <: Tree
type Match >: Null <: Tree
type This >: Null <: Tree
type ThisRef >: Null <: Tree
type CaseDef >: Null <: Tree
type Alternative >: Null <: Tree
type DefDef >: Null <: Tree
Expand Down Expand Up @@ -78,7 +78,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
implicit val ArrayValueTag: ClassTag[ArrayValue]
implicit val MatchTag: ClassTag[Match]
implicit val CaseDefTag: ClassTag[CaseDef]
implicit val ThisTag: ClassTag[This]
implicit val ThisTag: ClassTag[ThisRef]
implicit val AlternativeTag: ClassTag[Alternative]
implicit val DefDefTag: ClassTag[DefDef]
implicit val ModuleDefTag: ClassTag[ModuleDef]
Expand Down Expand Up @@ -201,7 +201,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
val Throw: ThrowDeconstructor
val New: NewDeconstructor
val ApplyDynamic: ApplyDynamicDeconstructor
val This: ThisDeconstructor
val ThisRef: ThisDeconstructor
val Ident: IdentDeconstructor
val Try: TryDeconstructor
val Labeled: LabeledDeconstructor
Expand Down Expand Up @@ -287,7 +287,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
def _3: Symbol // functionalInterface
}

abstract class ThisDeconstructor extends Deconstructor1Common[This, Name]{
abstract class ThisDeconstructor extends Deconstructor1Common[ThisRef, Name]{
def apply(s: Symbol): Tree
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
type Block = tpd.Block
type Typed = tpd.Typed
type Match = tpd.Match
type This = tpd.This
type ThisRef = tpd.ThisRef
type CaseDef = tpd.CaseDef
type Alternative = tpd.Alternative
type DefDef = tpd.DefDef
Expand Down Expand Up @@ -198,7 +198,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
implicit val ArrayValueTag: ClassTag[ArrayValue] = ClassTag[ArrayValue](classOf[ArrayValue])
implicit val MatchTag: ClassTag[Match] = ClassTag[Match](classOf[Match])
implicit val CaseDefTag: ClassTag[CaseDef] = ClassTag[CaseDef](classOf[CaseDef])
implicit val ThisTag: ClassTag[This] = ClassTag[This](classOf[This])
implicit val ThisTag: ClassTag[ThisRef] = ClassTag[ThisRef](classOf[ThisRef])
implicit val AlternativeTag: ClassTag[Alternative] = ClassTag[Alternative](classOf[Alternative])
implicit val DefDefTag: ClassTag[DefDef] = ClassTag[DefDef](classOf[DefDef])
implicit val ModuleDefTag: ClassTag[ModuleDef] = ClassTag[ModuleDef](classOf[ModuleDef])
Expand Down Expand Up @@ -1053,9 +1053,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def get: Type = field.tpt.tpe
}

object This extends ThisDeconstructor {
object ThisRef extends ThisDeconstructor {
def get: Name = field.qual.name
def apply(s: Symbol): This = tpd.This(s.asClass)
def apply(s: Symbol): ThisRef = tpd.ThisRef(s.asClass)
}

object Labeled extends LabeledDeconstructor {
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class JSCodeGen()(implicit ctx: Context) {
implicit def pos: SourcePosition = tree.sourcePos

tree match {
case _: This =>
case _: ThisRef =>
val sym = tree.symbol
if (sym != currentClassSym.get && sym.is(Module))
genLoadModuleOrGlobalScope(sym)
Expand Down Expand Up @@ -882,7 +882,7 @@ class JSCodeGen()(implicit ctx: Context) {
/*case app: ApplyDynamic =>
genApplyDynamic(app)*/

case tree: This =>
case tree: ThisRef =>
val currentClass = currentClassSym.get
val symIsModuleClass = tree.symbol.is(ModuleClass)
assert(tree.symbol == currentClass || symIsModuleClass,
Expand Down Expand Up @@ -988,7 +988,7 @@ class JSCodeGen()(implicit ctx: Context) {
def ctorAssignment = (
currentMethodSym.get.name == nme.CONSTRUCTOR &&
currentMethodSym.get.owner == qualifier.symbol &&
qualifier.isInstanceOf[This]
qualifier.isInstanceOf[ThisRef]
)
// TODO This fails for OFFSET$x fields. Re-enable when we can.
/*if (!sym.is(Mutable) && !ctorAssignment)
Expand Down Expand Up @@ -1042,7 +1042,7 @@ class JSCodeGen()(implicit ctx: Context) {
case fun: Ident =>
fun.tpe match {
case TermRef(prefix: TermRef, _) => tpd.ref(prefix)
case TermRef(prefix: ThisType, _) => tpd.This(prefix.cls)
case TermRef(prefix: ThisType, _) => tpd.ThisRef(prefix.cls)
}
case Select(qualifier, _) =>
qualifier
Expand Down Expand Up @@ -2141,7 +2141,7 @@ class JSCodeGen()(implicit ctx: Context) {
implicit val pos = value.span
val formalIdent = value match {
case Ident(name) => freshLocalIdent(name.toString)
case This(_) => freshLocalIdent("this")
case ThisRef(_) => freshLocalIdent("this")
case _ => freshLocalIdent()
}
val formalCapture =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class JUnitBootstrappers extends MiniPhase {
val sym = ctx.newDefaultConstructor(owner).entered
DefDef(sym, {
Block(
Super(This(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil,
Super(ThisRef(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil,
unitLiteral
)
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ object desugar {
val caseParams = derivedVparamss.head.toArray
for (i <- List.range(0, arity) if nme.selectorName(i) `ne` caseParams(i).name)
yield syntheticProperty(nme.selectorName(i), caseParams(i).tpt,
Select(This(EmptyTypeIdent), caseParams(i).name))
Select(ThisRef(EmptyTypeIdent), caseParams(i).name))
}
def ordinalMeths = if (isEnumCase) ordinalMethLit(nextOrdinal(CaseKind.Class)._1) :: Nil else Nil
def copyMeths = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object DesugarEnums {

private def registerCall(implicit ctx: Context): List[Tree] =
if (enumClass.typeParams.nonEmpty) Nil
else Apply(valuesDot("register"), This(EmptyTypeIdent) :: Nil) :: Nil
else Apply(valuesDot("register"), ThisRef(EmptyTypeIdent) :: Nil) :: Nil

/** The following lists of definitions for an enum type E:
*
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>

/** Is tree a path? */
def isPath(tree: Tree): Boolean = unsplice(tree) match {
case Ident(_) | This(_) | Super(_, _) => true
case Ident(_) | ThisRef(_) | Super(_, _) => true
case Select(qual, _) => isPath(qual)
case _ => false
}
Expand All @@ -118,7 +118,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
* same object?
*/
def isSelfConstrCall(tree: Tree): Boolean = methPart(tree) match {
case Ident(nme.CONSTRUCTOR) | Select(This(_), nme.CONSTRUCTOR) => true
case Ident(nme.CONSTRUCTOR) | Select(ThisRef(_), nme.CONSTRUCTOR) => true
case _ => false
}

Expand All @@ -136,7 +136,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>

def isSelfOrSuperConstrCall(tree: Tree): Boolean = methPart(tree) match {
case Ident(nme.CONSTRUCTOR)
| Select(This(_), nme.CONSTRUCTOR)
| Select(ThisRef(_), nme.CONSTRUCTOR)
| Select(Super(_, _), nme.CONSTRUCTOR) => true
case _ => false
}
Expand Down Expand Up @@ -381,7 +381,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
*/
def exprPurity(tree: Tree)(implicit ctx: Context): PurityLevel = unsplice(tree) match {
case EmptyTree
| This(_)
| ThisRef(_)
| Super(_, _)
| Literal(_) =>
PurePath
Expand Down Expand Up @@ -557,7 +557,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>

/** Is tree a `this` node which belongs to `enclClass`? */
def isSelf(tree: Tree, enclClass: Symbol)(implicit ctx: Context): Boolean = unsplice(tree) match {
case This(_) => tree.symbol == enclClass
case ThisRef(_) => tree.symbol == enclClass
case _ => false
}

Expand Down Expand Up @@ -770,7 +770,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
def qualifier(tree: Tree)(implicit ctx: Context): Tree = tree match {
case Select(qual, _) => qual
case tree: Ident => desugarIdentPrefix(tree)
case _ => This(ctx.owner.enclosingClass.asClass)
case _ => ThisRef(ctx.owner.enclosingClass.asClass)
}

/** Is this a (potentially applied) selection of a member of a structural type
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ object Trees {
}

/** qual.this */
case class This[-T >: Untyped] private[ast] (qual: untpd.Ident)(implicit @constructorOnly src: SourceFile)
case class ThisRef[-T >: Untyped] private[ast] (qual: untpd.Ident)(implicit @constructorOnly src: SourceFile)
extends DenotingTree[T] with TermTree[T] {
type ThisTree[-T >: Untyped] = This[T]
// Denotation of a This tree is always the underlying class; needs correction for modules.
type ThisTree[-T >: Untyped] = ThisRef[T]
// Denotation of a ThisRef tree is always the underlying class; needs correction for modules.
override def denot(implicit ctx: Context): Denotation =
typeOpt match {
case tpe @ TermRef(pre, _) if tpe.symbol.is(Module) =>
Expand Down Expand Up @@ -949,7 +949,7 @@ object Trees {
type SearchFailureIdent = Trees.SearchFailureIdent[T]
type Select = Trees.Select[T]
type SelectWithSig = Trees.SelectWithSig[T]
type This = Trees.This[T]
type ThisRef = Trees.ThisRef[T]
type Super = Trees.Super[T]
type Apply = Trees.Apply[T]
type TypeApply = Trees.TypeApply[T]
Expand Down Expand Up @@ -1046,9 +1046,9 @@ object Trees {
case Ident(_) => Ident(tree)(name)
case Select(qual, _) => Select(tree)(qual, name)
}
def This(tree: Tree)(qual: untpd.Ident)(implicit ctx: Context): This = tree match {
case tree: This if (qual eq tree.qual) => tree
case _ => finalize(tree, untpd.This(qual)(sourceFile(tree)))
def ThisRef(tree: Tree)(qual: untpd.Ident)(implicit ctx: Context): ThisRef = tree match {
case tree: ThisRef if (qual eq tree.qual) => tree
case _ => finalize(tree, untpd.ThisRef(qual)(sourceFile(tree)))
}
def Super(tree: Tree)(qual: Tree, mix: untpd.Ident)(implicit ctx: Context): Super = tree match {
case tree: Super if (qual eq tree.qual) && (mix eq tree.mix) => tree
Expand Down Expand Up @@ -1254,7 +1254,7 @@ object Trees {
tree
case Select(qualifier, name) =>
cpy.Select(tree)(transform(qualifier), name)
case This(qual) =>
case ThisRef(qual) =>
tree
case Super(qual, mix) =>
cpy.Super(tree)(transform(qual), mix)
Expand Down Expand Up @@ -1378,7 +1378,7 @@ object Trees {
x
case Select(qualifier, name) =>
this(x, qualifier)
case This(qual) =>
case ThisRef(qual) =>
x
case Super(qual, mix) =>
this(x, qual)
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def Select(qualifier: Tree, tp: NamedType)(implicit ctx: Context): Select =
untpd.Select(qualifier, tp.name).withType(tp)

def This(cls: ClassSymbol)(implicit ctx: Context): This =
untpd.This(untpd.Ident(cls.name)).withType(cls.thisType)
def ThisRef(cls: ClassSymbol)(implicit ctx: Context): ThisRef =
untpd.ThisRef(untpd.Ident(cls.name)).withType(cls.thisType)

def Super(qual: Tree, mix: untpd.Ident, inConstrCall: Boolean, mixinClass: Symbol)(implicit ctx: Context): Super =
ta.assignType(untpd.Super(qual, mix), qual, inConstrCall, mixinClass)
Expand Down Expand Up @@ -376,7 +376,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
if (tp.isType) TypeTree(tp)
else if (prefixIsElidable(tp)) Ident(tp)
else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass))
followOuterLinks(This(tp.symbol.moduleClass.asClass))
followOuterLinks(ThisRef(tp.symbol.moduleClass.asClass))
else if (tp.symbol hasAnnotation defn.ScalaStaticAnnot)
Ident(tp)
else {
Expand All @@ -389,7 +389,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))

private def followOuterLinks(t: Tree)(implicit ctx: Context) = t match {
case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
case t: ThisRef if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) =>
// after erasure outer paths should be respected
ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.widen.classSymbol)
case t =>
Expand All @@ -398,7 +398,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {

def singleton(tp: Type)(implicit ctx: Context): Tree = tp match {
case tp: TermRef => ref(tp)
case tp: ThisType => This(tp.cls)
case tp: ThisType => ThisRef(tp.cls)
case tp: SkolemType => singleton(tp.narrow)
case SuperType(qual, _) => singleton(qual)
case ConstantType(value) => Literal(value)
Expand Down Expand Up @@ -1260,7 +1260,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
case TermRef(prefix: TermRef, _) =>
ref(prefix)
case TermRef(prefix: ThisType, _) =>
This(prefix.cls)
ThisRef(prefix.cls)
case _ =>
EmptyTree
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def SearchFailureIdent(name: Name)(implicit src: SourceFile): SearchFailureIdent = new SearchFailureIdent(name)
def Select(qualifier: Tree, name: Name)(implicit src: SourceFile): Select = new Select(qualifier, name)
def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit src: SourceFile): Select = new SelectWithSig(qualifier, name, sig)
def This(qual: Ident)(implicit src: SourceFile): This = new This(qual)
def ThisRef(qual: Ident)(implicit src: SourceFile): ThisRef = new ThisRef(qual)
def Super(qual: Tree, mix: Ident)(implicit src: SourceFile): Super = new Super(qual, mix)
def Apply(fun: Tree, args: List[Tree])(implicit src: SourceFile): Apply = new Apply(fun, args)
def TypeApply(fun: Tree, args: List[Tree])(implicit src: SourceFile): TypeApply = new TypeApply(fun, args)
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Constraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import printing.Showable
*/
abstract class Constraint extends Showable {

type This <: Constraint
type ThisConstraint <: Constraint

/** Does the constraint's domain contain the type parameters of `tl`? */
def contains(tl: TypeLambda): Boolean
Expand Down Expand Up @@ -77,7 +77,7 @@ abstract class Constraint extends Showable {
* satisfiability but will solved to give instances of
* type variables.
*/
def add(poly: TypeLambda, tvars: List[TypeVar])(implicit ctx: Context): This
def add(poly: TypeLambda, tvars: List[TypeVar])(implicit ctx: Context): ThisConstraint

/** A new constraint which is derived from this constraint by updating
* the entry for parameter `param` to `tp`.
Expand All @@ -88,26 +88,26 @@ abstract class Constraint extends Showable {
*
* @pre `this contains param`.
*/
def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): This
def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): ThisConstraint

/** A constraint that includes the relationship `p1 <: p2`.
* `<:` relationships between parameters ("edges") are propagated, but
* non-parameter bounds are left alone.
*/
def addLess(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This
def addLess(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): ThisConstraint

/** A constraint resulting from adding p2 = p1 to this constraint, and at the same
* time transferring all bounds of p2 to p1
*/
def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This
def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): ThisConstraint

/** A new constraint which is derived from this constraint by removing
* the type parameter `param` from the domain and replacing all top-level occurrences
* of the parameter elsewhere in the constraint by type `tp`, or a conservative
* approximation of it if that is needed to avoid cycles.
* Occurrences nested inside a refinement or prefix are not affected.
*/
def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): This
def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): ThisConstraint

/** Is entry associated with `tl` removable? This is the case if
* all type parameters of the entry are associated with type variables
Expand All @@ -116,10 +116,10 @@ abstract class Constraint extends Showable {
def isRemovable(tl: TypeLambda): Boolean

/** A new constraint with all entries coming from `tl` removed. */
def remove(tl: TypeLambda)(implicit ctx: Context): This
def remove(tl: TypeLambda)(implicit ctx: Context): ThisConstraint

/** A new constraint with entry `tl` renamed to a fresh type lambda */
def rename(tl: TypeLambda)(implicit ctx: Context): This
def rename(tl: TypeLambda)(implicit ctx: Context): ThisConstraint

/** The given `tl` in case it is not contained in this constraint,
* a fresh copy of `tl` otherwise.
Expand Down
Loading