Skip to content

Commit 78e80c8

Browse files
authored
Merge pull request #3087 from dotty-staging/change-termref
Generalize RefTypes
2 parents 0c673e7 + 2f9d66c commit 78e80c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+392
-447
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
431431
var found = desugared.get(i.tpe)
432432
if (found == null) {
433433
i.tpe match {
434-
case TermRef(prefix: TermRef, name) =>
434+
case TermRef(prefix: TermRef, _) =>
435435
found = tpd.ref(prefix).select(i.symbol)
436-
case TermRef(prefix: ThisType, name) =>
436+
case TermRef(prefix: ThisType, _) =>
437437
found = tpd.This(prefix.cls).select(i.symbol)
438-
case TermRef(NoPrefix, name) =>
438+
case TermRef(NoPrefix, _) =>
439439
if (i.symbol is Flags.Method) found = This(i.symbol.topLevelClass).select(i.symbol) // workaround #342 todo: remove after fixed
440440
case _ =>
441441
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ object desugar {
10571057
} else if (arity == 1) ts.head
10581058
else if (ctx.mode is Mode.Type) AppliedTypeTree(ref(tupleTypeRef), ts)
10591059
else if (arity == 0) unitLiteral
1060-
else Apply(ref(tupleTypeRef.classSymbol.companionModule.valRef), ts)
1060+
else Apply(ref(tupleTypeRef.classSymbol.companionModule.termRef), ts)
10611061
case WhileDo(cond, body) =>
10621062
// { <label> def while$(): Unit = if (cond) { body; while$() } ; while$() }
10631063
val call = Apply(Ident(nme.WHILE_PREFIX), Nil).withPos(tree.pos)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ object Trees {
8686
* where we overwrite with a simplified version of the type itself.
8787
*/
8888
private[dotc] def overwriteType(tpe: T) = {
89-
if (this.isInstanceOf[Template[_]]) assert(tpe.isInstanceOf[WithFixedSym], s"$this <--- $tpe")
89+
if (this.isInstanceOf[Template[_]])
90+
tpe match {
91+
case tpe: TermRef => assert(tpe.hasFixedSym , s"$this <--- $tpe")
92+
}
9093
myTpe = tpe
9194
}
9295

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import dotty.tools.dotc.transform.{ExplicitOuter, Erasure}
66
import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped
77
import transform.SymUtils._
88
import core._
9-
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._
9+
import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._
1010
import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._, Symbols._
1111
import Denotations._, Decorators._, DenotTransformers._
1212
import collection.mutable
@@ -243,7 +243,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
243243
val localDummy = ((NoSymbol: Symbol) /: body)(findLocalDummy.apply)
244244
.orElse(ctx.newLocalDummy(cls))
245245
val impl = untpd.Template(constr, parents, selfType, newTypeParams ++ body)
246-
.withType(localDummy.nonMemberTermRef)
246+
.withType(localDummy.termRef)
247247
ta.assignType(untpd.TypeDef(cls.name, impl), cls)
248248
}
249249

@@ -382,7 +382,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
382382
val targs = tp.argTypes
383383
val tycon = tp.typeConstructor
384384
New(tycon)
385-
.select(TermRef.withSig(tycon, constr))
385+
.select(TermRef.withSym(tycon, constr))
386386
.appliedToTypes(targs)
387387
.appliedToArgs(args)
388388
}
@@ -702,16 +702,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
702702
TypeRef(tree.tpe, sym.name.asTypeName)
703703
}
704704
else
705-
TermRef.withSigAndDenot(tree.tpe, sym.name.asTermName,
706-
sym.signature, sym.denot.asSeenFrom(tree.tpe))
707-
untpd.Select(tree, sym.name)
708-
.withType(tp)
705+
TermRef(tree.tpe, sym.name.asTermName, sym.denot.asSeenFrom(tree.tpe))
706+
untpd.Select(tree, sym.name).withType(tp)
709707
}
710708

711709
/** A select node with the given selector name and signature and a computed type */
712710
def selectWithSig(name: Name, sig: Signature)(implicit ctx: Context): Tree =
713711
untpd.SelectWithSig(tree, name, sig)
714-
.withType(TermRef.withSig(tree.tpe, name.asTermName, sig))
712+
.withType(TermRef(tree.tpe, name.asTermName.withSig(sig)))
715713

716714
/** A select node with selector name and signature taken from `sym`.
717715
* Note: Use this method instead of select(sym) if the referenced symbol
@@ -919,7 +917,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
919917
}
920918
else denot.asSingleDenotation.termRef
921919
val fun = receiver
922-
.select(TermRef.withSig(receiver.tpe, selected.termSymbol.asTerm))
920+
.select(TermRef.withSym(receiver.tpe, selected.termSymbol.asTerm))
923921
.appliedToTypes(targs)
924922

925923
def adaptLastArg(lastParam: Tree, expectedType: Type) = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ object Annotations {
140140

141141
def makeAlias(sym: TermSymbol)(implicit ctx: Context) =
142142
apply(defn.AliasAnnot, List(
143-
ref(TermRef.withSigAndDenot(sym.owner.thisType, sym.name, sym.signature, sym))))
143+
ref(TermRef(sym.owner.thisType, sym.name, sym))))
144144

145145
def makeChild(delayedSym: Context => Symbol)(implicit ctx: Context): Annotation = {
146146
def makeChildLater(implicit ctx: Context) = {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,9 @@ object Contexts {
614614
/** A table for hash consing unique named types */
615615
private[core] val uniqueNamedTypes = new NamedTypeUniques
616616

