Skip to content

Commit 1e4439a

Browse files
committed
Move methods
1 parent 1a7dc1e commit 1e4439a

File tree

5 files changed

+85
-87
lines changed

5 files changed

+85
-87
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,15 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
13511351
*/
13521352
val mustUseAnyComparator: Boolean = {
13531353
val areSameFinals = l.tpe.typeSymbol.is(Flags.Final) && r.tpe.typeSymbol.is(Flags.Final) && (l.tpe =:= r.tpe)
1354-
1354+
// todo: remove
1355+
def isMaybeBoxed(sym: Symbol): Boolean = {
1356+
(sym == defn.ObjectClass) ||
1357+
(sym == defn.JavaSerializableClass) ||
1358+
(sym == defn.ComparableClass) ||
1359+
(sym derivesFrom defn.BoxedNumberClass) ||
1360+
(sym derivesFrom defn.BoxedCharClass) ||
1361+
(sym derivesFrom defn.BoxedBooleanClass)
1362+
}
13551363
!areSameFinals && isMaybeBoxed(l.tpe.widenDealias.typeSymbol) && isMaybeBoxed(r.tpe.widenDealias.typeSymbol)
13561364
}
13571365
def isNull(t: Tree): Boolean = t match {

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import dotty.tools.dotc.core.Decorators._
1717
import dotty.tools.dotc.core.Flags
1818
import dotty.tools.dotc.core.Names.Name
1919
import dotty.tools.dotc.core.NameKinds.ExpandedName
20-
import dotty.tools.dotc.core.Symbols._
20+
import dotty.tools.dotc.core.Signature
2121
import dotty.tools.dotc.core.StdNames._
22+
import dotty.tools.dotc.core.Symbols._
2223
import dotty.tools.dotc.core.Types
24+
import dotty.tools.dotc.core.Types._
2325

2426
/*
2527
* Traits encapsulating functionality to convert Scala AST Trees into ASM ClassNodes.
@@ -183,7 +185,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
183185

184186
trait BCInnerClassGen {
185187

186-
def debugLevel = int.debuglevel
188+
def debugLevel = 3 // 0 -> no debug info; 1-> filename; 2-> lines; 3-> varnames
187189

188190
final val emitSource = debugLevel >= 1
189191
final val emitLines = debugLevel >= 2
@@ -323,6 +325,12 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
323325
emitAssocs(pannVisitor, assocs, BCodeHelpers.this)(this)
324326
}
325327

328+
329+
private def shouldEmitAnnotation(annot: Annotation): Boolean = {
330+
annot.symbol.is(Flags.JavaDefined) &&
331+
retentionPolicyOf(annot) != AnnotationRetentionSourceAttr
332+
}
333+
326334
private def emitAssocs(av: asm.AnnotationVisitor, assocs: List[(Name, Object)], bcodeStore: BCodeHelpers)
327335
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
328336
for ((name, value) <- assocs)
@@ -412,6 +420,20 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
412420
case _ => arg
413421
}
414422

423+
private def isRuntimeVisible(annot: Annotation): Boolean =
424+
if (toDenot(annot.tree.tpe.typeSymbol).hasAnnotation(AnnotationRetentionAttr))
425+
retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr
426+
else {
427+
// SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the
428+
// annotation is emitted with visibility `RUNTIME`
429+
// dotty bug: #389
430+
true
431+
}
432+
433+
private def retentionPolicyOf(annot: Annotation): Symbol =
434+
annot.tree.tpe.typeSymbol.getAnnotation(AnnotationRetentionAttr).
435+
flatMap(_.argumentConstant(0).map(_.symbolValue)).getOrElse(AnnotationRetentionClassAttr)
436+
415437
} // end of trait BCAnnotGen
416438

417439
trait BCJGenSigGen {
@@ -527,6 +549,20 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
527549
}
528550
}
529551

552+
/** The members of this type that have all of `required` flags but none of `excluded` flags set.
553+
* The members are sorted by name and signature to guarantee a stable ordering.
554+
*/
555+
private def sortedMembersBasedOnFlags(tp: Type, required: Flags.Flag, excluded: Flags.FlagSet): List[Symbol] = {
556+
// The output of `memberNames` is a Set, sort it to guarantee a stable ordering.
557+
val names = tp.memberNames(takeAllFilter).toSeq.sorted
558+
val buffer = mutable.ListBuffer[Symbol]()
559+
names.foreach { name =>
560+
buffer ++= tp.memberBasedOnFlags(name, required, excluded)
561+
.alternatives.sortBy(_.signature)(Signature.lexicographicOrdering).map(_.symbol)
562+
}
563+
buffer.toList
564+
}
565+
530566
/*
531567
* Quoting from JVMS 4.7.5 The Exceptions Attribute
532568
* "The Exceptions attribute indicates which checked exceptions a method may throw.

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import scala.annotation.threadUnsafe
77

88
import dotty.tools.dotc.core.Flags
99
import dotty.tools.dotc.core.Symbols._
10+
import dotty.tools.dotc.transform.SymUtils._
1011

1112
/**
1213
* This class mainly contains the method classBTypeFromSymbol, which extracts the necessary
@@ -89,7 +90,22 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
8990
val superClass = if (superClassSym == NoSymbol) None
9091
else Some(classBTypeFromSymbol(superClassSym))
9192

92-
val interfaces = symHelper(classSym).superInterfaces.map(classBTypeFromSymbol)
93+
/**
94+
* All interfaces implemented by a class, except for those inherited through the superclass.
95+
* Redundant interfaces are removed unless there is a super call to them.
96+
*/
97+
def (sym: Symbol).superInterfaces: List[Symbol] = {
98+
val directlyInheritedTraits = sym.directlyInheritedTraits
99+
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
100+
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
101+
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
102+
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait))
103+
// if (additional.nonEmpty)
104+
// println(s"$fullName: adding supertraits $additional")
105+
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCalls(t)) ++ additional
106+
}
107+
108+
val interfaces = classSym.superInterfaces.map(classBTypeFromSymbol)
93109

