From 726b5c8a30b2459727dede5061ddbbba803b9c52 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 23 Jan 2016 18:29:42 +0100 Subject: [PATCH] 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 --- compile/interface/src/main/scala/xsbt/Compat.scala | 4 ++-- compile/interface/src/main/scala/xsbt/ExtractAPI.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compile/interface/src/main/scala/xsbt/Compat.scala b/compile/interface/src/main/scala/xsbt/Compat.scala index 9f9fb247c..a4859275d 100644 --- a/compile/interface/src/main/scala/xsbt/Compat.scala +++ b/compile/interface/src/main/scala/xsbt/Compat.scala @@ -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 { diff --git a/compile/interface/src/main/scala/xsbt/ExtractAPI.scala b/compile/interface/src/main/scala/xsbt/ExtractAPI.scala index 7a0a78b2c..011479be6 100644 --- a/compile/interface/src/main/scala/xsbt/ExtractAPI.scala +++ b/compile/interface/src/main/scala/xsbt/ExtractAPI.scala @@ -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))