617-
/** A table for hash consing unique symbolic named types */
618-
private[core] val uniqueWithFixedSyms = new WithFixedSymUniques
619-
620617
private def uniqueSets = Map(
621618
"uniques" -> uniques,
622619
"uniqueAppliedTypes" -> uniqueAppliedTypes,
623-
"uniqueWithFixedSyms" -> uniqueWithFixedSyms,
624620
"uniqueNamedTypes" -> uniqueNamedTypes)
625621

626622
/** A map that associates label and size of all uniques sets */

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import Decorators.SymbolIteratorDecorator
3333
*
3434
* Lines ending in a horizontal line mean subtying (right is a subtype of left).
3535
*
36-
* NamedType------TermRefWithSignature
37-
* | | Symbol---------ClassSymbol
38-
* | | | |
39-
* | denot | denot | denot | denot
40-
* v v v v
36+
* NamedType
37+
* | Symbol---------ClassSymbol
38+
* | | |
39+
* | denot | denot | denot
40+
* v v v
4141
* Denotation-+-----SingleDenotation-+------SymDenotation-+----ClassDenotation
4242
* | |
4343
* +-----MultiDenotation |
@@ -51,8 +51,6 @@ import Decorators.SymbolIteratorDecorator
5151
* prefix: Type
5252
* name: Name
5353
* It has two subtypes: TermRef and TypeRef
54-
* TermRefWithSignature A TermRef that has in addition a signature to select an overloaded variant, with new field
55-
* sig: Signature
5654
* Symbol A label for a definition or declaration in one compiler run
5755
* ClassSymbol A symbol representing a class
5856
* Denotation The meaning of a named type or symbol during a period
@@ -655,25 +653,11 @@ object Denotations {
655653
def termRef(implicit ctx: Context): TermRef =
656654
TermRef(symbol.owner.thisType, symbol.name.asTermName, this)
657655

658-
/** The TermRef representing this term denotation at its original location
659-
* and at signature `NotAMethod`.
660-
*/
661-
def valRef(implicit ctx: Context): TermRef =
662-
TermRef.withSigAndDenot(symbol.owner.thisType, symbol.name.asTermName, Signature.NotAMethod, this)
663-
664-
/** The TermRef representing this term denotation at its original location
665-
* at the denotation's signature.
666-
* @note Unlike `valRef` and `termRef`, this will force the completion of the
667-
* denotation via a call to `info`.
668-
*/
669-
def termRefWithSig(implicit ctx: Context): TermRef =
670-
TermRef.withSigAndDenot(symbol.owner.thisType, symbol.name.asTermName, signature, this)
671-
672656
/** The NamedType representing this denotation at its original location.
673-
* Same as either `typeRef` or `termRefWithSig` depending whether this denotes a type or not.
657+
* Same as either `typeRef` or `termRef` depending whether this denotes a type or not.
674658
*/
675659
def namedType(implicit ctx: Context): NamedType =
676-
if (isType) typeRef else termRefWithSig
660+
if (isType) typeRef else termRef
677661

678662
// ------ Transformations -----------------------------------------
679663

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package dotty.tools
2+
package dotc
3+
package core
4+
5+
import Names._
6+
import Contexts.Context
7+
8+
/** Defines a common superclass of Name and Symbol and its Term/Type variants
9+
* Designators are used in reference type to identity what is referred to.
10+
*/
11+
object Designators {
12+
13+
abstract class Designator extends util.DotClass {
14+
15+
type ThisName <: Name
16+
17+
/** Classifiers and casts, to be overridden in implemetations */
18+
def isName: Boolean = false
19+
def isSymbol: Boolean = false
20+
21+
def isTerm(implicit ctx: Context) = false
22+
def isType(implicit ctx: Context) = false
23+
24+
def asTerm(implicit ctx: Context): TermDesignator = unsupported("asTerm")
25+
def asType(implicit ctx: Context): TypeDesignator = unsupported("asType")
26+
}
27+
28+
type TermDesignator = Designator { type ThisName = TermName }
29+
type TypeDesignator = Designator { type ThisName = TypeName }
30+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ object Flags {
359359

360360
// Flags following this one are not pickled
361361

362-
/** Symbol always defines a fresh named type */
363-
final val Fresh = commonFlag(45, "<fresh>")
362+
/** Symbol is not a member of its owner */
363+
final val NonMember = commonFlag(45, "<non-member>")
364364

365365
/** Denotation is in train of being loaded and completed, used to catch cyclic dependencies */
366366
final val Touched = commonFlag(48, "<touched>")
@@ -446,7 +446,7 @@ object Flags {
446446
Module | Package | Deferred | MethodOrHKCommon | Param | ParamAccessor.toCommonFlags |
447447
Scala2ExistentialCommon | Mutable.toCommonFlags | Touched | JavaStatic |
448448
CovariantOrOuter | ContravariantOrLabel | CaseAccessor.toCommonFlags |
449-
Fresh | Erroneous | ImplicitCommon | Permanent | Synthetic |
449+
NonMember | Erroneous | ImplicitCommon | Permanent | Synthetic |
450450
SuperAccessorOrScala2x | Inline
451451

452452
/** Flags guaranteed to be set upon symbol creation, or, if symbol is a top-level

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,5 +305,7 @@ object NameOps {
305305
case raw.BANG => UNARY_!
306306
case _ => name
307307
}
308+
309+
def withSig(sig: Signature) = SignedName(name.exclude(SignedName), sig)
308310
}
309311
}

0 commit comments

Comments
 (0)