94110
val flags = javaFlags(classSym)
95111

@@ -166,7 +182,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
166182
if (!isNested) None
167183
else {
168184
// See comment in BTypes, when is a class marked static in the InnerClass table.
169-
val isStaticNestedClass = symHelper(symHelper(innerClassSym.originalOwner).originalLexicallyEnclosingClass).isOriginallyStaticOwner
185+
val isStaticNestedClass = symHelper(innerClassSym.originalOwner).originalLexicallyEnclosingClass.isOriginallyStaticOwner
170186

171187
// After lambdalift (which is where we are), the rawowoner field contains the enclosing class.
172188
val enclosingClassSym = {
@@ -184,6 +200,8 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
184200
None
185201
} else {
186202
val outerName = symHelper(innerClassSym.originalOwner).originalLexicallyEnclosingClass.fullName.mangledString.replace('.', '/')
203+
def dropModule(str: String): String =
204+
if (!str.isEmpty && str.last == '$') str.take(str.length - 1) else str
187205
// Java compatibility. See the big comment in BTypes that summarizes the InnerClass spec.
188206
val outerNameModule =
189207
if (symHelper(symHelper(innerClassSym.originalOwner).originalLexicallyEnclosingClass).isTopLevelModuleClass) dropModule(outerName)
@@ -204,6 +222,18 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
204222
}
205223
}
206224

