diff options
author | Paul Phillips <paulp@improving.org> | 2012-12-03 11:53:17 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-12-17 17:47:59 -0800 |
commit | 5f1e18b1cd8f76f40bb01d257ae3b81cb70e3e07 (patch) | |
tree | b2e850946257461fe20941b078da6be3f42273be /src | |
parent | e14917528e1c080a7f10785e21de36f3a7769718 (diff) | |
download | scala-5f1e18b1cd8f76f40bb01d257ae3b81cb70e3e07.tar.gz scala-5f1e18b1cd8f76f40bb01d257ae3b81cb70e3e07.tar.bz2 scala-5f1e18b1cd8f76f40bb01d257ae3b81cb70e3e07.zip |
Optimization in SpecializeTypes.
Avoid time traveling to find type parameters which will
never be there.
Diffstat (limited to 'src')
3 files changed, 27 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala index 4e4c1b98ac..e3239313de 100644 --- a/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala +++ b/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala @@ -403,11 +403,16 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { case _ => false }) def specializedTypeVars(tpes: List[Type]): immutable.Set[Symbol] = { - val buf = Set.newBuilder[Symbol] - tpes foreach (tp => buf ++= specializedTypeVars(tp)) - buf.result + if (tpes.isEmpty) immutable.Set.empty else { + val buf = Set.newBuilder[Symbol] + tpes foreach (tp => buf ++= specializedTypeVars(tp)) + buf.result + } } - def specializedTypeVars(sym: Symbol): immutable.Set[Symbol] = enteringTyper(specializedTypeVars(sym.info)) + def specializedTypeVars(sym: Symbol): immutable.Set[Symbol] = ( + if (definitions.neverHasTypeParameters(sym)) immutable.Set.empty + else enteringTyper(specializedTypeVars(sym.info)) + ) /** Return the set of @specialized type variables mentioned by the given type. * It only counts type variables that appear: @@ -436,7 +441,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers { case AnnotatedType(_, tp, _) => specializedTypeVars(tp) case TypeBounds(lo, hi) => specializedTypeVars(lo :: hi :: Nil) case RefinedType(parents, _) => parents flatMap specializedTypeVars toSet - case _ => Set() + case _ => immutable.Set.empty } /** Returns the type parameter in the specialized class `sClass` that corresponds to type parameter diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a1c1b53cce..703c12038f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2716,13 +2716,8 @@ trait Typers extends Modes with Adaptations with Tags { val att = templ.attachments.get[CompoundTypeTreeOriginalAttachment].getOrElse(CompoundTypeTreeOriginalAttachment(Nil, Nil)) templ.removeAttachment[CompoundTypeTreeOriginalAttachment] templ updateAttachment att.copy(stats = stats1) - for (stat <- stats1 if stat.isDef) { - val member = stat.symbol - if (!(context.owner.ancestors forall - (bc => member.matchingSymbol(bc, context.owner.thisType) == NoSymbol))) { - member setFlag OVERRIDE - } - } + for (stat <- stats1 if stat.isDef && stat.symbol.isOverridingSymbol) + stat.symbol setFlag OVERRIDE } } diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala index 8c048ed7f8..d165f66004 100644 --- a/src/reflect/scala/reflect/internal/Definitions.scala +++ b/src/reflect/scala/reflect/internal/Definitions.scala @@ -686,6 +686,21 @@ trait Definitions extends api.StandardDefinitions { def ClassType(arg: Type) = if (phase.erasedTypes) ClassClass.tpe else appliedType(ClassClass, arg) + /** Can we tell by inspecting the symbol that it will never + * at any phase have type parameters? + */ + def neverHasTypeParameters(sym: Symbol) = sym match { + case _: RefinementClassSymbol => true + case _: ModuleClassSymbol => true + case _: ImplClassSymbol => true + case _ => + ( + sym.isPrimitiveValueClass + || sym.isAnonymousClass + || sym.initialize.isMonomorphicType + ) + } + def EnumType(sym: Symbol) = // given (in java): "class A { enum E { VAL1 } }" // - sym: the symbol of the actual enumeration value (VAL1) |