Skip to content

Use symbolic names internally #2169

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 8 commits into from
May 7, 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
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ object NameKinds {
def infoString: String
}

/** The kind of SimpleNames */
object SimpleNameKind extends NameKind(UTF8) { self =>
type ThisInfo = Info
val info = new Info
Expand Down Expand Up @@ -311,7 +310,7 @@ object NameKinds {
val PatMatSelectorName = new UniqueNameKind("selector")

/** The kind of names of default argument getters */
object DefaultGetterName extends NumberedNameKind(DEFAULTGETTER, "DefaultGetter") {
val DefaultGetterName = new NumberedNameKind(DEFAULTGETTER, "DefaultGetter") {
def mkString(underlying: TermName, info: ThisInfo) = {
val prefix = if (underlying.isConstructorName) nme.DEFAULT_GETTER_INIT else underlying
prefix.toString + str.DEFAULT_GETTER + (info.num + 1)
Expand All @@ -330,14 +329,14 @@ object NameKinds {
}

/** The kind of names that also encode a variance: 0 for contravariance, 1 for covariance. */
object VariantName extends NumberedNameKind(VARIANT, "Variant") {
val VariantName = new NumberedNameKind(VARIANT, "Variant") {
def mkString(underlying: TermName, info: ThisInfo) = "-+"(info.num).toString + underlying
}

/** Names of the form N_<outer>. Emitted by inliner, replaced by outer path
* in ExplicitOuter.
*/
object OuterSelectName extends NumberedNameKind(OUTERSELECT, "OuterSelect") {
val OuterSelectName = new NumberedNameKind(OUTERSELECT, "OuterSelect") {
def mkString(underlying: TermName, info: ThisInfo) = {
assert(underlying.isEmpty)
info.num + "_<outer>"
Expand All @@ -351,7 +350,9 @@ object NameKinds {
val ProtectedSetterName = new PrefixNameKind(PROTECTEDSETTER, "protected$set") // dubious encoding, kept for Scala2 compatibility
val AvoidClashName = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
val DirectMethodName = new SuffixNameKind(DIRECT, "$direct") { override def definesNewName = true }
val FieldName = new SuffixNameKind(FIELD, "$$local")
val FieldName = new SuffixNameKind(FIELD, "$$local") {
override def mkString(underlying: TermName, info: ThisInfo) = underlying.toString
}
val ExtMethName = new SuffixNameKind(EXTMETH, "$extension")
val ModuleVarName = new SuffixNameKind(OBJECTVAR, "$module")
val ModuleClassName = new SuffixNameKind(OBJECTCLASS, "$", optInfoString = "ModuleClass")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ object Names {
}

@sharable // because it's just a cache for performance
private[Names] var myMangledString: String = null
private[this] var myMangledString: String = null

@sharable // because it's just a cache for performance
private[this] var myMangled: Name = null
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ object Types {
case tycon: TypeRef if !tycon.symbol.isClass =>
case _: TypeParamRef | _: ErrorType | _: WildcardType =>
case _: TypeLambda =>
assert(args.exists(_.isInstanceOf[TypeBounds]), s"unreduced type apply: $this")
assert(!args.exists(_.isInstanceOf[TypeBounds]), s"unreduced type apply: $this")
case tycon: AnnotatedType =>
check(tycon.underlying)
case _ =>
Expand Down
30 changes: 15 additions & 15 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ Macro-format:
EXPANDEDPREFIX Length qualified_NameRef selector_NameRef
TRAITSETTER Length qualified_NameRef selector_NameRef
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
DEFAULTGETTER Length underlying_NameRef index_Nat
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
OUTERSELECT Length underlying_NameRef nhops_Nat // a reference to `nhops` <outer> selections, followed by `underlying`

SUPERACCESSOR Length underlying_NameRef
PROTECTEDACCESSOR Length underlying_NameRef
PROTECTEDSETTER Length underlying_NameRef
INITIALIZER Length underlying_NameRef
SHADOWED Length underlying_NameRef
AVOIDCLASH Length underlying_NameRef
DIRECT Length underlying_NameRef
FIELD Length underlying_NameRef
EXTMETH Length underlying_NameRef
OBJECTVAR Length underlying_NameRef
OBJECTCLASS Length underlying_NameRef
DEFAULTGETTER Length underlying_NameRef index_Nat
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
OUTERSELECT Length underlying_NameRef nhops_Nat // a reference to `nhops` <outer> selections, followed by `underlying`

SUPERACCESSOR Length underlying_NameRef
PROTECTEDACCESSOR Length underlying_NameRef
PROTECTEDSETTER Length underlying_NameRef
INITIALIZER Length underlying_NameRef
SHADOWED Length underlying_NameRef
AVOIDCLASH Length underlying_NameRef
DIRECT Length underlying_NameRef
FIELD Length underlying_NameRef
EXTMETH Length underlying_NameRef
OBJECTVAR Length underlying_NameRef
OBJECTCLASS Length underlying_NameRef
SIGNED Length original_NameRef resultSig_NameRef paramSig_NameRef*

NameRef = Nat // ordinal number of name in name table, starting from 1.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ trait TypeAssigner {
val refinableDecls = info.decls.filter(
sym => !(sym.is(TypeParamAccessor | Private) || sym.isConstructor))
val fullType = (parentType /: refinableDecls)(addRefinement)
mapOver(fullType)
apply(fullType)
case TypeBounds(lo, hi) if variance > 0 =>
apply(hi)
case _ =>
Expand Down
3 changes: 2 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ class CompilationTests extends ParallelTesting {
}.map(_.checkCompile()).foreach(_.delete())
}

@Test def bytecodeIdempotency: Unit = {
/** Add a `z` so that they run last. TODO: Only run them selectively? */
@Test def zBytecodeIdempotency: Unit = {
var failed = 0
var total = 0
val blacklisted = Set(
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/avoid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,20 @@ object test {
}
val z: String = x.y
}

// A tricky case involving inner classes, exercised
// in the large in dotty.tools.dotc.core.NameKinds.scala.
object Test2 {

class NK {
class I
type T
}

val x = new NK { type T = I }

val y = {
class C extends NK { type T = I }
new C
}
}
12 changes: 6 additions & 6 deletions tests/run/paramForwarding.check
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
B:
private final int B.theValue$$local
private final int B.theValueInB$$local
private final int B.theValue
private final int B.theValueInB
Bz:
private final int Bz.theValue$$local
private final int Bz.theValueInBz$$local
private final int Bz.theValue
private final int Bz.theValueInBz
C:

D:
private final int D.other$$local
private final int D.other
NonVal:

X:
private final int X.theValue$$local
private final int X.theValue
Y:

2 changes: 1 addition & 1 deletion tests/run/paramForwarding_separate.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fields in A:
private final int A.member$$local
private final int A.member
# Fields in SubA:

# Fields in B:
Expand Down
2 changes: 1 addition & 1 deletion tests/run/paramForwarding_together.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fields in A:
private final int A.member$$local
private final int A.member
# Fields in SubA:

# Fields in B:
Expand Down
2 changes: 1 addition & 1 deletion tests/run/paramForwarding_together_b.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Fields in A:
private final int A.member$$local
private final int A.member
# Fields in SubA:

# Fields in B:
Expand Down
8 changes: 4 additions & 4 deletions tests/run/statics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import scala.annotation.static

class Foo{
class Bar {
def qwa =
def qwa =
Bar.field
// 0: invokestatic #31 // Method Foo$Bar$.field:()I
// 3: ireturn
}
object Bar {
@static
@static
val field = 1
}
}

object Foo{
object Foo{
@static
def method = 1

Expand All @@ -35,6 +35,6 @@ object Test {
}

class WithLazies{
@volatile lazy val s = 1
@volatile lazy val s = 1
// 98: getstatic #30 // Field WithLazies$.OFFSET$0:J
}
4 changes: 2 additions & 2 deletions tests/run/variable-pattern-access.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fields of A:
private final int A.a$$local
private final int A.b$$local
private final int A.a
private final int A.b
private final scala.Tuple2 A.$1$
# Methods of A:
public int A.a()
Expand Down