Skip to content

Commit

Permalink
Use perRun for Definition members #2
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 17, 2019
1 parent 0b49754 commit 2bac1fe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
36 changes: 16 additions & 20 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,21 @@ class Definitions {
else NoSymbol)
cls
}
@threadUnsafe lazy val ScalaPackageObjectRef: TermRef = ctx.requiredModuleRef("scala.package")
@threadUnsafe lazy val ScalaPackageObject: SymbolPerRun = perRun(ctx.requiredModuleRef("scala.package"))
@threadUnsafe lazy val JavaPackageVal: TermSymbol = ctx.requiredPackage(nme.java)
@threadUnsafe lazy val JavaLangPackageVal: TermSymbol = ctx.requiredPackage(jnme.JavaLang)

// fundamental modules
@threadUnsafe lazy val SysPackage: TermSymbol = ctx.requiredModule("scala.sys.package")
@threadUnsafe lazy val SysPackage : SymbolPerRun = perRun(ctx.requiredModuleRef("scala.sys.package"))
@threadUnsafe lazy val Sys_error: SymbolPerRun = perRun(SysPackage.moduleClass.requiredMethodRef(nme.error))

@threadUnsafe lazy val ScalaXmlPackageClass: Symbol = ctx.getPackageClassIfDefined("scala.xml")

@threadUnsafe lazy val CompiletimePackageObjectRef: TermRef = ctx.requiredModuleRef("scala.compiletime.package")
@threadUnsafe lazy val CompiletimePackageObject: Symbol = CompiletimePackageObjectRef.symbol.moduleClass
@threadUnsafe lazy val Compiletime_error : SymbolPerRun = perRun(CompiletimePackageObjectRef.symbol.requiredMethodRef(nme.error))
@threadUnsafe lazy val Compiletime_constValue : SymbolPerRun = perRun(CompiletimePackageObjectRef.symbol.requiredMethodRef("constValue"))
@threadUnsafe lazy val Compiletime_constValueOpt: SymbolPerRun = perRun(CompiletimePackageObjectRef.symbol.requiredMethodRef("constValueOpt"))
@threadUnsafe lazy val Compiletime_code : SymbolPerRun = perRun(CompiletimePackageObjectRef.symbol.requiredMethodRef("code"))
@threadUnsafe lazy val CompiletimePackageObject: SymbolPerRun = perRun(ctx.requiredModuleRef("scala.compiletime.package"))
@threadUnsafe lazy val Compiletime_error : SymbolPerRun = perRun(CompiletimePackageObject.requiredMethodRef(nme.error))
@threadUnsafe lazy val Compiletime_constValue : SymbolPerRun = perRun(CompiletimePackageObject.requiredMethodRef("constValue"))
@threadUnsafe lazy val Compiletime_constValueOpt: SymbolPerRun = perRun(CompiletimePackageObject.requiredMethodRef("constValueOpt"))
@threadUnsafe lazy val Compiletime_code : SymbolPerRun = perRun(CompiletimePackageObject.requiredMethodRef("code"))

/** The `scalaShadowing` package is used to safely modify classes and
* objects in scala so that they can be used from dotty. They will
Expand All @@ -246,8 +246,7 @@ class Definitions {
* in `scalaShadowing` so they don't clash with the same-named `scala`
* members at runtime.
*/
@threadUnsafe lazy val ScalaShadowingPackageVal: TermSymbol = ctx.requiredPackage(nme.scalaShadowing)
def ScalaShadowingPackageClass(implicit ctx: Context): ClassSymbol = ScalaShadowingPackageVal.moduleClass.asClass
@threadUnsafe lazy val ScalaShadowingPackage: TermSymbol = ctx.requiredPackage(nme.scalaShadowing)

