mirror of https://github.com/sbt/sbt.git
ExtractAPI: avoid unnecessary duplication of defs with primitive types
If a method's type contains a non-primitive value class then it has two signatures: one before erasure and one after erasure. Before this commit, we checked if this was the case using `isAnyValSubtype`, but this is too crude since primitive value classes are also subtypes of `AnyVal` but do not change signature after erasure. This commit replaces `isAnyValSubtype` by `isDerivedValueClass` which excludes primitive value classes. In practice, for an empty class, this reduces the size of the output of `DefaultShowAPI` from 65 lines to 25 lines. Before: https://gist.github.com/smarter/cf1d6fe58efda88d6ee6#file-old-api After: https://gist.github.com/smarter/cf1d6fe58efda88d6ee6#file-new-api
This commit is contained in:
parent
0993c1c7cc
commit
726b5c8a30
|
|
@ -107,8 +107,8 @@ abstract class Compat {
|
|||
}
|
||||
lazy val AnyValClass = global.rootMirror.getClassIfDefined("scala.AnyVal")
|
||||
|
||||
def isAnyValSubtype(sym: Symbol): Boolean = sym.isNonBottomSubClass(AnyValClass)
|
||||
|
||||
def isDerivedValueClass(sym: Symbol): Boolean =
|
||||
sym.isNonBottomSubClass(AnyValClass) && !definitions.ScalaValueClasses.contains(sym)
|
||||
}
|
||||
|
||||
object MacroExpansionOf {
|
||||
|
|
|
|||
|
|
@ -205,14 +205,14 @@ class ExtractAPI[GlobalType <: CallbackGlobal](val global: GlobalType,
|
|||
|
||||
val hasValueClassAsParameter: Boolean = {
|
||||
import MirrorHelper._
|
||||
s.asMethod.paramss.flatten map (_.info) exists (t => isAnyValSubtype(t.typeSymbol))
|
||||
s.asMethod.paramss.flatten map (_.info) exists (t => isDerivedValueClass(t.typeSymbol))
|
||||
}
|
||||
|
||||
def hasValueClassAsReturnType(tpe: Type): Boolean = tpe match {
|
||||
case PolyType(_, base) => hasValueClassAsReturnType(base)
|
||||
case MethodType(_, resultType) => hasValueClassAsReturnType(resultType)
|
||||
case Nullary(resultType) => hasValueClassAsReturnType(resultType)
|
||||
case resultType => isAnyValSubtype(resultType.typeSymbol)
|
||||
case resultType => isDerivedValueClass(resultType.typeSymbol)
|
||||
}
|
||||
|
||||
val inspectPostErasure = hasValueClassAsParameter || hasValueClassAsReturnType(viewer(in).memberInfo(s))
|
||||
|
|
|
|||
Loading…
Reference in New Issue