diff --git a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala index 4a7cad85de..f0f3657c95 100644 --- a/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala +++ b/internal/compiler-bridge/src/main/scala/xsbt/ExtractAPI.scala @@ -174,11 +174,6 @@ class ExtractAPI[GlobalType <: Global]( if (sym == NoSymbol || sym.isRoot || sym.isEmptyPackageClass || sym.isRootPackage) postfix else pathComponents(sym.owner, new xsbti.api.Id(simpleName(sym)) :: postfix) } - private def simpleType(in: Symbol, t: Type): SimpleType = - processType(in, t) match { - case s: SimpleType => s - case x => log("Not a simple type:\n\tType: " + t + " (" + t.getClass + ")\n\tTransformed: " + x.getClass); Constants.emptyType - } private def types(in: Symbol, t: List[Type]): Array[xsbti.api.Type] = t.toArray[Type].map(processType(in, _)) private def projectionType(in: Symbol, pre: Type, sym: Symbol) = { @@ -192,7 +187,7 @@ class ExtractAPI[GlobalType <: Global]( reference(sym) } } else if (sym.isRoot || sym.isRootPackage) Constants.emptyType - else new xsbti.api.Projection(simpleType(in, pre), simpleName(sym)) + else new xsbti.api.Projection(processType(in, pre), simpleName(sym)) } private def reference(sym: Symbol): xsbti.api.ParameterRef = new xsbti.api.ParameterRef(tparamID(sym)) diff --git a/internal/compiler-interface/src/main/contraband/type.json b/internal/compiler-interface/src/main/contraband/type.json index 2d1e5a34e7..8cb150abf0 100644 --- a/internal/compiler-interface/src/main/contraband/type.json +++ b/internal/compiler-interface/src/main/contraband/type.json @@ -8,51 +8,42 @@ "types": [ { - "name": "SimpleType", + "name": "Projection", "namespace": "xsbti.api", "target": "Java", - "type": "interface", - - "types": [ - { - "name": "Projection", - "namespace": "xsbti.api", - "target": "Java", - "type": "record", - "fields": [ - { "name": "prefix", "type": "SimpleType" }, - { "name": "id", "type": "String" } - ] - }, - { - "name": "ParameterRef", - "namespace": "xsbti.api", - "target": "Java", - "type": "record", - "fields": [ - { "name": "id", "type": "String" } - ] - }, - { - "name": "Singleton", - "namespace": "xsbti.api", - "target": "Java", - "type": "record", - "fields": [ - { "name": "path", "type": "Path" } - ] - }, - { "name": "EmptyType", "namespace": "xsbti.api", "target": "Java", "type": "record" }, - { - "name": "Parameterized", - "namespace": "xsbti.api", - "target": "Java", - "type": "record", - "fields": [ - { "name": "baseType", "type": "SimpleType" }, - { "name": "typeArguments", "type": "Type*" } - ] - } + "type": "record", + "fields": [ + { "name": "prefix", "type": "Type" }, + { "name": "id", "type": "String" } + ] + }, + { + "name": "ParameterRef", + "namespace": "xsbti.api", + "target": "Java", + "type": "record", + "fields": [ + { "name": "id", "type": "String" } + ] + }, + { + "name": "Singleton", + "namespace": "xsbti.api", + "target": "Java", + "type": "record", + "fields": [ + { "name": "path", "type": "Path" } + ] + }, + { "name": "EmptyType", "namespace": "xsbti.api", "target": "Java", "type": "record" }, + { + "name": "Parameterized", + "namespace": "xsbti.api", + "target": "Java", + "type": "record", + "fields": [ + { "name": "baseType", "type": "Type" }, + { "name": "typeArguments", "type": "Type*" } ] }, { diff --git a/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala b/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala index d7255d30f0..4154b48be2 100644 --- a/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala +++ b/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala @@ -130,7 +130,6 @@ 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 emptySimpleTypeArray = new Array[xsbti.api.SimpleType](0) private val lzyEmptyTpeArray = lzyS(emptyTypeArray) private val lzyEmptyDefArray = lzyS(new Array[xsbti.api.ClassDefinition](0)) @@ -239,7 +238,7 @@ object ClassToAPI { def parameter(annots: Array[Annotation], parameter: Type, varArgs: Boolean): api.MethodParameter = new api.MethodParameter("", annotated(reference(parameter), annots), false, if (varArgs) api.ParameterModifier.Repeated else api.ParameterModifier.Plain) - def annotated(t: api.SimpleType, annots: Array[Annotation]): api.Type = ( + def annotated(t: api.Type, annots: Array[Annotation]): api.Type = ( if (annots.length == 0) t else new api.Annotated(t, annotations(annots)) ) @@ -306,7 +305,7 @@ object ClassToAPI { * * We need this logic to trigger recompilation due to changes to pattern exhaustivity checking results. */ - private def childrenOfSealedClass(c: Class[_]): Seq[api.SimpleType] = if (!c.isEnum) emptySimpleTypeArray else { + private def childrenOfSealedClass(c: Class[_]): Seq[api.Type] = if (!c.isEnum) emptyTypeArray else { // Calling getCanonicalName() on classes from enum constants yields same string as enumClazz.getCanonicalName // Moreover old behaviour create new instance of enum - what may fail (e.g. in static block ) Array(reference(c)) @@ -316,14 +315,14 @@ object ClassToAPI { def javaAnnotation(s: String): api.AnnotationArgument = new api.AnnotationArgument("toString", s) - def array(tpe: api.Type): api.SimpleType = new api.Parameterized(ArrayRef, Array(tpe)) - def reference(c: Class[_]): api.SimpleType = + def array(tpe: api.Type): api.Type = new api.Parameterized(ArrayRef, Array(tpe)) + def reference(c: Class[_]): api.Type = if (c.isArray) array(reference(c.getComponentType)) else if (c.isPrimitive) primitive(c.getName) else reference(classCanonicalName(c)) // does not handle primitives - def reference(s: String): api.SimpleType = + def reference(s: String): api.Type = { val (pkg, cls) = packageAndName(s) pkg match { @@ -340,7 +339,7 @@ object ClassToAPI { val base = reference(t.getRawType) new api.Parameterized(base, args) } - def reference(t: Type): api.SimpleType = + def reference(t: Type): api.Type = t match { case _: WildcardType => reference("_") case tv: TypeVariable[_] => new api.ParameterRef(typeVariable(tv)) @@ -381,7 +380,7 @@ object ClassToAPI { private[this] def PrimitiveNames = Seq("boolean", "byte", "char", "short", "int", "long", "float", "double") private[this] def PrimitiveMap = PrimitiveNames.map(j => (j, j.capitalize)) :+ ("void" -> "Unit") private[this] val PrimitiveRefs = PrimitiveMap.map { case (n, sn) => (n, reference("scala." + sn)) }.toMap - def primitive(name: String): api.SimpleType = PrimitiveRefs(name) + def primitive(name: String): api.Type = PrimitiveRefs(name) // Workarounds for https://github.com/sbt/sbt/issues/1035 // these catch the GenericSignatureFormatError and return the erased type diff --git a/internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala b/internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala index 3adad64f5a..61104fbde0 100644 --- a/internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala +++ b/internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala @@ -258,14 +258,20 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) { def sameType(a: Type, b: Type): Boolean = samePending(a, b)(sameTypeDirect) def sameTypeDirect(a: Type, b: Type): Boolean = - (a, b) match { - case (sa: SimpleType, sb: SimpleType) => debug(sameSimpleTypeDirect(sa, sb), "Different simple types: " + DefaultShowAPI(sa) + " and " + DefaultShowAPI(sb)) - case (ca: Constant, cb: Constant) => debug(sameConstantType(ca, cb), "Different constant types: " + DefaultShowAPI(ca) + " and " + DefaultShowAPI(cb)) - case (aa: Annotated, ab: Annotated) => debug(sameAnnotatedType(aa, ab), "Different annotated types") - case (sa: Structure, sb: Structure) => debug(sameStructureDirect(sa, sb), "Different structure type") - case (ea: Existential, eb: Existential) => debug(sameExistentialType(ea, eb), "Different existential type") - case (pa: Polymorphic, pb: Polymorphic) => debug(samePolymorphicType(pa, pb), "Different polymorphic type") - case _ => differentCategory("type", a, b) + { + (a, b) match { + case (pa: Projection, pb: Projection) => debug(sameProjection(pa, pb), "Different projection") + case (pa: ParameterRef, pb: ParameterRef) => debug(sameParameterRef(pa, pb), "Different parameter ref") + case (sa: Singleton, sb: Singleton) => debug(sameSingleton(sa, sb), "Different singleton") + case (_: EmptyType, _: EmptyType) => true + case (pa: Parameterized, pb: Parameterized) => debug(sameParameterized(pa, pb), "Different parameterized") + case (ca: Constant, cb: Constant) => debug(sameConstantType(ca, cb), "Different constant types: " + DefaultShowAPI(ca) + " and " + DefaultShowAPI(cb)) + case (aa: Annotated, ab: Annotated) => debug(sameAnnotatedType(aa, ab), "Different annotated types") + case (sa: Structure, sb: Structure) => debug(sameStructureDirect(sa, sb), "Different structure type") + case (ea: Existential, eb: Existential) => debug(sameExistentialType(ea, eb), "Different existential type") + case (pa: Polymorphic, pb: Polymorphic) => debug(samePolymorphicType(pa, pb), "Different polymorphic type") + case _ => differentCategory("type", a, b) + } } def sameConstantType(ca: Constant, cb: Constant): Boolean = @@ -296,28 +302,17 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) { def sameMembers(a: Seq[Definition], b: Seq[Definition]): Boolean = sameDefinitions(a, b, topLevel = false) - def sameSimpleType(a: SimpleType, b: SimpleType): Boolean = - samePending(a, b)(sameSimpleTypeDirect) - def sameSimpleTypeDirect(a: SimpleType, b: SimpleType): Boolean = - (a, b) match { - case (pa: Projection, pb: Projection) => debug(sameProjection(pa, pb), "Different projection") - case (pa: ParameterRef, pb: ParameterRef) => debug(sameParameterRef(pa, pb), "Different parameter ref") - case (sa: Singleton, sb: Singleton) => debug(sameSingleton(sa, sb), "Different singleton") - case (_: EmptyType, _: EmptyType) => true - case (pa: Parameterized, pb: Parameterized) => debug(sameParameterized(pa, pb), "Different parameterized") - case _ => differentCategory("simple type", a, b) - } def differentCategory(label: String, a: AnyRef, b: AnyRef): Boolean = debug(flag = false, "Different category of " + label + " (" + a.getClass.getName + " and " + b.getClass.getName + ") for (" + a + " and " + b + ")") def sameParameterized(a: Parameterized, b: Parameterized): Boolean = - sameSimpleType(a.baseType, b.baseType) && + sameType(a.baseType, b.baseType) && sameSeq(a.typeArguments, b.typeArguments)(sameType) def sameParameterRef(a: ParameterRef, b: ParameterRef): Boolean = sameTags(a.id, b.id) def sameSingleton(a: Singleton, b: Singleton): Boolean = samePath(a.path, b.path) def sameProjection(a: Projection, b: Projection): Boolean = - sameSimpleType(a.prefix, b.prefix) && + sameType(a.prefix, b.prefix) && (a.id == b.id) def samePath(a: Path, b: Path): Boolean =