/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)
* because after erasure the Any and AnyVal references get remapped to the Object methods
Expand Down Expand Up @@ -364,8 +363,7 @@ class Definitions {
def ImplicitScrutineeTypeRef: TypeRef = ImplicitScrutineeTypeSym.typeRef


@threadUnsafe lazy val ScalaPredefModuleRef: TermRef = ctx.requiredModuleRef("scala.Predef")
def ScalaPredefModule(implicit ctx: Context): Symbol = ScalaPredefModuleRef.symbol
@threadUnsafe lazy val ScalaPredefModule: SymbolPerRun = perRun(ctx.requiredModuleRef("scala.Predef"))
@threadUnsafe lazy val Predef_conforms : SymbolPerRun = perRun(ScalaPredefModule.requiredMethodRef(nme.conforms_))
@threadUnsafe lazy val Predef_classOf : SymbolPerRun = perRun(ScalaPredefModule.requiredMethodRef(nme.classOf))
@threadUnsafe lazy val Predef_undefined: SymbolPerRun = perRun(ScalaPredefModule.requiredMethodRef(nme.???))
Expand All @@ -382,13 +380,11 @@ class Definitions {
else
ScalaPredefModule.requiredClass("DummyImplicit")

@threadUnsafe lazy val ScalaRuntimeModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.ScalaRunTime")
def ScalaRuntimeModule(implicit ctx: Context): Symbol = ScalaRuntimeModuleRef.symbol
@threadUnsafe lazy val ScalaRuntimeModule: SymbolPerRun = perRun(ctx.requiredModuleRef("scala.runtime.ScalaRunTime"))
def ScalaRuntimeClass(implicit ctx: Context): ClassSymbol = ScalaRuntimeModule.moduleClass.asClass

def runtimeMethodRef(name: PreName): TermRef = ScalaRuntimeModule.requiredMethodRef(name)
def ScalaRuntime_dropR(implicit ctx: Context): TermRef = runtimeMethodRef(nme.drop)
def ScalaRuntime_drop(implicit ctx: Context): Symbol = ScalaRuntime_dropR.symbol
def ScalaRuntime_drop: SymbolPerRun = perRun(runtimeMethodRef(nme.drop))

@threadUnsafe lazy val BoxesRunTimeModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.BoxesRunTime")
def BoxesRunTimeModule(implicit ctx: Context): Symbol = BoxesRunTimeModuleRef.symbol
Expand Down Expand Up @@ -1031,7 +1027,7 @@ class Definitions {
}

final def isCompiletime_S(sym: Symbol)(implicit ctx: Context): Boolean =
sym.name == tpnme.S && sym.owner == CompiletimePackageObject
sym.name == tpnme.S && sym.owner == CompiletimePackageObject.moduleClass

// ----- Symbol sets ---------------------------------------------------

Expand Down Expand Up @@ -1191,8 +1187,8 @@ class Definitions {
)

val PredefImportFns: List[() => TermRef] = List[() => TermRef](
() => ScalaPredefModuleRef,
() => DottyPredefModuleRef
() => ScalaPredefModule.termRef,
() => DottyPredefModule.termRef
)

@threadUnsafe lazy val RootImportFns: List[() => TermRef] =
Expand Down Expand Up @@ -1469,7 +1465,7 @@ class Definitions {
this.ctx = ctx
if (!isInitialized) {
// Enter all symbols from the scalaShadowing package in the scala package
for (m <- ScalaShadowingPackageClass.info.decls)
for (m <- ScalaShadowingPackage.info.decls)
ScalaPackageClass.enter(m)

// force initialization of every symbol that is synthesized or hijacked by the compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ClassfileParser(
} else if (result == Some(NoEmbedded)) {
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
classRoot.owner.asClass.delete(sym)
if (classRoot.owner == defn.ScalaShadowingPackageClass) {
if (classRoot.owner == defn.ScalaShadowingPackage.moduleClass) {
// Symbols in scalaShadowing are also added to scala
defn.ScalaPackageClass.delete(sym)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
* They are either aliased in scala.Predef or in the scala package object.
*/
private[this] lazy val printWithoutPrefix: Set[Symbol] =
(defn.ScalaPredefModuleRef.typeAliasMembers
++ defn.ScalaPackageObjectRef.typeAliasMembers).map(_.info.classSymbol).toSet
(defn.ScalaPredefModule.termRef.typeAliasMembers
++ defn.ScalaPackageObject.termRef.typeAliasMembers).map(_.info.classSymbol).toSet

def toText(tp: Type): Text = controlled {
homogenize(tp) match {
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ trait QuotesAndSplices { self: Typer =>
case quoted =>
ctx.compilationUnit.needsStaging = true
val tree1 =
if (quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext)
if (quoted.isType) typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuote.termRef), quoted :: Nil), pt)(quoteContext)
else if (ctx.mode.is(Mode.Pattern) && level == 0) typedQuotePattern(quoted, pt, qctx)
else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuoteR), quoted), pt)(quoteContext)
else typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprQuote.termRef), quoted), pt)(quoteContext)
tree1.withSpan(tree.span)
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ trait QuotesAndSplices { self: Typer =>
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)
markAsMacro(ctx)
}
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext).withSpan(tree.span)
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSplice.termRef), tree.expr), pt)(spliceContext).withSpan(tree.span)
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ trait QuotesAndSplices { self: Typer =>
val exprTpt = AppliedTypeTree(TypeTree(defn.QuotedExprType), tpt1 :: Nil)
transform(Splice(Typed(pat, exprTpt)))
case Splice(pat) =>
try ref(defn.InternalQuoted_patternHoleR).appliedToType(tree.tpe).withSpan(tree.span)
try ref(defn.InternalQuoted_patternHole.termRef).appliedToType(tree.tpe).withSpan(tree.span)
finally {
val patType = pat.tpe.widen
val patType1 = patType.underlyingIfRepeated(isJava = false)
Expand Down Expand Up @@ -347,9 +347,9 @@ trait QuotesAndSplices { self: Typer =>
val splicePat = typed(untpd.Tuple(splices.map(x => untpd.TypedSplice(replaceBindingsInTree.transform(x)))).withSpan(quoted.span), patType)

UnApply(
fun = ref(defn.InternalQuotedMatcher_unapplyR).appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
fun = ref(defn.InternalQuotedMatcher_unapply.termRef).appliedToTypeTrees(typeBindingsTuple :: TypeTree(patType) :: Nil),
implicits =
ref(defn.InternalQuoted_exprQuoteR).appliedToType(shape.tpe).appliedTo(shape) ::
ref(defn.InternalQuoted_exprQuote.termRef).appliedToType(shape.tpe).appliedTo(shape) ::
Literal(Constant(typeBindings.nonEmpty)) ::
qctx :: Nil,
patterns = splicePat :: Nil,
Expand Down

0 comments on commit 2bac1fe

Please sign in to comment.