Skip to content

Commit

Permalink
Revert "Remove laziness in Structure type"
Browse files Browse the repository at this point in the history
This reverts commit 7ee45c7.
  • Loading branch information
eed3si9n committed Apr 15, 2017
1 parent f9055e3 commit ae0d474
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class ExtractAPI[GlobalType <: Global](
def linearizedAncestorTypes(info: Type): List[Type] = info.baseClasses.tail.map(info.baseType)

private def mkStructure(s: Symbol, bases: List[Type], declared: List[Symbol], inherited: List[Symbol]): xsbti.api.Structure = {
new xsbti.api.Structure(types(s, bases), processDefinitions(s, declared), lzy(processDefinitions(s, inherited)))
new xsbti.api.Structure(lzy(types(s, bases)), lzy(processDefinitions(s, declared)), lzy(processDefinitions(s, inherited)))
}
private def processDefinitions(in: Symbol, defs: List[Symbol]): Array[xsbti.api.ClassDefinition] =
sort(defs.toArray).flatMap((d: Symbol) => definition(in, d))
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler-interface/src/main/contraband/type.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
"target": "Java",
"type": "record",
"fields": [
{ "name": "parents", "type": "Type*" },
{ "name": "declared", "type": "ClassDefinition*" },
{ "name": "parents", "type": "lazy Type*" },
{ "name": "declared", "type": "lazy ClassDefinition*" },
{ "name": "inherited", "type": "lazy ClassDefinition*" }
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ object ClassToAPI {
if (!Modifier.isPrivate(c.getModifiers))
cmap.inherited ++= parentJavaTypes.collect { case parent: Class[_] => c -> parent }
val parentTypes = types(parentJavaTypes)
val instanceStructure = new api.Structure(parentTypes, all.declared.toArray, lzyS(all.inherited.toArray))
val staticStructure = new api.Structure(emptyTypeArray, all.staticDeclared.toArray, lzyS(all.staticInherited.toArray))
val instanceStructure = new api.Structure(lzyS(parentTypes), lzyS(all.declared.toArray), lzyS(all.inherited.toArray))
val staticStructure = new api.Structure(lzyEmptyTpeArray, lzyS(all.staticDeclared.toArray), lzyS(all.staticInherited.toArray))
(staticStructure, instanceStructure)
}

Expand All @@ -130,9 +130,8 @@ object ClassToAPI {
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 val lzyEmptyDefArray = lzyS(new Array[xsbti.api.ClassDefinition](0))

private def allSuperTypes(t: Type): Seq[Type] =
{
Expand Down Expand Up @@ -161,7 +160,7 @@ object ClassToAPI {
def parents(c: Class[_]): Seq[api.Type] = types(allSuperTypes(c))
def types(ts: Seq[Type]): Array[api.Type] = (ts filter (_ ne null) map reference).toArray
def upperBounds(ts: Array[Type]): api.Type =
new api.Structure(types(ts), emptyDefArray, lzyEmptyDefArray)
new api.Structure(lzy(types(ts)), lzyEmptyDefArray, lzyEmptyDefArray)

@deprecated("Use fieldToDef[4] instead", "0.13.9")
def fieldToDef(enclPkg: Option[String])(f: Field): api.FieldLike = {
Expand Down
8 changes: 4 additions & 4 deletions internal/zinc-apiinfo/src/main/scala/xsbt/api/APIUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ object APIUtil {
}

def minimizeStructure(s: Structure, isModule: Boolean): Structure =
new Structure(s.parents, filterDefinitions(s.declared, isModule), lzy(filterDefinitions(s.inherited, isModule)))
def filterDefinitions(ds: Array[ClassDefinition], isModule: Boolean): Array[ClassDefinition] =
if (isModule) ds filter Discovery.isMainMethod else Array()
new Structure(lzy(s.parents), filterDefinitions(s.declared, isModule), filterDefinitions(s.inherited, isModule))
def filterDefinitions(ds: Array[ClassDefinition], isModule: Boolean): Lazy[Array[ClassDefinition]] =
lzy(if (isModule) ds filter Discovery.isMainMethod else Array())

def isNonPrivate(d: Definition): Boolean = isNonPrivate(d.access)
/** Returns false if the `access` is `Private` and qualified, true otherwise.*/
Expand All @@ -76,7 +76,7 @@ object APIUtil {
case _ => true
}
private val emptyModifiers = new Modifiers(false, false, false, false, false, false, false, false)
private val emptyStructure = new Structure(Array.empty, Array.empty, lzy(Array.empty))
private val emptyStructure = new Structure(lzy(Array.empty), lzy(Array.empty), lzy(Array.empty))
def emptyClassLike(name: String, definitionType: DefinitionType): ClassLike =
new xsbti.api.ClassLike(name, new Public, emptyModifiers, Array.empty,
definitionType, lzy(emptyType), lzy(emptyStructure), Array.empty, Array.empty, true, Array.empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ class NameHashingSpecification extends UnitSpec {
val barMethod = new Def("bar", publicAccess, defaultModifiers, Array.empty, Array.empty, Array.empty, intTpe)
val parentB = simpleClass("Parent", barMethod)
val childA = {
val structure = new Structure(Array[Type](parentA.structure), emptyMembers, lzyEmptyMembers)
val structure = new Structure(lzy(Array[Type](parentA.structure)), emptyMembers, emptyMembers)
simpleClassLike("Child", structure)
}
val childB = {
val structure = new Structure(Array[Type](parentB.structure), emptyMembers, lzy(Array[ClassDefinition](barMethod)))
val structure = new Structure(lzy(Array[Type](parentB.structure)), emptyMembers, lzy(Array[ClassDefinition](barMethod)))
simpleClassLike("Child", structure)
}
val parentANameHashes = nameHashesForClass(parentA)
Expand Down Expand Up @@ -278,7 +278,7 @@ class NameHashingSpecification extends UnitSpec {
private def lzy[T](x: T): Lazy[T] = new Lazy[T] { def get: T = x }

private def simpleStructure(defs: ClassDefinition*) =
new Structure(Array.empty[Type], defs.toArray, lzyEmptyMembers)
new Structure(lzy(Array.empty[Type]), lzy(defs.toArray), emptyMembers)

private def simpleClass(name: String, defs: ClassDefinition*): ClassLike = {
val structure = simpleStructure(defs: _*)
Expand All @@ -302,7 +302,6 @@ class NameHashingSpecification extends UnitSpec {
private val publicAccess = new Public
private val privateAccess = new Private(new Unqualified)
private val defaultModifiers = new Modifiers(false, false, false, false, false, false, false, false)
private val emptyMembers = Array.empty[ClassDefinition]
private val lzyEmptyMembers = lzy(emptyMembers)
private val emptyMembers = lzy(Array.empty[ClassDefinition])

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object TestCaseGenerators {
} yield Stamps(zipMap(prod, prodStamps), zipMap(src, srcStamps), zipMap(bin, binStamps))
}

private[this] val emptyStructure = new Structure(Array(), Array(), lzy(Array()))
private[this] val emptyStructure = new Structure(lzy(Array()), lzy(Array()), lzy(Array()))

// 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 =
Expand Down

0 comments on commit ae0d474

Please sign in to comment.