Skip to content

Add some more caches #9722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1104,8 +1104,6 @@ class Definitions {
@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0)
val AbstractFunctionClassPerRun: PerRun[Array[Symbol]] = new PerRun(AbstractFunctionType.map(_.symbol.asClass))
def AbstractFunctionClass(n: Int)(using Context): Symbol = AbstractFunctionClassPerRun()(using ctx)(n)
@tu private lazy val ImplementedFunctionType = mkArityArray("scala.Function", MaxImplementedFunctionArity, 0)
def FunctionClassPerRun: PerRun[Array[Symbol]] = new PerRun(ImplementedFunctionType.map(_.symbol.asClass))

val LazyHolder: PerRun[Map[Symbol, Symbol]] = new PerRun({
def holderImpl(holderType: String) = requiredClass("scala.runtime." + holderType)
Expand All @@ -1124,23 +1122,33 @@ class Definitions {

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

private class FunType(prefix: String):
private var classRefs: Array[TypeRef] = new Array(22)
def apply(n: Int): TypeRef =
while n >= classRefs.length do
val classRefs1 = new Array[TypeRef](classRefs.length * 2)
Array.copy(classRefs, 0, classRefs1, 0, classRefs.length)
classRefs = classRefs1
if classRefs(n) == null then
classRefs(n) = requiredClassRef(prefix + n.toString)
classRefs(n)

private val erasedContextFunType = FunType("scala.ErasedContextFunction")
private val contextFunType = FunType("scala.ContextFunction")
private val erasedFunType = FunType("scala.ErasedFunction")
private val funType = FunType("scala.Function")

def FunctionClass(n: Int, isContextual: Boolean = false, isErased: Boolean = false)(using Context): Symbol =
if (isContextual && isErased)
requiredClass("scala.ErasedContextFunction" + n.toString)
else if (isContextual)
requiredClass("scala.ContextFunction" + n.toString)
else if (isErased)
requiredClass("scala.ErasedFunction" + n.toString)
else if (n <= MaxImplementedFunctionArity)
FunctionClassPerRun()(n)
else
requiredClass("scala.Function" + n.toString)

@tu lazy val Function0_apply: Symbol = ImplementedFunctionType(0).symbol.requiredMethod(nme.apply)
( if isContextual && isErased then erasedContextFunType(n)
else if isContextual then contextFunType(n)
else if isErased then erasedFunType(n)
else funType(n)
).symbol.asClass

@tu lazy val Function0_apply: Symbol = FunctionClass(0).requiredMethod(nme.apply)

def FunctionType(n: Int, isContextual: Boolean = false, isErased: Boolean = false)(using Context): TypeRef =
if (n <= MaxImplementedFunctionArity && (!isContextual || ctx.erasedTypes) && !isErased) ImplementedFunctionType(n)
else FunctionClass(n, isContextual, isErased).typeRef
FunctionClass(n, isContextual && !ctx.erasedTypes, isErased).typeRef

lazy val PolyFunctionClass = requiredClass("scala.PolyFunction")
def PolyFunctionType = PolyFunctionClass.typeRef
Expand Down
13 changes: 11 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ object Names {
val (first, last, sep) = split
if (first.isEmpty) f2(last) else str.sanitize(f1(first) + sep + f2(last))
}

protected def computeToString: String

@sharable private var myToString: String = null

override def toString =
if myToString == null then myToString = computeToString
myToString

}

/** A simple name is essentially an interned string */
Expand Down Expand Up @@ -371,7 +380,7 @@ object Names {

override def hashCode: Int = start

override def toString: String =
protected def computeToString: String =
if (length == 0) ""
else {
if (Config.checkBackendNames)
Expand Down Expand Up @@ -500,7 +509,7 @@ object Names {
case qual: QualifiedInfo => qual.name
case _ => underlying.lastPart
}
override def toString: String = info.mkString(underlying)
protected def computeToString: String = info.mkString(underlying)
override def debugString: String = s"${underlying.debugString}[$info]"
}

Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ object SymbolLoaders {
Stats.record("package scopes")

/** The scope of a package. This is different from a normal scope
* in two aspects:
*
* 1. Names of scope entries are kept in mangled form.
* 2. Some function types in the `scala` package are synthesized.
* in that names of scope entries are kept in mangled form.
*/
final class PackageScope extends MutableScope {
override def newScopeEntry(name: Name, sym: Symbol)(using Context): ScopeEntry =
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-with-compiler/lazyValsSepComp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ import dotty.tools.dotc.core.Contexts._
object Foo {
val definitions: Definitions = null
def defn = definitions
def go = defn.FunctionClassPerRun
def go = defn.ScalaBoxedClasses
}