Skip to content

Commit b5168aa

Browse files
committed
Do not capture Context in symExtension
1 parent 95c247d commit b5168aa

File tree

6 files changed

+56
-51
lines changed

6 files changed

+56
-51
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dotty.tools.dotc.core.Symbols._
1111
*/
1212
final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
1313
import interface._
14-
import interface.symExtensions
14+
import DottyBackendInterface.symExtensions
1515

1616
/**
1717
* True if `classSym` is an anonymous class or a local class. I.e., false if `classSym` is a

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
3030
// import definitions._
3131
import tpd._
3232
import int._
33-
import int.symExtensions
33+
import DottyBackendInterface.symExtensions
3434
import bTypes._
3535
import coreBTypes._
3636
import BCodeBodyBuilder._

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import dotty.tools.dotc.util.Spans._
2727
*/
2828
trait BCodeSkelBuilder extends BCodeHelpers {
2929
import int._
30-
import int.symExtensions
30+
import DottyBackendInterface.symExtensions
3131
import tpd._
3232
import bTypes._
3333
import coreBTypes._

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import dotty.tools.dotc.util.WeakHashSet
2727
*/
2828
class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
2929
import int._
30-
import int.symExtensions
30+
import DottyBackendInterface.symExtensions
3131

3232
lazy val TransientAttr = requiredClass[scala.transient]
3333
lazy val VolatileAttr = requiredClass[scala.volatile]

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

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,54 +65,8 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
6565
if (found == null) None else Some(found)
6666
}
6767

68-
extension symExtensions on (sym: Symbol) {
69-
70-
def isInterface: Boolean = (sym.is(Flags.PureInterface)) || sym.is(Flags.Trait)
71-
72-
def isStaticConstructor: Boolean = (sym.isStaticMember && sym.isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
73-
74-
def isStaticMember: Boolean = (sym ne NoSymbol) &&
75-
(sym.is(Flags.JavaStatic) || sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot))
76-
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
77-
78-
/**
79-
* True for module classes of modules that are top-level or owned only by objects. Module classes
80-
* for such objects will get a MODULE$ flag and a corresponding static initializer.
81-
*/
82-
def isStaticModuleClass: Boolean =
83-
(sym.is(Flags.Module)) && {
84-
// scalac uses atPickling here
85-
// this would not work if modules are created after pickling
86-
// for example by specialization
87-
val original = toDenot(sym).initial
88-
val validity = original.validFor
89-
val shiftedContext = ctx.withPhase(validity.phaseId)
90-
toDenot(sym)(shiftedContext).isStatic(shiftedContext)
91-
}
92-
9368

9469

95-
def originalLexicallyEnclosingClass: Symbol =
96-
// used to populate the EnclosingMethod attribute.
97-
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
98-
if (sym.exists) {
99-
val validity = toDenot(sym).initial.validFor
100-
val shiftedContext = ctx.withPhase(validity.phaseId)
101-
toDenot(sym)(shiftedContext).lexicallyEnclosingClass(shiftedContext)
102-
} else NoSymbol
103-
104-
/**
105-
* True for module classes of package level objects. The backend will generate a mirror class for
106-
* such objects.
107-
*/
108-
def isTopLevelModuleClass: Boolean =
109-
sym.is(Flags.ModuleClass) &&
110-
ctx.atPhase(ctx.flattenPhase) {
111-
toDenot(sym).owner.is(Flags.PackageClass)
112-
}
113-
114-
}
115-
11670
object SelectBI extends DeconstructorCommon[tpd.Tree] {
11771

11872
var desugared: tpd.Select = null
@@ -185,3 +139,54 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
185139
}
186140

187141
}
142+
143+
object DottyBackendInterface {
144+
145+
extension symExtensions on (sym: Symbol) {
146+
147+
def isInterface(using Context): Boolean = (sym.is(Flags.PureInterface)) || sym.is(Flags.Trait)
148+
149+
def isStaticConstructor(using Context): Boolean = (sym.isStaticMember && sym.isClassConstructor) || (sym.name eq nme.STATIC_CONSTRUCTOR)
150+
151+
def isStaticMember(using Context): Boolean = (sym ne NoSymbol) &&
152+
(sym.is(Flags.JavaStatic) || sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot))
153+
// guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone
154+
155+
/**
156+
* True for module classes of modules that are top-level or owned only by objects. Module classes
157+
* for such objects will get a MODULE$ flag and a corresponding static initializer.
158+
*/
159+
def isStaticModuleClass(using Context): Boolean =
160+
(sym.is(Flags.Module)) && {
161+
// scalac uses atPickling here
162+
// this would not work if modules are created after pickling
163+
// for example by specialization
164+
val original = toDenot(sym).initial
165+
val validity = original.validFor
166+
val shiftedContext = ctx.withPhase(validity.phaseId)
167+
toDenot(sym)(shiftedContext).isStatic(shiftedContext)
168+
}
169+
170+
171+
172+
def originalLexicallyEnclosingClass(using Context): Symbol =
173+
// used to populate the EnclosingMethod attribute.
174+
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
175+
if (sym.exists) {
176+
val validity = toDenot(sym).initial.validFor
177+
val shiftedContext = ctx.withPhase(validity.phaseId)
178+
toDenot(sym)(shiftedContext).lexicallyEnclosingClass(shiftedContext)
179+
} else NoSymbol
180+
181+
/**
182+
* True for module classes of package level objects. The backend will generate a mirror class for
183+
* such objects.
184+
*/
185+
def isTopLevelModuleClass(using Context): Boolean =
186+
sym.is(Flags.ModuleClass) &&
187+
ctx.atPhase(ctx.flattenPhase) {
188+
toDenot(sym).owner.is(Flags.PackageClass)
189+
}
190+
191+
}
192+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object GenBCode {
7070
}
7171

7272
class GenBCodePipeline(val int: DottyBackendInterface)(implicit ctx: Context) extends BCodeSyncAndTry {
73-
import int.symExtensions
73+
import DottyBackendInterface.symExtensions
7474

7575
private var tree: Tree = _
7676

0 commit comments

Comments
 (0)