Skip to content

Commit 3ecfae3

Browse files
committed
Eliminate remaining PerRun datastructures
1 parent 65b448c commit 3ecfae3

File tree

9 files changed

+32
-57
lines changed

9 files changed

+32
-57
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
154154
@threadUnsafe lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
155155
@threadUnsafe lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")
156156

157-
def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def?
157+
def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses.map{x => // @darkdimius Are you sure this should be a def?
158158
(x, Erasure.Boxing.boxMethod(x.asClass))
159159
}.toMap
160160
def unboxMethods: Map[Symbol, Symbol] =
161-
defn.ScalaValueClasses().map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap
161+
defn.ScalaValueClasses.map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap
162162

163163
override def isSyntheticArrayConstructor(s: Symbol): Boolean = {
164164
s eq defn.newArrayMethod

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2696,7 +2696,7 @@ class JSCodeGen()(implicit ctx: Context) {
26962696

26972697
private object WrapArray {
26982698
lazy val isWrapArray: Set[Symbol] = {
2699-
val names0 = defn.ScalaValueClasses().map(sym => nme.wrapXArray(sym.name))
2699+
val names0 = defn.ScalaValueClasses.map(sym => nme.wrapXArray(sym.name))
27002700
val names1 = names0 ++ Set(nme.wrapRefArray, nme.genericWrapArray)
27012701
val names2 = names1.map(defn.ScalaPredefModule.requiredMethod(_))
27022702
names2.toSet

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

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ class Definitions {
883883
@threadUnsafe lazy val FunctionClass: Array[Symbol] =
884884
mkArityArray("scala.Function", MaxImplementedFunctionArity, 0).map(_.symbol.asClass)
885885

886-
val LazyHolder: PerRun[Map[Symbol, Symbol]] = new PerRun({ implicit ctx =>
886+
@threadUnsafe lazy val LazyHolder: Map[Symbol, Symbol] = {
887887
def holderImpl(holderType: String) = ctx.requiredClass("scala.runtime." + holderType)
888888
Map[Symbol, Symbol](
889889
IntClass -> holderImpl("LazyInt"),
@@ -896,7 +896,7 @@ class Definitions {
896896
ShortClass -> holderImpl("LazyShort")
897897
)
898898
.withDefaultValue(holderImpl("LazyRef"))
899-
})
899+
}
900900

901901
@threadUnsafe lazy val TupleType: Array[TypeRef] = mkArityArray("scala.Tuple", MaxTupleArity, 1)
902902

@@ -1108,39 +1108,28 @@ class Definitions {
11081108
isNonRefinedFunction(tp.dropDependentRefinement)
11091109

11101110
// Specialized type parameters defined for scala.Function{0,1,2}.
1111-
@threadUnsafe lazy val Function1SpecializedParamTypes: collection.Set[TypeRef] =
1112-
Set(IntType, LongType, FloatType, DoubleType)
1113-
@threadUnsafe lazy val Function2SpecializedParamTypes: collection.Set[TypeRef] =
1114-
Set(IntType, LongType, DoubleType)
1115-
@threadUnsafe lazy val Function0SpecializedReturnTypes: collection.Set[TypeRef] =
1116-
ScalaNumericValueTypeList.toSet + UnitType + BooleanType
1117-
@threadUnsafe lazy val Function1SpecializedReturnTypes: collection.Set[TypeRef] =
1118-
Set(UnitType, BooleanType, IntType, FloatType, LongType, DoubleType)
1119-
@threadUnsafe lazy val Function2SpecializedReturnTypes: collection.Set[TypeRef] =
1120-
Function1SpecializedReturnTypes
1121-
1122-
@threadUnsafe lazy val Function1SpecializedParamClasses: PerRun[collection.Set[Symbol]] =
1123-
new PerRun(implicit ctx => Function1SpecializedParamTypes.map(_.symbol))
1124-
@threadUnsafe lazy val Function2SpecializedParamClasses: PerRun[collection.Set[Symbol]] =
1125-
new PerRun(implicit ctx => Function2SpecializedParamTypes.map(_.symbol))
1126-
@threadUnsafe lazy val Function0SpecializedReturnClasses: PerRun[collection.Set[Symbol]] =
1127-
new PerRun(implicit ctx => Function0SpecializedReturnTypes.map(_.symbol))
1128-
@threadUnsafe lazy val Function1SpecializedReturnClasses: PerRun[collection.Set[Symbol]] =
1129-
new PerRun(implicit ctx => Function1SpecializedReturnTypes.map(_.symbol))
1130-
@threadUnsafe lazy val Function2SpecializedReturnClasses: PerRun[collection.Set[Symbol]] =
1131-
new PerRun(implicit ctx => Function2SpecializedReturnTypes.map(_.symbol))
1111+
@threadUnsafe lazy val Function1SpecializedParamClasses: collection.Set[Symbol] =
1112+
Set(IntType, LongType, FloatType, DoubleType).map(_.symbol)
1113+
@threadUnsafe lazy val Function2SpecializedParamClasses: collection.Set[Symbol] =
1114+
Set(IntType, LongType, DoubleType).map(_.symbol)
1115+
@threadUnsafe lazy val Function0SpecializedReturnClasses: collection.Set[Symbol] =
1116+
(ScalaNumericValueTypeList.toSet + UnitType + BooleanType).map(_.symbol)
1117+
@threadUnsafe lazy val Function1SpecializedReturnClasses: collection.Set[Symbol] =
1118+
Set(UnitType, BooleanType, IntType, FloatType, LongType, DoubleType).map(_.symbol)
1119+
@threadUnsafe lazy val Function2SpecializedReturnClasses: collection.Set[Symbol] =
1120+
Function1SpecializedReturnClasses
11321121

11331122
def isSpecializableFunction(cls: ClassSymbol, paramTypes: List[Type], retType: Type)(implicit ctx: Context): Boolean =
11341123
paramTypes.length <= 2 && cls.derivesFrom(FunctionClass(paramTypes.length)) && (paramTypes match {
11351124
case Nil =>
1136-
Function0SpecializedReturnClasses().contains(retType.typeSymbol)
1125+
Function0SpecializedReturnClasses.contains(retType.typeSymbol)
11371126
case List(paramType0) =>
1138-
Function1SpecializedParamClasses().contains(paramType0.typeSymbol) &&
1139-
Function1SpecializedReturnClasses().contains(retType.typeSymbol)
1127+
Function1SpecializedParamClasses.contains(paramType0.typeSymbol) &&
1128+
Function1SpecializedReturnClasses.contains(retType.typeSymbol)
11401129
case List(paramType0, paramType1) =>
1141-
Function2SpecializedParamClasses().contains(paramType0.typeSymbol) &&
1142-
Function2SpecializedParamClasses().contains(paramType1.typeSymbol) &&
1143-
Function2SpecializedReturnClasses().contains(retType.typeSymbol)
1130+
Function2SpecializedParamClasses.contains(paramType0.typeSymbol) &&
1131+
Function2SpecializedParamClasses.contains(paramType1.typeSymbol) &&
1132+
Function2SpecializedReturnClasses.contains(retType.typeSymbol)
11441133
case _ =>
11451134
false
11461135
})
@@ -1188,31 +1177,17 @@ class Definitions {
11881177

11891178
// ----- primitive value class machinery ------------------------------------------
11901179

1191-
/** This class would also be obviated by the implicit function type design */
1192-
class PerRun[T](generate: Context => T) {
1193-
private[this] var current: RunId = NoRunId
1194-
private[this] var cached: T = _
1195-
def apply()(implicit ctx: Context): T = {
1196-
if (current != ctx.runId) {
1197-
cached = generate(ctx)
1198-
current = ctx.runId
1199-
}
1200-
cached
1201-
}
1202-
}
1203-
12041180
@threadUnsafe lazy val ScalaNumericValueTypeList: List[TypeRef] = List(
12051181
ByteType, ShortType, CharType, IntType, LongType, FloatType, DoubleType)
12061182

12071183
@threadUnsafe private lazy val ScalaNumericValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypeList.toSet
12081184
@threadUnsafe private lazy val ScalaValueTypes: collection.Set[TypeRef] = ScalaNumericValueTypes + UnitType + BooleanType
12091185

1210-
val ScalaNumericValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaNumericValueTypes.map(_.symbol))
1211-
val ScalaValueClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx => ScalaValueTypes.map(_.symbol))
1186+
@threadUnsafe lazy val ScalaNumericValueClasses: collection.Set[Symbol] = ScalaNumericValueTypes.map(_.symbol)
1187+
@threadUnsafe lazy val ScalaValueClasses: collection.Set[Symbol] = ScalaValueTypes.map(_.symbol)
12121188

1213-
val ScalaBoxedClasses: PerRun[collection.Set[Symbol]] = new PerRun(implicit ctx =>
1189+
@threadUnsafe lazy val ScalaBoxedClasses: collection.Set[Symbol] =
12141190
Set(BoxedByteClass, BoxedShortClass, BoxedCharClass, BoxedIntClass, BoxedLongClass, BoxedFloatClass, BoxedDoubleClass, BoxedUnitClass, BoxedBooleanClass)
1215-
)
12161191

12171192
private val valueTypeEnc = mutable.Map[TypeName, PrimitiveClassEnc]()
12181193
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)
@@ -1314,7 +1289,7 @@ class Definitions {
13141289
ScalaPackageClass.enter(m)
13151290

13161291
// force initialization of every symbol that is synthesized or hijacked by the compiler
1317-
val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses() :+ JavaEnumClass
1292+
val forced = syntheticCoreClasses ++ syntheticCoreMethods ++ ScalaValueClasses :+ JavaEnumClass
13181293

13191294
isInitialized = true
13201295
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,11 @@ object SymDenotations {
600600

601601
/** Is symbol a primitive value class? */
602602
def isPrimitiveValueClass(implicit ctx: Context): Boolean =
603-
maybeOwner == defn.ScalaPackageClass && defn.ScalaValueClasses().contains(symbol)
603+
maybeOwner == defn.ScalaPackageClass && defn.ScalaValueClasses.contains(symbol)
604604

605605
/** Is symbol a primitive numeric value class? */
606606
def isNumericValueClass(implicit ctx: Context): Boolean =
607-
maybeOwner == defn.ScalaPackageClass && defn.ScalaNumericValueClasses().contains(symbol)
607+
maybeOwner == defn.ScalaPackageClass && defn.ScalaNumericValueClasses.contains(symbol)
608608

609609
/** Is symbol a class for which no runtime representation exists? */
610610
def isNotRuntimeClass(implicit ctx: Context): Boolean = defn.NotRuntimeClasses contains symbol

compiler/src/dotty/tools/dotc/transform/ArrayApply.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ArrayApply extends MiniPhase {
5151
case _: Literal => true // ClassTag.apply(classOf[XYZ])
5252
case rc: RefTree if rc.name == nme.TYPE_ =>
5353
// ClassTag.apply(java.lang.XYZ.Type)
54-
defn.ScalaBoxedClasses().contains(rc.symbol.maybeOwner.companionClass)
54+
defn.ScalaBoxedClasses.contains(rc.symbol.maybeOwner.companionClass)
5555
case _ => false
5656
}
5757
case Apply(ctm: RefTree, _) if ctm.symbol.maybeOwner.companionModule == defn.ClassTagModule =>

compiler/src/dotty/tools/dotc/transform/CapturedVars.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisPhase =
3232
private class RefInfo(implicit ctx: Context) {
3333
/** The classes for which a Ref type exists. */
3434
val refClassKeys: collection.Set[Symbol] =
35-
defn.ScalaNumericValueClasses() + defn.BooleanClass + defn.ObjectClass
35+
defn.ScalaNumericValueClasses + defn.BooleanClass + defn.ObjectClass
3636

3737
val refClass: Map[Symbol, Symbol] =
3838
refClassKeys.map(rc => rc -> ctx.requiredClass(s"scala.runtime.${rc.name}Ref")).toMap

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ object Erasure {
176176
*/
177177
private def safelyRemovableUnboxArg(tree: Tree)(implicit ctx: Context): Tree = tree match {
178178
case Apply(fn, arg :: Nil)
179-
if isUnbox(fn.symbol) && defn.ScalaBoxedClasses().contains(arg.tpe.widen.typeSymbol) =>
179+
if isUnbox(fn.symbol) && defn.ScalaBoxedClasses.contains(arg.tpe.widen.typeSymbol) =>
180180
arg
181181
case _ =>
182182
EmptyTree

compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class InterceptedMethods extends MiniPhase {
9191
List(qual, typer.resolveClassTag(tree.pos, qual.tpe.widen))))
9292
}*/
9393
*/
94-
case t if t.name == nme.getClass_ && defn.ScalaValueClasses().contains(t.owner) =>
94+
case t if t.name == nme.getClass_ && defn.ScalaValueClasses.contains(t.owner) =>
9595
// if we got here then we're trying to send a primitive getClass method to either
9696
// a) an Any, in which cage Object_getClass works because Any erases to object. Or
9797
//

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
146146

147147
// val x$lzy = new scala.runtime.LazyInt()
148148
val holderName = LazyLocalName.fresh(xname)
149-
val holderImpl = defn.LazyHolder()(ctx)(tpe.typeSymbol)
149+
val holderImpl = defn.LazyHolder(tpe.typeSymbol)
150150
val holderSymbol = ctx.newSymbol(x.symbol.owner, holderName, containerFlags, holderImpl.typeRef, coord = x.span)
151151
val holderTree = ValDef(holderSymbol, New(holderImpl.typeRef, Nil))
152152

0 commit comments

Comments
 (0)