Skip to content

Commit 1014af3

Browse files
authored
Merge pull request #2169 from dotty-staging/change-late-op-encoding
Use symbolic names internally
2 parents 83da57a + d3501e1 commit 1014af3

13 files changed

+58
-39
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ object NameKinds {
6161
def infoString: String
6262
}
6363

64-
/** The kind of SimpleNames */
6564
object SimpleNameKind extends NameKind(UTF8) { self =>
6665
type ThisInfo = Info
6766
val info = new Info
@@ -311,7 +310,7 @@ object NameKinds {
311310
val PatMatSelectorName = new UniqueNameKind("selector")
312311

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

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

337336
/** Names of the form N_<outer>. Emitted by inliner, replaced by outer path
338337
* in ExplicitOuter.
339338
*/
340-
object OuterSelectName extends NumberedNameKind(OUTERSELECT, "OuterSelect") {
339+
val OuterSelectName = new NumberedNameKind(OUTERSELECT, "OuterSelect") {
341340
def mkString(underlying: TermName, info: ThisInfo) = {
342341
assert(underlying.isEmpty)
343342
info.num + "_<outer>"
@@ -351,7 +350,9 @@ object NameKinds {
351350
val ProtectedSetterName = new PrefixNameKind(PROTECTEDSETTER, "protected$set") // dubious encoding, kept for Scala2 compatibility
352351
val AvoidClashName = new SuffixNameKind(AVOIDCLASH, "$_avoid_name_clash_$")
353352
val DirectMethodName = new SuffixNameKind(DIRECT, "$direct") { override def definesNewName = true }
354-
val FieldName = new SuffixNameKind(FIELD, "$$local")
353+
val FieldName = new SuffixNameKind(FIELD, "$$local") {
354+
override def mkString(underlying: TermName, info: ThisInfo) = underlying.toString
355+
}
355356
val ExtMethName = new SuffixNameKind(EXTMETH, "$extension")
356357
val ModuleVarName = new SuffixNameKind(OBJECTVAR, "$module")
357358
val ModuleClassName = new SuffixNameKind(OBJECTCLASS, "$", optInfoString = "ModuleClass")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ object Names {
247247
}
248248

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

252252
@sharable // because it's just a cache for performance
253253
private[this] var myMangled: Name = null

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,7 @@ object Types {
29302930
case tycon: TypeRef if !tycon.symbol.isClass =>
29312931
case _: TypeParamRef | _: ErrorType | _: WildcardType =>
29322932
case _: TypeLambda =>
2933-
assert(args.exists(_.isInstanceOf[TypeBounds]), s"unreduced type apply: $this")
2933+
assert(!args.exists(_.isInstanceOf[TypeBounds]), s"unreduced type apply: $this")
29342934
case tycon: AnnotatedType =>
29352935
check(tycon.underlying)
29362936
case _ =>

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ Macro-format:
3636
EXPANDEDPREFIX Length qualified_NameRef selector_NameRef
3737
TRAITSETTER Length qualified_NameRef selector_NameRef
3838
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
39-
DEFAULTGETTER Length underlying_NameRef index_Nat
40-
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
41-
OUTERSELECT Length underlying_NameRef nhops_Nat // a reference to `nhops` <outer> selections, followed by `underlying`
42-
43-
SUPERACCESSOR Length underlying_NameRef
44-
PROTECTEDACCESSOR Length underlying_NameRef
45-
PROTECTEDSETTER Length underlying_NameRef
46-
INITIALIZER Length underlying_NameRef
47-
SHADOWED Length underlying_NameRef
48-
AVOIDCLASH Length underlying_NameRef
49-
DIRECT Length underlying_NameRef
50-
FIELD Length underlying_NameRef
51-
EXTMETH Length underlying_NameRef
52-
OBJECTVAR Length underlying_NameRef
53-
OBJECTCLASS Length underlying_NameRef
39+
DEFAULTGETTER Length underlying_NameRef index_Nat
40+
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
41+
OUTERSELECT Length underlying_NameRef nhops_Nat // a reference to `nhops` <outer> selections, followed by `underlying`
42+
43+
SUPERACCESSOR Length underlying_NameRef
44+
PROTECTEDACCESSOR Length underlying_NameRef
45+
PROTECTEDSETTER Length underlying_NameRef
46+
INITIALIZER Length underlying_NameRef
47+
SHADOWED Length underlying_NameRef
48+
AVOIDCLASH Length underlying_NameRef
49+
DIRECT Length underlying_NameRef
50+
FIELD Length underlying_NameRef
51+
EXTMETH Length underlying_NameRef
52+
OBJECTVAR Length underlying_NameRef
53+
OBJECTCLASS Length underlying_NameRef
5454
SIGNED Length original_NameRef resultSig_NameRef paramSig_NameRef*
5555
5656
NameRef = Nat // ordinal number of name in name table, starting from 1.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ trait TypeAssigner {
9494
val refinableDecls = info.decls.filter(
9595
sym => !(sym.is(TypeParamAccessor | Private) || sym.isConstructor))
9696
val fullType = (parentType /: refinableDecls)(addRefinement)
97-
mapOver(fullType)
97+
apply(fullType)
9898
case TypeBounds(lo, hi) if variance > 0 =>
9999
apply(hi)
100100
case _ =>

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ class CompilationTests extends ParallelTesting {
244244
}.map(_.checkCompile()).foreach(_.delete())
245245
}
246246

247-
@Test def bytecodeIdempotency: Unit = {
247+
/** Add a `z` so that they run last. TODO: Only run them selectively? */
248+
@Test def zBytecodeIdempotency: Unit = {
248249
var failed = 0
249250
var total = 0
250251
val blacklisted = Set(

tests/pos/avoid.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,20 @@ object test {
88
}
99
val z: String = x.y
1010
}
11+
12+
// A tricky case involving inner classes, exercised
13+
// in the large in dotty.tools.dotc.core.NameKinds.scala.
14+
object Test2 {
15+
16+
class NK {
17+
class I
18+
type T
19+
}
20+
21+
val x = new NK { type T = I }
22+
23+
val y = {
24+
class C extends NK { type T = I }
25+
new C
26+
}
27+
}

tests/run/paramForwarding.check

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
B:
2-
private final int B.theValue$$local
3-
private final int B.theValueInB$$local
2+
private final int B.theValue
3+
private final int B.theValueInB
44
Bz:
5-
private final int Bz.theValue$$local
6-
private final int Bz.theValueInBz$$local
5+
private final int Bz.theValue
6+
private final int Bz.theValueInBz
77
C:
88

99
D:
10-
private final int D.other$$local
10+
private final int D.other
1111
NonVal:
1212

1313
X:
14-
private final int X.theValue$$local
14+
private final int X.theValue
1515
Y:
1616

tests/run/paramForwarding_separate.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Fields in A:
2-
private final int A.member$$local
2+
private final int A.member
33
# Fields in SubA:
44

55
# Fields in B:

tests/run/paramForwarding_together.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Fields in A:
2-
private final int A.member$$local
2+
private final int A.member
33
# Fields in SubA:
44

55
# Fields in B:

tests/run/paramForwarding_together_b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Fields in A:
2-
private final int A.member$$local
2+
private final int A.member
33
# Fields in SubA:
44

55
# Fields in B:

tests/run/statics.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import scala.annotation.static
22

33
class Foo{
44
class Bar {
5-
def qwa =
5+
def qwa =
66
Bar.field
77
// 0: invokestatic #31 // Method Foo$Bar$.field:()I
88
// 3: ireturn
99
}
1010
object Bar {
11-
@static
11+
@static
1212
val field = 1
1313
}
1414
}
1515

16-
object Foo{
16+
object Foo{
1717
@static
1818
def method = 1
1919

@@ -35,6 +35,6 @@ object Test {
3535
}
3636

3737
class WithLazies{
38-
@volatile lazy val s = 1
38+
@volatile lazy val s = 1
3939
// 98: getstatic #30 // Field WithLazies$.OFFSET$0:J
4040
}

tests/run/variable-pattern-access.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Fields of A:
2-
private final int A.a$$local
3-
private final int A.b$$local
2+
private final int A.a
3+
private final int A.b
44
private final scala.Tuple2 A.$1$
55
# Methods of A:
66
public int A.a()

0 commit comments

Comments
 (0)