225+
/**
226+
* This is basically a re-implementation of sym.isStaticOwner, but using the originalOwner chain.
227+
*
228+
* The problem is that we are interested in a source-level property. Various phases changed the
229+
* symbol's properties in the meantime, mostly lambdalift modified (destructively) the owner.
230+
* Therefore, `sym.isStatic` is not what we want. For example, in
231+
* object T { def f { object U } }
232+
* the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here.
233+
*/
234+
private def (sym: Symbol).isOriginallyStaticOwner: Boolean =
235+
sym.is(Flags.PackageClass) || sym.is(Flags.ModuleClass) && symHelper(sym.originalOwner).originalLexicallyEnclosingClass.isOriginallyStaticOwner
236+
207237
/**
208238
* Return the Java modifiers for the given symbol.
209239
* Java modifiers for classes:

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait BytecodeWriters {
3535

3636
def factoryNonJarBytecodeWriter(): BytecodeWriter = {
3737
val emitAsmp = None
38-
val doDump = int.dumpClasses
38+
val doDump = dumpClasses
3939
(emitAsmp.isDefined, doDump.isDefined) match {
4040
case (false, false) => new ClassBytecodeWriter { }
4141
case (false, true ) => new ClassBytecodeWriter with DumpBytecodeWriter { }
@@ -116,7 +116,7 @@ trait BytecodeWriters {
116116
}
117117

118118
trait DumpBytecodeWriter extends BytecodeWriter {
119-
val baseDir = Directory(int.dumpClasses.get).createDirectory()
119+
val baseDir = Directory(dumpClasses.get).createDirectory()
120120

121121
abstract override def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], outfile: AbstractFile): Unit = {
122122
super.writeClass(label, jclassName, jclassBytes, outfile)
@@ -130,4 +130,8 @@ trait BytecodeWriters {
130130
finally outstream.close()
131131
}
132132
}
133+
134+
private def dumpClasses: Option[String] =
135+
if (ctx.settings.Ydumpclasses.isDefault) None
136+
else Some(ctx.settings.Ydumpclasses.value)
133137
}

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

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
5757

5858
val primitives = new DottyPrimitives(ctx)
5959

60-
def isRuntimeVisible(annot: Annotation): Boolean =
61-
if (toDenot(annot.tree.tpe.typeSymbol).hasAnnotation(AnnotationRetentionAttr))
62-
retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr
63-
else {
64-
// SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the
65-
// annotation is emitted with visibility `RUNTIME`
66-
// dotty bug: #389
67-
true
68-
}
69-
70-
def shouldEmitAnnotation(annot: Annotation): Boolean = {
71-
annot.symbol.is(Flags.JavaDefined) &&
72-
retentionPolicyOf(annot) != AnnotationRetentionSourceAttr
73-
}
74-
75-
private def retentionPolicyOf(annot: Annotation): Symbol =
76-
annot.tree.tpe.typeSymbol.getAnnotation(AnnotationRetentionAttr).
77-
flatMap(_.argumentConstant(0).map(_.symbolValue)).getOrElse(AnnotationRetentionClassAttr)
78-
7960
private def erasureString(clazz: Class[_]): String = {
8061
if (clazz.isArray) "Array[" + erasureString(clazz.getComponentType) + "]"
8162
else clazz.getName
@@ -97,12 +78,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
9778
def sourcePos(pos: Spans.Span)(implicit ctx: Context): util.SourcePosition =
9879
ctx.source.atSpan(pos)
9980

100-
def dumpClasses: Option[String] =
101-
if (ctx.settings.Ydumpclasses.isDefault) None
102-
else Some(ctx.settings.Ydumpclasses.value)
103-
104-
def debuglevel: Int = 3 // 0 -> no debug info; 1-> filename; 2-> lines; 3-> varnames
105-
10681
val perRunCaches: Caches = new Caches {
10782
def newAnyRefMap[K <: AnyRef, V](): mutable.AnyRefMap[K, V] = new mutable.AnyRefMap[K, V]()
10883
def newWeakMap[K, V](): mutable.WeakHashMap[K, V] = new mutable.WeakHashMap[K, V]()
@@ -112,9 +87,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
11287
def newSet[K](): mutable.Set[K] = new mutable.HashSet[K]
11388
}
11489

115-
def dropModule(str: String): String =
116-
if (!str.isEmpty && str.last == '$') str.take(str.length - 1) else str
117-
11890
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
11991

12092
def desugarIdentBI(i: Ident): Option[tpd.Select] = {
@@ -130,16 +102,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
130102
if (found == null) None else Some(found)
131103
}
132104

133-
// todo: remove
134-
def isMaybeBoxed(sym: Symbol): Boolean = {
135-
(sym == defn.ObjectClass) ||
136-
(sym == defn.JavaSerializableClass) ||
137-
(sym == defn.ComparableClass) ||
138-
(sym derivesFrom defn.BoxedNumberClass) ||
139-
(sym derivesFrom defn.BoxedCharClass) ||
140-
(sym derivesFrom defn.BoxedBooleanClass)
141-
}
142-
143105
// @M don't generate java generics sigs for (members of) implementation
144106
// classes, as they are monomorphic (TODO: ok?)
145107
private final def needsGenericSignature(sym: Symbol): Boolean = !(
@@ -318,21 +280,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
318280
}
319281
else Nil
320282

321-
/**
322-
* All interfaces implemented by a class, except for those inherited through the superclass.
323-
* Redundant interfaces are removed unless there is a super call to them.
324-
*/
325-
def superInterfaces: List[Symbol] = {
326-
val directlyInheritedTraits = decorateSymbol(sym).directlyInheritedTraits
327-
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
328-
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
329-
val superCalls = superCallsMap.getOrElse(sym, Set.empty)
330-
val additional = (superCalls -- directlyInheritedTraitsSet).filter(_.is(Flags.Trait))
331-
// if (additional.nonEmpty)
332-
// println(s"$fullName: adding supertraits $additional")
333-
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCalls(t)) ++ additional
334-
}
335-
336283
/**
337284
* True for module classes of package level objects. The backend will generate a mirror class for
338285
* such objects.
@@ -353,33 +300,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
353300
}
354301
}
355302

356-
357-
/**
358-
* This is basically a re-implementation of sym.isStaticOwner, but using the originalOwner chain.
359-
*
360-
* The problem is that we are interested in a source-level property. Various phases changed the
361-
* symbol's properties in the meantime, mostly lambdalift modified (destructively) the owner.
362-
* Therefore, `sym.isStatic` is not what we want. For example, in
363-
* object T { def f { object U } }
364-
* the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here.
365-
*/
366-
def isOriginallyStaticOwner: Boolean =
367-
sym.is(Flags.PackageClass) || sym.is(Flags.ModuleClass) && symHelper(symHelper(sym.originalOwner).originalLexicallyEnclosingClass).isOriginallyStaticOwner
368-
}
369-
370-
371-
/** The members of this type that have all of `required` flags but none of `excluded` flags set.
372-
* The members are sorted by name and signature to guarantee a stable ordering.
373-
*/
374-
def sortedMembersBasedOnFlags(tp: Type, required: Flags.Flag, excluded: Flags.FlagSet): List[Symbol] = {
375-
// The output of `memberNames` is a Set, sort it to guarantee a stable ordering.
376-
val names = tp.memberNames(takeAllFilter).toSeq.sorted
377-
val buffer = mutable.ListBuffer[Symbol]()
378-
names.foreach { name =>
379-
buffer ++= tp.memberBasedOnFlags(name, required, excluded)
380-
.alternatives.sortBy(_.signature)(Signature.lexicographicOrdering).map(_.symbol)
381-
}
382-
buffer.toList
383303
}
384304

385305
object SelectBI extends DeconstructorCommon[tpd.Tree] {

0 commit comments

Comments
 (0)