Skip to content

Remove mixin traits of Context #9343

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 10 commits into from
Jul 20, 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
2 changes: 1 addition & 1 deletion bench/src/main/scala/Benchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Worker extends Driver {
}
catch {
case ex: FatalError =>
ctx.error(ex.getMessage) // signals that we should fail compilation.
report.error(ex.getMessage) // signals that we should fail compilation.
ctx.reporter
}
else ctx.reporter
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeAsmCommon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package jvm

import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.report

/**
* This trait contains code shared between GenBCode and GenASM that depends on types defined in
Expand Down Expand Up @@ -89,7 +90,7 @@ final class BCodeAsmCommon[I <: DottyBackendInterface](val interface: I) {
def enclosingMethodAttribute(classSym: Symbol, classDesc: Symbol => String, methodDesc: Symbol => String): Option[EnclosingMethodEntry] = {
if (isAnonymousOrLocalClass(classSym)) {
val methodOpt = enclosingMethodForEnclosingMethodAttribute(classSym)
ctx.debuglog(s"enclosing method for $classSym is $methodOpt (in ${methodOpt.map(_.enclosingClass)})")
report.debuglog(s"enclosing method for $classSym is $methodOpt (in ${methodOpt.map(_.enclosingClass)})")
Some(EnclosingMethodEntry(
classDesc(enclosingClassForEnclosingMethodAttribute(classSym)),
methodOpt.map(_.javaSimpleName).orNull,
Expand Down
15 changes: 8 additions & 7 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.transform.SymUtils._
import dotty.tools.dotc.util.Spans._
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.report

/*
*
Expand Down Expand Up @@ -277,7 +278,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {

tree match {
case ValDef(nme.THIS, _, _) =>
ctx.debuglog("skipping trivial assign to _$this: " + tree)
report.debuglog("skipping trivial assign to _$this: " + tree)

case tree@ValDef(_, _, _) =>
val sym = tree.symbol
Expand Down Expand Up @@ -326,9 +327,9 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
else {
val arity = app.meth.tpe.widenDealias.firstParamTypes.size - env.size
val returnsUnit = app.meth.tpe.widenDealias.resultType.classSymbol == defn.UnitClass
if (returnsUnit) ctx.requiredClass(("dotty.runtime.function.JProcedure" + arity))
else if (arity <= 2) ctx.requiredClass(("dotty.runtime.function.JFunction" + arity))
else ctx.requiredClass(("scala.Function" + arity))
if (returnsUnit) requiredClass(("dotty.runtime.function.JProcedure" + arity))
else if (arity <= 2) requiredClass(("dotty.runtime.function.JFunction" + arity))
else requiredClass(("scala.Function" + arity))
}
}
val (fun, args) = call match {
Expand Down Expand Up @@ -669,7 +670,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
var elemKind = arr.elementType
val argsSize = args.length
if (argsSize > dims) {
ctx.error(s"too many arguments for array constructor: found ${args.length} but array has only $dims dimension(s)", ctx.source.atSpan(app.span))
report.error(s"too many arguments for array constructor: found ${args.length} but array has only $dims dimension(s)", ctx.source.atSpan(app.span))
}
if (argsSize < dims) {
/* In one step:
Expand Down Expand Up @@ -1431,7 +1432,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
def genInvokeDynamicLambda(ctor: Symbol, lambdaTarget: Symbol, environmentSize: Int, functionalInterface: Symbol): BType = {
import java.lang.invoke.LambdaMetafactory.FLAG_SERIALIZABLE

ctx.debuglog(s"Using invokedynamic rather than `new ${ctor.owner}`")
report.debuglog(s"Using invokedynamic rather than `new ${ctor.owner}`")
val generatedType = classBTypeFromSymbol(functionalInterface)
// Lambdas should be serializable if they implement a SAM that extends Serializable or if they
// implement a scala.Function* class.
Expand Down
41 changes: 21 additions & 20 deletions compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.Trees
import dotty.tools.dotc.core.Annotations._
import dotty.tools.dotc.core.Constants._
import dotty.tools.dotc.core.Contexts.{Context, atPhase}
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.Flags._
Expand All @@ -27,6 +27,7 @@ import dotty.tools.dotc.core.Types._
import dotty.tools.dotc.core.TypeErasure
import dotty.tools.dotc.transform.GenericSignatures
import dotty.tools.io.AbstractFile
import dotty.tools.dotc.report

import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions

Expand All @@ -52,11 +53,11 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
def ScalaATTRName: String = "Scala"
def ScalaSignatureATTRName: String = "ScalaSig"

@threadUnsafe lazy val AnnotationRetentionAttr: ClassSymbol = ctx.requiredClass("java.lang.annotation.Retention")
@threadUnsafe lazy val AnnotationRetentionSourceAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
@threadUnsafe lazy val AnnotationRetentionClassAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
@threadUnsafe lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
@threadUnsafe lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")
@threadUnsafe lazy val AnnotationRetentionAttr: ClassSymbol = requiredClass("java.lang.annotation.Retention")
@threadUnsafe lazy val AnnotationRetentionSourceAttr: TermSymbol = requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
@threadUnsafe lazy val AnnotationRetentionClassAttr: TermSymbol = requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
@threadUnsafe lazy val AnnotationRetentionRuntimeAttr: TermSymbol = requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
@threadUnsafe lazy val JavaAnnotationClass: ClassSymbol = requiredClass("java.lang.annotation.Annotation")

val bCodeAsmCommon: BCodeAsmCommon[int.type] = new BCodeAsmCommon(int)
import bCodeAsmCommon._
Expand All @@ -76,7 +77,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
outputDirectory
} catch {
case ex: Throwable =>
ctx.error(s"Couldn't create file for class $cName\n${ex.getMessage}", ctx.source.atSpan(csym.span))
report.error(s"Couldn't create file for class $cName\n${ex.getMessage}", ctx.source.atSpan(csym.span))
null
}
}
Expand Down Expand Up @@ -425,7 +426,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
emitAssocs(nestedVisitor, assocs, bcodeStore)(innerClasesStore)

case t =>
ctx.error(ex"Annotation argument is not a constant", t.sourcePos)
report.error(ex"Annotation argument is not a constant", t.sourcePos)
}
}

Expand Down Expand Up @@ -563,26 +564,26 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
*/
def addForwarders(jclass: asm.ClassVisitor, jclassName: String, moduleClass: Symbol): Unit = {
assert(moduleClass.is(ModuleClass), moduleClass)
ctx.debuglog(s"Dumping mirror class for object: $moduleClass")
report.debuglog(s"Dumping mirror class for object: $moduleClass")

val linkedClass = moduleClass.companionClass
lazy val conflictingNames: Set[Name] = {
(linkedClass.info.allMembers.collect { case d if d.name.isTermName => d.name }).toSet
}
ctx.debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")
report.debuglog(s"Potentially conflicting names for forwarders: $conflictingNames")

for (m0 <- sortedMembersBasedOnFlags(moduleClass.info, required = Method, excluded = ExcludedForwarder)) {
val m = if (m0.is(Bridge)) m0.nextOverriddenSymbol else m0
if (m == NoSymbol)
ctx.log(s"$m0 is a bridge method that overrides nothing, something went wrong in a previous phase.")
report.log(s"$m0 is a bridge method that overrides nothing, something went wrong in a previous phase.")
else if (m.isType || m.is(Deferred) || (m.owner eq defn.ObjectClass) || m.isConstructor || m.name.is(ExpandedName))
ctx.debuglog(s"No forwarder for '$m' from $jclassName to '$moduleClass'")
report.debuglog(s"No forwarder for '$m' from $jclassName to '$moduleClass'")
else if (conflictingNames(m.name))
ctx.log(s"No forwarder for $m due to conflict with ${linkedClass.info.member(m.name)}")
report.log(s"No forwarder for $m due to conflict with ${linkedClass.info.member(m.name)}")
else if (m.accessBoundary(defn.RootClass) ne defn.RootClass)
ctx.log(s"No forwarder for non-public member $m")
report.log(s"No forwarder for non-public member $m")
else {
ctx.log(s"Adding static forwarder for '$m' from $jclassName to '$moduleClass'")
report.log(s"Adding static forwarder for '$m' from $jclassName to '$moduleClass'")
addForwarder(jclass, moduleClass, m)
}
}
Expand Down Expand Up @@ -822,7 +823,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
*/
case a @ AnnotatedType(t, _) =>
ctx.debuglog(s"typeKind of annotated type $a")
report.debuglog(s"typeKind of annotated type $a")
typeToTypeKind(t)(ct)(storage)

/* The cases below should probably never occur. They are kept for now to avoid introducing
Expand All @@ -831,7 +832,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
*/

case tp =>
ctx.warning(
report.warning(
s"an unexpected type representation reached the compiler backend while compiling ${ctx.compilationUnit}: $tp. " +
"If possible, please file a bug on https://github.com/lampepfl/dotty/issues")

Expand Down Expand Up @@ -871,7 +872,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
try body
catch {
case ex: Throwable =>
ctx.error(i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
report.error(i"""|compiler bug: created invalid generic signature for $sym in ${sym.denot.owner.showFullName}
|signature: $sig
|if this is reproducible, please report bug at https://github.com/lampepfl/dotty/issues
""".trim, sym.sourcePos)
Expand Down Expand Up @@ -922,11 +923,11 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
}

def abort(msg: String): Nothing = {
ctx.error(msg)
report.error(msg)
throw new RuntimeException(msg)
}

private def compilingArray(using ctx: Context) =
private def compilingArray(using Context) =
ctx.compilationUnit.source.file.name == "Array.scala"
}

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.annotation.switch
import scala.collection.mutable
import Primitives.{NE, EQ, TestOp, ArithmeticOp}
import scala.tools.asm.tree.MethodInsnNode
import dotty.tools.dotc.report

/*
* A high-level facade to the ASM API for bytecode generation.
Expand Down Expand Up @@ -585,7 +586,7 @@ trait BCodeIdiomatic {
}

def abort(msg: String): Nothing = {
ctx.error(msg)
report.error(msg)
throw new RuntimeException(msg)
}

Expand Down
15 changes: 8 additions & 7 deletions compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import dotty.tools.dotc.core.StdNames.str
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.util.Spans._
import dotty.tools.dotc.report

/*
*
Expand Down Expand Up @@ -118,12 +119,12 @@ trait BCodeSkelBuilder extends BCodeHelpers {
val optSerial: Option[Long] =
claszSymbol.getAnnotation(defn.SerialVersionUIDAnnot).flatMap { annot =>
if (claszSymbol.is(Trait)) {
ctx.error("@SerialVersionUID does nothing on a trait", annot.tree.sourcePos)
report.error("@SerialVersionUID does nothing on a trait", annot.tree.sourcePos)
None
} else {
val vuid = annot.argumentConstant(0).map(_.longValue)
if (vuid.isEmpty)
ctx.error("The argument passed to @SerialVersionUID must be a constant",
report.error("The argument passed to @SerialVersionUID must be a constant",
annot.argument(0).getOrElse(annot.tree).sourcePos)
vuid
}
Expand Down Expand Up @@ -192,7 +193,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
// it must be a top level class (name contains no $s)
val isCandidateForForwarders = (lmoc.is(Module)) && lmoc.isStatic
if (isCandidateForForwarders) {
ctx.log(s"Adding static forwarders from '$claszSymbol' to implementations in '$lmoc'")
report.log(s"Adding static forwarders from '$claszSymbol' to implementations in '$lmoc'")
addForwarders(cnode, thisName, lmoc.moduleClass)
}
}
Expand Down Expand Up @@ -388,7 +389,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
*/
def makeLocal(tk: BType, name: String, tpe: Type, pos: Span): Symbol = {

val locSym = ctx.newSymbol(methSymbol, name.toTermName, Synthetic, tpe, NoSymbol, pos)
val locSym = newSymbol(methSymbol, name.toTermName, Synthetic, tpe, NoSymbol, pos)
makeLocal(locSym, tk)
locSym
}
Expand All @@ -407,7 +408,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
val loc = Local(tk, sym.javaSimpleName, nxtIdx, sym.is(Synthetic))
val existing = slots.put(sym, loc)
if (existing.isDefined)
ctx.error("attempt to create duplicate local var.", ctx.source.atSpan(sym.span))
report.error("attempt to create duplicate local var.", ctx.source.atSpan(sym.span))
assert(tk.size > 0, "makeLocal called for a symbol whose type is Unit.")
nxtIdx += tk.size
loc
Expand Down Expand Up @@ -560,7 +561,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {

if (params.size > MaximumJvmParameters) {
// SI-7324
ctx.error(s"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
report.error(s"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
return
}

Expand All @@ -587,7 +588,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
case (_: Return) | Block(_, (_: Return)) => ()
case (_: Apply) | Block(_, (_: Apply)) if rhs.symbol eq defn.throwMethod => ()
case tpd.EmptyTree =>
ctx.error("Concrete method has no definition: " + dd + (
report.error("Concrete method has no definition: " + dd + (
if (ctx.settings.Ydebug.value) "(found: " + methSymbol.owner.info.decls.toList.mkString(", ") + ")"
else ""),
ctx.source.atSpan(NoSpan)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.collection.mutable
import scala.collection.generic.Clearable

import dotty.tools.dotc.core.Flags._
import dotty.tools.dotc.core.Contexts.{inContext, atPhase}
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Phases.Phase
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package jvm

import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream, File => JFile }
import dotty.tools.io._
import dotty.tools.dotc.report

import java.util.jar.Attributes.Name
import scala.language.postfixOps

Expand Down Expand Up @@ -61,7 +63,7 @@ trait BytecodeWriters {
try out.write(jclassBytes, 0, jclassBytes.length)
finally out.flush()

ctx.informProgress("added " + label + path + " to jar")
report.informProgress("added " + label + path + " to jar")
}
override def close() = writer.close()
}
Expand Down Expand Up @@ -111,7 +113,7 @@ trait BytecodeWriters {

try outstream.write(jclassBytes, 0, jclassBytes.length)
finally outstream.close()
ctx.informProgress("wrote '" + label + "' to " + outfile)
report.informProgress("wrote '" + label + "' to " + outfile)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dotty.tools.backend.jvm

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.{Context, ctx}
import dotty.tools.dotc.core.Contexts._
import dotty.tools.dotc.core.Phases._
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Flags.Trait
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/CoreBTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class CoreBTypes[BTFS <: BTypesFromSymbols[_ <: DottyBackendInterface]](val bTyp
* names of NothingClass and NullClass can't be emitted as-is.
* TODO @lry Once there's a 2.11.3 starr, use the commented argument list. The current starr crashes on the type literal `scala.runtime.Nothing$`
*/
lazy val RT_NOTHING : ClassBType = classBTypeFromSymbol(ctx.requiredClass("scala.runtime.Nothing$")) // (requiredClass[scala.runtime.Nothing$])
lazy val RT_NULL : ClassBType = classBTypeFromSymbol(ctx.requiredClass("scala.runtime.Null$")) // (requiredClass[scala.runtime.Null$])
lazy val RT_NOTHING : ClassBType = classBTypeFromSymbol(requiredClass("scala.runtime.Nothing$")) // (requiredClass[scala.runtime.Nothing$])
lazy val RT_NULL : ClassBType = classBTypeFromSymbol(requiredClass("scala.runtime.Null$")) // (requiredClass[scala.runtime.Null$])

lazy val ObjectReference : ClassBType = classBTypeFromSymbol(defn.ObjectClass)
lazy val objArrayReference : ArrayBType = ArrayBType(ObjectReference)
Expand Down
16 changes: 12 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Phases._

import dotty.tools.dotc.util
import dotty.tools.dotc.util.Spans
import dotty.tools.dotc.report

import Decorators._
import Constants._
import tpd._
Expand Down Expand Up @@ -81,7 +83,7 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
def _1: Type = field.tpe match {
case JavaArrayType(elem) => elem
case _ =>
ctx.error(s"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
report.error(s"JavaSeqArray with type ${field.tpe} reached backend: $field", ctx.source.atSpan(field.span))
UnspecifiedErrorType
}
def _2: List[Tree] = field.elems
Expand All @@ -107,13 +109,19 @@ object DottyBackendInterface {
else clazz.getName
}

def requiredClass(str: String)(using Context): ClassSymbol =
Symbols.requiredClass(str)

def requiredClass[T](using evidence: ClassTag[T], ctx: Context): Symbol =
ctx.requiredClass(erasureString(evidence.runtimeClass))
requiredClass(erasureString(evidence.runtimeClass))

def requiredModule(str: String)(using Context): Symbol =
Symbols.requiredModule(str)

def requiredModule[T](using evidence: ClassTag[T], ctx: Context): Symbol = {
val moduleName = erasureString(evidence.runtimeClass)
val className = if (moduleName.endsWith("$")) moduleName.dropRight(1) else moduleName
ctx.requiredModule(className)
requiredModule(className)
}

given symExtensions as AnyRef:
Expand Down Expand Up @@ -189,7 +197,7 @@ object DottyBackendInterface {
* True if the current compilation unit is of a primitive class (scala.Boolean et al).
* Used only in assertions.
*/
def isCompilingPrimitive(using ctx: Context) = {
def isCompilingPrimitive(using Context) = {
primitiveCompilationUnits(ctx.compilationUnit.source.file.name)
}

Expand Down
Loading