Skip to content

Commit c12f213

Browse files
committed
Merge pull request #358 from dotty-staging/backend-backports
Backend discovered issues
2 parents b2ca9fe + 10167c4 commit c12f213

File tree

8 files changed

+40
-8
lines changed

8 files changed

+40
-8
lines changed

src/dotty/tools/dotc/Run.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import scala.reflect.io.VirtualFile
1313

1414
class Run(comp: Compiler)(implicit ctx: Context) {
1515

16+
assert(comp.phases.last.last.id <= Periods.MaxPossiblePhaseId)
17+
assert(ctx.runId <= Periods.MaxPossibleRunId)
18+
1619
var units: List[CompilationUnit] = _
1720

1821
def getSource(fileName: String): SourceFile = {

src/dotty/tools/dotc/core/Periods.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,19 @@ object Periods {
119119
object Period {
120120

121121
/** The single-phase period consisting of given run id and phase id */
122-
def apply(rid: RunId, pid: PhaseId): Period =
122+
def apply(rid: RunId, pid: PhaseId): Period = {
123123
new Period(((rid << PhaseWidth) | pid) << PhaseWidth)
124+
}
124125

125126
/** The period consisting of given run id, and lo/hi phase ids */
126-
def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period =
127+
def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period = {
127128
new Period(((rid << PhaseWidth) | hiPid) << PhaseWidth | (hiPid - loPid))
129+
}
128130

129131
/** The interval consisting of all periods of given run id */
130-
def allInRun(rid: RunId) =
132+
def allInRun(rid: RunId) = {
131133
apply(rid, 0, PhaseMask)
134+
}
132135
}
133136

134137
final val Nowhere = new Period(0)
@@ -141,6 +144,8 @@ object Periods {
141144
type RunId = Int
142145
final val NoRunId = 0
143146
final val InitialRunId = 1
147+
final val RunWidth = java.lang.Integer.SIZE - PhaseWidth * 2 - 1/* sign */
148+
final val MaxPossibleRunId = (1 << RunWidth) - 1
144149

145150
/** An ordinal number for phases. First phase has number 1. */
146151
type PhaseId = Int

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,21 @@ object SymDenotations {
292292
if (isType) fn.toTypeName else fn.toTermName
293293
}
294294

295+
296+
/** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */
297+
def flatName(separator: Char = '$')(implicit ctx: Context): Name =
298+
if (symbol == NoSymbol || owner == NoSymbol || owner.isEffectiveRoot || (owner is PackageClass)) name
299+
else {
300+
var owner = this
301+
var sep = ""
302+
do {
303+
owner = owner.owner
304+
sep += separator
305+
} while (!owner.isClass && !owner.isPackageObject)
306+
val fn = owner.flatName(separator) ++ sep ++ name
307+
if (isType) fn.toTypeName else fn.toTermName
308+
}
309+
295310
/** `fullName` where `.' is the separator character */
296311
def fullName(implicit ctx: Context): Name = fullNameSeparated('.')
297312

@@ -622,15 +637,22 @@ object SymDenotations {
622637
* the completers.
623638
*/
624639
/** The class implementing this module, NoSymbol if not applicable. */
625-
final def moduleClass(implicit ctx: Context): Symbol =
640+
final def moduleClass(implicit ctx: Context): Symbol = {
641+
def notFound = {println(s"missing module class for $name: $myInfo"); NoSymbol}
626642
if (this is ModuleVal)
627643
myInfo match {
628644
case info: TypeRef => info.symbol
629645
case ExprType(info: TypeRef) => info.symbol // needed after uncurry, when module terms might be accessor defs
630646
case info: LazyType => info.moduleClass
631-
case _ => println(s"missing module class for $name: $myInfo"); NoSymbol
647+
case t: MethodType =>
648+
t.resultType match {
649+
case info: TypeRef => info.symbol
650+
case _ => notFound
651+
}
652+
case _ => notFound
632653
}
633654
else NoSymbol
655+
}
634656

635657
/** The module implemented by this module class, NoSymbol if not applicable. */
636658
final def sourceModule(implicit ctx: Context): Symbol = myInfo match {

src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
3535
case ref: ClassDenotation if ref is ModuleClass =>
3636
ref.linkedClass match {
3737
case origClass: ClassSymbol if isDerivedValueClass(origClass) =>
38-
val cinfo = ref.classInfo
38+
val cinfo = ref.classInfo // ./tests/pos/t2667.scala dies here for module class AnyVal$
3939
val decls1 = cinfo.decls.cloneScope
4040
ctx.atPhase(thisTransformer.next) { implicit ctx =>
4141
for (decl <- origClass.classInfo.decls) {

src/dotty/tools/dotc/transform/Flatten.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Flatten extends MiniPhaseTransform with SymTransformer { thisTransform =>
1919
def transformSym(ref: SymDenotation)(implicit ctx: Context) = {
2020
if (ref.isClass && !ref.is(Package) && !ref.owner.is(Package)) {
2121
ref.copySymDenotation(
22-
name = ref.flatName,
22+
name = ref.flatName(),
2323
owner = ref.enclosingPackageClass)
2424
}
2525
else ref

src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class SymUtils(val self: Symbol) extends AnyVal {
9393
self.owner.info.decl(self.asTerm.name.fieldName).suchThat(!_.is(Method)).symbol
9494

9595
/** `fullName` where `$' is the separator character */
96-
def flatName(implicit ctx: Context): Name = self.fullNameSeparated('$')
96+
def flatName(implicit ctx: Context): Name = self.flatName('$')
9797

9898
def initializer(implicit ctx: Context): TermSymbol =
9999
self.owner.info.decl(InitializerName(self.asTerm.name)).symbol.asTerm

tests/pos/t2667.scala renamed to tests/disabled/t2667.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ExtensionMethods info transformer fails here for AnyVal$
12
object A {
23
def foo(x: Int, y: Int*): Int = 45
34
def foo[T](x: T*): Int = 55

tests/pos/t2669.scala renamed to tests/disabled/t2669.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// #2629, #2639, #2669
2+
// dies in classfile parser while parsing java.util.Vector(requested by bakend)
23
object Test2669 {
34

45
def test[T](l: java.util.ArrayList[_ <: T]) = 1

0 commit comments

Comments
 (0)