Skip to content

Commit 45efefa

Browse files
committed
Type alias for InternalName
1 parent 91435f6 commit 45efefa

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ import scala.tools.asm
1010
import asm.Opcodes
1111

1212
/**
13-
* The BTypes component defines The BType class hierarchy. BTypes encapsulates all type information
13+
* The BTypes component defines The BType class hierarchy. BTypes encapsulate all type information
1414
* that is required after building the ASM nodes. This includes optimizations, generation of
1515
* InnerClass attributes and generation of stack map frames.
1616
*
1717
* This representation is immutable and independent of the compiler data structures, hence it can
1818
* be queried by concurrent threads.
1919
*/
2020
abstract class BTypes {
21+
import BTypes.InternalName
22+
2123
/**
2224
* A map from internal names to ClassBTypes. Every ClassBType is added to this map on its
2325
* construction.
@@ -29,12 +31,12 @@ abstract class BTypes {
2931
* Concurrent because stack map frames are computed when in the class writer, which might run
3032
* on multiple classes concurrently.
3133
*/
32-
protected val classBTypeFromInternalNameMap: collection.concurrent.Map[String, ClassBType]
34+
protected val classBTypeFromInternalNameMap: collection.concurrent.Map[InternalName, ClassBType]
3335

3436
/**
3537
* Obtain a previously constructed ClassBType for a given internal name.
3638
*/
37-
def classBTypeFromInternalName(internalName: String) = classBTypeFromInternalNameMap(internalName)
39+
def classBTypeFromInternalName(internalName: InternalName) = classBTypeFromInternalNameMap(internalName)
3840

3941
// Some core BTypes are required here, in class BType, where no Global instance is available.
4042
// The Global is only available in the subclass BTypesFromSymbols. We cannot depend on the actual
@@ -566,7 +568,7 @@ abstract class BTypes {
566568
* A ClassBType represents a class or interface type. The necessary information to build a
567569
* ClassBType is extracted from compiler symbols and types, see BTypesFromSymbols.
568570
*/
569-
final case class ClassBType(internalName: String) extends RefBType {
571+
final case class ClassBType(internalName: InternalName) extends RefBType {
570572
/**
571573
* Write-once variable allows initializing a cyclic graph of infos. This is required for
572574
* nested classes. Example: for the definition `class A { class B }` we have
@@ -827,3 +829,12 @@ abstract class BTypes {
827829
*/
828830
def isCompilingPrimitive: Boolean
829831
}
832+
833+
object BTypes {
834+
/**
835+
* A marker for strings that represent class internal names.
836+
* Ideally the type would be incompatible with String, for example by making it a value class.
837+
* But that would create overhead in a Collection[InternalName].
838+
*/
839+
type InternalName = String
840+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package scala.tools.nsc
77
package backend.jvm
88

99
import scala.tools.asm
10+
import BTypes.InternalName
1011

1112
/**
1213
* This class mainly contains the method classBTypeFromSymbol, which extracts the necessary
@@ -37,7 +38,7 @@ class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
3738
}
3839

3940
protected val classBTypeFromInternalNameMap = {
40-
global.perRunCaches.recordCache(collection.concurrent.TrieMap.empty[String, ClassBType])
41+
global.perRunCaches.recordCache(collection.concurrent.TrieMap.empty[InternalName, ClassBType])
4142
}
4243

4344
/**

0 commit comments

Comments
 (0)