Skip to content

Commit

Permalink
Revert "Remove laziness in ClassLike definition"
Browse files Browse the repository at this point in the history
This reverts commit d1b18bd.
  • Loading branch information
eed3si9n committed Apr 15, 2017
1 parent cf63590 commit f9055e3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,14 @@ class ExtractAPI[GlobalType <: Global](
val acc = getAccess(c)
val name = classNameAsSeenIn(in, c)
val tParams = typeParameters(in, sym) // look at class symbol
val selfType = this.selfType(in, sym)
def constructClass(structure: Structure): ClassLike = {
val selfType = lzy(this.selfType(in, sym))
def constructClass(structure: xsbti.api.Lazy[Structure]): ClassLike = {
new xsbti.api.ClassLike(name, acc, modifiers, anns,
defType, selfType, structure, emptyStringArray,
childrenOfSealedClass, topLevel, tParams) // use original symbol (which is a term symbol when `c.isModule`) for `name` and other non-classy stuff
}
val info = viewer(in).memberInfo(sym)
val structure = structureWithInherited(info, sym)
val structure = lzy(structureWithInherited(info, sym))
val classWithMembers = constructClass(structure)

allNonLocalClassesInSrc += classWithMembers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
"type": "record",
"fields": [
{ "name": "definitionType", "type": "DefinitionType" },
{ "name": "selfType", "type": "Type" },
{ "name": "structure", "type": "Structure" },
{ "name": "selfType", "type": "lazy Type" },
{ "name": "structure", "type": "lazy Structure" },
{ "name": "savedAnnotations", "type": "String*" },
{ "name": "childrenOfSealedClass", "type": "Type*" },
{ "name": "topLevel", "type": "boolean" },
{ "name": "topLevel", "type": "Boolean" },
{ "name": "typeParameters", "type": "TypeParameter*" }
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ object ClassToAPI {
val topLevel = c.getEnclosingClass == null
val name = classCanonicalName(c)
val tpe = if (Modifier.isInterface(c.getModifiers)) Trait else ClassDef
val (static, instance) = structure(c, enclPkg, cmap)
val cls = new api.ClassLike(name, acc, mods, annots, tpe, Empty, instance, emptyStringArray, children.toArray,
lazy val (static, instance) = structure(c, enclPkg, cmap)
val cls = new api.ClassLike(name, acc, mods, annots, tpe, lzyS(Empty), lzy(instance, cmap), emptyStringArray, children.toArray,
topLevel, typeParameters(typeParameterTypes(c)))
val clsDef = new api.ClassLikeDef(name, acc, mods, annots, typeParameters(typeParameterTypes(c)), tpe)
val stat = new api.ClassLike(name, acc, mods, annots, Module, Empty, static, emptyStringArray, emptyTypeArray,
val stat = new api.ClassLike(name, acc, mods, annots, Module, lzyS(Empty), lzy(static, cmap), emptyStringArray, emptyTypeArray,
topLevel, emptyTypeParameterArray)
val statDef = new api.ClassLikeDef(name, acc, mods, annots, emptyTypeParameterArray, Module)
val defs = cls :: stat :: Nil
Expand Down Expand Up @@ -120,12 +120,18 @@ object ClassToAPI {

@inline private[this] def lzyS[T <: AnyRef](t: T): xsbti.api.Lazy[T] = SafeLazyProxy.strict(t)
@inline final def lzy[T <: AnyRef](t: => T): xsbti.api.Lazy[T] = SafeLazyProxy(t)
private[this] def lzy[T <: AnyRef](t: => T, cmap: ClassMap): xsbti.api.Lazy[T] = {
val s = lzy(t)
cmap.lz += s
s
}

private val emptyStringArray = new Array[String](0)
private val emptyTypeArray = new Array[xsbti.api.Type](0)
private val emptyAnnotationArray = new Array[xsbti.api.Annotation](0)
private val emptyTypeParameterArray = new Array[xsbti.api.TypeParameter](0)
private val emptyDefArray = new Array[xsbti.api.ClassDefinition](0)
private val lzyEmptyTpeArray = lzyS(emptyTypeArray)
private val lzyEmptyDefArray = lzyS(emptyDefArray)

private def allSuperTypes(t: Type): Seq[Type] =
Expand Down
4 changes: 2 additions & 2 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object APIUtil {
val savedAnnotations = Discovery.defAnnotations(c.structure, (_: Any) => true).toArray[String]
val struct = minimizeStructure(c.structure, c.definitionType == DefinitionType.Module)
new ClassLike(c.name, c.access, c.modifiers, c.annotations,
c.definitionType, emptyType, struct, savedAnnotations, c.childrenOfSealedClass,
c.definitionType, lzy(emptyType), lzy(struct), savedAnnotations, c.childrenOfSealedClass,
c.topLevel, c.typeParameters)
}

Expand All @@ -79,7 +79,7 @@ object APIUtil {
private val emptyStructure = new Structure(Array.empty, Array.empty, lzy(Array.empty))
def emptyClassLike(name: String, definitionType: DefinitionType): ClassLike =
new xsbti.api.ClassLike(name, new Public, emptyModifiers, Array.empty,
definitionType, emptyType, emptyStructure, Array.empty, Array.empty, true, Array.empty)
definitionType, lzy(emptyType), lzy(emptyStructure), Array.empty, Array.empty, true, Array.empty)

private[this] def lzy[T <: AnyRef](t: T): Lazy[T] = SafeLazyProxy.strict(t)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ class NameHashingSpecification extends UnitSpec {

private def simpleClassLike(name: String, structure: Structure,
dt: DefinitionType = DefinitionType.ClassDef, topLevel: Boolean = true, access: Access = publicAccess): ClassLike = {
new ClassLike(name, access, defaultModifiers, Array.empty, dt, emptyType,
structure, Array.empty, Array.empty, topLevel, Array.empty)
new ClassLike(name, access, defaultModifiers, Array.empty, dt, lzy(emptyType),
lzy(structure), Array.empty, Array.empty, topLevel, Array.empty)
}

private val emptyType = new EmptyType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object TestCaseGenerators {
// We need "proper" definitions with specific class names, as groupBy use these to pick a representative top-level class when splitting.
private[this] def makeClassLike(name: String, definitionType: DefinitionType): ClassLike =
new ClassLike(name, new Public(), APIs.emptyModifiers, Array(),
definitionType, new EmptyType(), emptyStructure, Array(), Array(), true, Array())
definitionType, lzy(new EmptyType()), lzy(emptyStructure), Array(), Array(), true, Array())

private[this] def makeCompanions(name: String): Companions =
new Companions(makeClassLike(name, DefinitionType.ClassDef), makeClassLike(name, DefinitionType.Module))
Expand Down

0 comments on commit f9055e3

Please sign in to comment.