Skip to content
Closed
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
44 changes: 26 additions & 18 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
// import global.*
// import definitions.*
import tpd.*
import int.{_, given}
import int.{*, given}
import DottyBackendInterface.symExtensions
import bTypes.*
import coreBTypes.*
Expand Down Expand Up @@ -431,16 +431,16 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val tk = symInfoTK(sym)
generatedType = tk

val desugared = cachedDesugarIdent(t)
/*val desugared = cachedDesugarIdent(t)
desugared match {
case None =>
if (!sym.is(Package)) {
if (sym.is(Module)) genLoadModule(sym)
else locals.load(sym)
}
case None =>*/
if (!sym.is(Package)) {
if (sym.is(Module)) genLoadModule(sym)
else locals.load(sym)
}/*
case Some(t) =>
genLoad(t, generatedType)
}
throw new AssertionError("How could we reach here? " + t.show) //genLoad(t, generatedType)
}*/

case Literal(value) =>
if (value.tag != UnitTag) (value.tag, expectedType) match {
Expand Down Expand Up @@ -469,7 +469,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
generatedType = UNIT
genStat(tree)

case av @ ArrayValue(_, _) =>
case av: tpd.JavaSeqLiteral =>
generatedType = genArrayValue(av)

case mtch @ Match(_, _) =>
Expand Down Expand Up @@ -750,10 +750,10 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
lineNumber(app)
app match {
case Apply(_, args) if app.symbol eq defn.newArrayMethod =>
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args: @unchecked
val List(elemClaz, Literal(c: Constant), av: tpd.JavaSeqLiteral) = args: @unchecked

generatedType = toTypeKind(c.typeValue)
mkArrayConstructorCall(generatedType.asArrayBType, app, dims)
mkArrayConstructorCall(generatedType.asArrayBType, app, av.elems)
case Apply(t :TypeApply, _) =>
generatedType =
if (t.symbol ne defn.Object_synchronized) genTypeApply(t)
Expand Down Expand Up @@ -878,10 +878,16 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
} // end of genApply()

private def genArrayValue(av: tpd.JavaSeqLiteral): BType = {
val ArrayValue(tpt, elems) = av: @unchecked
//val ArrayValue(tpt, elems) = av: @unchecked
val tpt = av.tpe match {
case JavaArrayType(elem) => elem
case _ =>
report.error(em"JavaSeqArray with type ${av.tpe} reached backend: $av", ctx.source.atSpan(av.span))
UnspecifiedErrorType
}

lineNumber(av)
genArray(elems, tpt)
genArray(av.elems, tpt)
}

private def genArray(elems: List[Tree], elemType: Type): BType = {
Expand Down Expand Up @@ -1190,12 +1196,14 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
tree match {
case DesugaredSelect(qualifier, _) => genLoad(qualifier)
case t: Ident => // dotty specific
cachedDesugarIdent(t) match {
case Some(sel) => genLoadQualifier(sel)
case None =>
/*cachedDesugarIdent(t) match {
case Some(sel) =>
throw new AssertionError("how could this happen? " + t.show)
//genLoadQualifier(sel)
case None =>*/
assert(t.symbol.owner == this.claszSymbol)
UNIT
}
//}
case _ => abort(s"Unknown qualifier $tree")
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ trait BCodeHelpers extends BCodeIdiomatic {
}

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

Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait BCodeIdiomatic {
val int: DottyBackendInterface
val bTypes: BTypesFromSymbols[int.type]

import int.{_, given}
// import int.{_, given}
import bTypes.*
import coreBTypes.*

Expand Down Expand Up @@ -554,14 +554,14 @@ trait BCodeIdiomatic {
jmethod.visitTypeInsn(Opcodes.INSTANCEOF, tk.classOrArrayType)
}

// can-multi-thread
// can-multire-thread
final def checkCast(tk: RefBType): Unit = {
// TODO ICode also requires: but that's too much, right? assert(!isBoxedType(tk), "checkcast on boxed type: " + tk)
jmethod.visitTypeInsn(Opcodes.CHECKCAST, tk.classOrArrayType)
}

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/BTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.tools.asm
abstract class BTypes { self =>
val frontendAccess: PostProcessorFrontendAccess
val int: DottyBackendInterface
import int.given
//import int.given
/**
* A map from internal names to ClassBTypes. Every ClassBType is added to this map on its
* construction.
Expand Down Expand Up @@ -611,7 +611,7 @@ abstract class BTypes { self =>
assert(!ClassBType.isInternalPhantomType(internalName), s"Cannot create ClassBType for phantom type $this")

assert(
if (info.superClass.isEmpty) { isJLO(this) || (DottyBackendInterface.isCompilingPrimitive && ClassBType.hasNoSuper(internalName)) }
if (info.superClass.isEmpty) { true /*isJLO(this) || (DottyBackendInterface.isCompilingPrimitive && ClassBType.hasNoSuper(internalName))*/ }
else if (isInterface) isJLO(info.superClass.get)
else !isJLO(this) && ifInit(info.superClass.get)(!_.isInterface),
s"Invalid superClass in $this: ${info.superClass}"
Expand Down
14 changes: 6 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,21 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I, val frontendAcce
val superClass = if (superClassSym == NoSymbol) None
else Some(classBTypeFromSymbol(superClassSym))

/**
* All interfaces implemented by a class, except for those inherited through the superclass.
/*
* Find all interfaces implemented by a class, except for those inherited through the superclass.
* Redundant interfaces are removed unless there is a super call to them.
*/
extension (sym: Symbol) def superInterfaces: List[Symbol] = {
val directlyInheritedTraits = sym.directlyInheritedTraits
val interfaces = {
val directlyInheritedTraits = classSym.directlyInheritedTraits
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
val superCalls = superCallsMap.getOrElse(sym, List.empty)
val superCalls = superCallsMap.getOrElse(classSym, List.empty)
val superCallsSet = superCalls.toSet
val additional = superCalls.filter(t => !directlyInheritedTraitsSet(t) && t.is(Trait))
// if (additional.nonEmpty)
// println(s"$fullName: adding supertraits $additional")
directlyInheritedTraits.filter(t => !allBaseClasses(t) || superCallsSet(t)) ++ additional
}

val interfaces = classSym.superInterfaces.map(classBTypeFromSymbol)
}.map(classBTypeFromSymbol)

val flags = javaFlags(classSym)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSym

private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]

def cachedDesugarIdent(i: Ident): Option[tpd.Select] = {
private def cachedDesugarIdent(i: Ident): Option[tpd.Select] = {
var found = desugared.get(i.tpe)
if (found == null) {
tpd.desugarIdent(i) match {
Expand Down Expand Up @@ -67,15 +67,15 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, List[ClassSym
}
}

object ArrayValue extends DeconstructorCommon[tpd.JavaSeqLiteral] {
/*object ArrayValue extends DeconstructorCommon[tpd.JavaSeqLiteral] {
def _1: Type = field.nn.tpe match {
case JavaArrayType(elem) => elem
case _ =>
report.error(em"JavaSeqArray with type ${field.nn.tpe} reached backend: $field", ctx.source.atSpan(field.nn.span))
UnspecifiedErrorType
}
def _2: List[Tree] = field.nn.elems
}
}*/

abstract class DeconstructorCommon[T <: AnyRef] {
var field: T | Null = null
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/LabelNode1.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public LabelNode1(Label label) {
super(label);
}

public int flags;
//public int flags;
}
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class DottyPrimitives(ictx: Context) {
* @param tpe The type of the receiver object. It is used only for array
* operations
*/
def getPrimitive(app: Apply, tpe: Type)(using Context): Int = {
def getPrimitive(app: Apply, tpe: Type): Int = {
given Context = ictx
val fun = app.fun.symbol
val defn = ctx.definitions
val code = app.fun match {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class JSPrimitives(ictx: Context) extends DottyPrimitives(ictx) {
override def getPrimitive(sym: Symbol): Int =
jsPrimitives.getOrElse(sym, super.getPrimitive(sym))

override def getPrimitive(app: Apply, tpe: Type)(using Context): Int =
jsPrimitives.getOrElse(app.fun.symbol, super.getPrimitive(app, tpe))
override def getPrimitive(app: Apply, tpe: Type): Int =
jsPrimitives.getOrElse(app.fun.symbol(using ictx), super.getPrimitive(app, tpe))

override def isPrimitive(sym: Symbol): Boolean =
jsPrimitives.contains(sym) || super.isPrimitive(sym)
Expand Down
Loading