Skip to content

Fix #8838: load Java enum members lazily to avoid cycles #9081

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 3 commits into from
May 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ object ClassfileConstants {
res = addFlag(res, nflags & JAVA_ACC_FINAL)
res = addFlag(res, nflags & JAVA_ACC_SYNTHETIC)
res = addFlag(res, nflags & JAVA_ACC_STATIC)
res = addFlag(res, nflags & JAVA_ACC_ENUM)
res = addFlag(res, nflags & JAVA_ACC_ABSTRACT)
res = addFlag(res, nflags & JAVA_ACC_INTERFACE)
res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ class ClassfileParser(
sym.markAbsent()
}

// eager load enum definitions for exhaustivity check of pattern match
if (isEnum) {
instanceScope.toList.map(_.ensureCompleted())
staticScope.toList.map(_.ensureCompleted())
}

result
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class SymUtils(val self: Symbol) extends AnyVal {
def children(implicit ctx: Context): List[Symbol] = {
if (self.isType)
self.setFlag(ChildrenQueried)

if (self.isAllOf(JavaEnumTrait))
self.linkedClass.info.decls.foreach(_.ensureCompleted())

self.annotations.collect {
case Annotation.Child(child) => child
}.reverse
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ object TypeTestsCasts {
maximizeType(P1, span, fromScala2x = false)

val res = P1 <:< P

debug.println(TypeComparer.explained(P1 <:< P))

debug.println("P1 : " + P1.show)
debug.println("P1 <:< P = " + res)

Expand Down
13 changes: 6 additions & 7 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
}

/** Decompose a type into subspaces -- assume the type can be decomposed */
def decompose(tp: Type): List[Space] = {
val children = tp.classSymbol.children

debug.println(s"candidates for ${tp.show} : [${children.map(_.show).mkString(", ")}]")

def decompose(tp: Type): List[Space] =
tp.dealias match {
case AndType(tp1, tp2) =>
intersect(Typ(tp1, false), Typ(tp2, false)) match {
Expand All @@ -607,8 +603,11 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
case tp if tp.isRef(defn.UnitClass) =>
Typ(ConstantType(Constant(())), true) :: Nil
case tp if tp.classSymbol.isAllOf(JavaEnumTrait) =>
children.map(sym => Typ(sym.termRef, true))
tp.classSymbol.children.map(sym => Typ(sym.termRef, true))
case tp =>
val children = tp.classSymbol.children
debug.println(s"candidates for ${tp.show} : [${children.map(_.show).mkString(", ")}]")

val parts = children.map { sym =>
val sym1 = if (sym.is(ModuleClass)) sym.sourceModule else sym
val refined = TypeOps.refineUsingParent(tp, sym1)
Expand All @@ -630,7 +629,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {

parts.map(Typ(_, true))
}
}


/** Abstract sealed types, or-types, Boolean and Java enums can be decomposed */
def canDecompose(tp: Type): Boolean = {
Expand Down