From 84c01ff493b81c0097d1707f64622ade028e53aa Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 20 Feb 2014 09:50:07 +0100 Subject: Reverted: Avoid using TypeBounds in alias refinements. The idea is to use the alias itself. This cuts down on # of typebounds created and makes operations on refined infos and applied types more direct. (reverted from commit 81f31f9b71bc4466d3f04f5ce28ef94051688ecd) --- src/dotty/tools/dotc/core/TypeApplications.scala | 34 +++++++----------------- 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'src/dotty/tools/dotc/core/TypeApplications.scala') diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 7ecabe6f5..9f742fcc2 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -92,7 +92,7 @@ class TypeApplications(val self: Type) extends AnyVal { println(s"precomplete decls = ${self.typeSymbol.decls.toList.map(_.denot).mkString("\n ")}") } val tparam = tparams.head - val tp1 = tp.paramRefinement(tparam, arg) + val tp1 = RefinedType(tp, tparam.name, arg.toBounds(tparam)) recur(tp1, tparams.tail, args1) case nil => tp } @@ -122,20 +122,17 @@ class TypeApplications(val self: Type) extends AnyVal { final def appliedTo(arg: Type)(implicit ctx: Context): Type = appliedTo(arg :: Nil) final def appliedTo(arg1: Type, arg2: Type)(implicit ctx: Context): Type = appliedTo(arg1 :: arg2 :: Nil) - /** Add a refinement to this type, which reflects `arg` being used as an argument for - * type parameter `tparam`. + /** Turn this type, which is used as an argument for + * type parameter `tparam`, into a TypeBounds RHS */ - final def paramRefinement(tparam: Symbol, arg: Type)(implicit ctx: Context): RefinedType = arg match { - case arg: TypeBounds => // this can happen for wildcard args - RefinedType(self, tparam.name, arg) + final def toBounds(tparam: Symbol)(implicit ctx: Context): TypeBounds = self match { + case self: TypeBounds => // this can happen for wildcard args + self case _ => val v = tparam.variance - if (v > 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) - RefinedType(self, tparam.name, TypeBounds.upper(arg)) - else if (v < 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) - RefinedType(self, tparam.name, TypeBounds.lower(arg)) - else - RefinedType.compact(self, tparam.name, arg, v) + if (v > 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.upper(self) + else if (v < 0 && !(tparam is Local) && !(tparam is ExpandedTypeParam)) TypeBounds.lower(self) + else TypeAlias(self, v) } /** The type arguments of the base type instance wrt `base` of this type */ @@ -174,7 +171,7 @@ class TypeApplications(val self: Type) extends AnyVal { if (tparams == null) tparams = tycon.typeParams if (buf.size < tparams.length) { val tparam = tparams(buf.size) - if (name == tparam.name) buf += tp.argTypeOfRefinement(tparam) + if (name == tparam.name) buf += tp.refinedInfo.argType(tparam) else null } else null } @@ -213,17 +210,6 @@ class TypeApplications(val self: Type) extends AnyVal { NoType } - /** If the refinement is the image of a type argument to type parameter `tparam`, - * recover the type argument, otherwise NoType. - */ - final def argTypeOfRefinement(tparam: Symbol)(implicit ctx: Context): Type = self match { - case self: RefinedType => - if (self.isAliasRefinement) self.compactInfo - else self.refinedInfo.argType(tparam) - case _ => - NoType - } - /** The element type of a sequence or array */ def elemType(implicit ctx: Context): Type = firstBaseTypeArg(defn.SeqClass) orElse firstBaseTypeArg(defn.ArrayClass) -- cgit v1.2.3