@@ -147,7 +147,7 @@ object Types {
147147 final def exists : Boolean = this .ne(NoType )
148148
149149 /** This type, if it exists, otherwise `that` type */
150- inline def orElse (inline that : => Type ): Type = if (exists) this else that
150+ inline def orElse (inline that : Type ): Type = if (exists) this else that
151151
152152 /** Is this type a value type? */
153153 final def isValueType : Boolean = this .isInstanceOf [ValueType ]
@@ -4672,12 +4672,11 @@ object Types {
46724672 // ----- Annotated and Import types -----------------------------------------------
46734673
46744674 /** An annotated type tpe @ annot */
4675- case class AnnotatedType (parent : Type , annot : Annotation ) extends UncachedProxyType with ValueType {
4676- // todo: cache them? but this makes only sense if annotations and trees are also cached.
4675+ abstract case class AnnotatedType (parent : Type , annot : Annotation ) extends CachedProxyType with ValueType {
46774676
46784677 override def underlying (using Context ): Type = parent
46794678
4680- def derivedAnnotatedType (parent : Type , annot : Annotation ): AnnotatedType =
4679+ def derivedAnnotatedType (parent : Type , annot : Annotation )( using Context ) : AnnotatedType =
46814680 if ((parent eq this .parent) && (annot eq this .annot)) this
46824681 else AnnotatedType (parent, annot)
46834682
@@ -4699,17 +4698,28 @@ object Types {
46994698
47004699 // equals comes from case class; no matching override is needed
47014700
4702- override def iso (that : Any , bs : BinderPairs ): Boolean = that match {
4703- case that : AnnotatedType => parent.equals(that.parent, bs) && (annot `eq` that.annot)
4701+ override def computeHash (bs : Binders ): Int =
4702+ doHash(bs, System .identityHashCode(annot), parent)
4703+ override def hashIsStable : Boolean =
4704+ parent.hashIsStable
4705+
4706+ override def eql (that : Type ): Boolean = that match
4707+ case that : AnnotatedType => (parent eq that.parent) && (annot eq that.annot)
47044708 case _ => false
4705- }
4706- }
47074709
4708- object AnnotatedType {
4709- def make ( underlying : Type , annots : List [ Annotation ]) : Type =
4710- annots.foldLeft(underlying)( AnnotatedType (_, _))
4710+ override def iso ( that : Any , bs : BinderPairs ) : Boolean = that match
4711+ case that : AnnotatedType => parent.equals(that.parent, bs) && (annot eq that.annot)
4712+ case _ => false
47114713 }
47124714
4715+ class CachedAnnotatedType (parent : Type , annot : Annotation ) extends AnnotatedType (parent, annot)
4716+
4717+ object AnnotatedType :
4718+ def make (underlying : Type , annots : List [Annotation ])(using Context ): Type =
4719+ annots.foldLeft(underlying)(apply(_, _))
4720+ def apply (parent : Type , annot : Annotation )(using Context ): AnnotatedType =
4721+ unique(CachedAnnotatedType (parent, annot))
4722+
47134723 // Special type objects and classes -----------------------------------------------------
47144724
47154725 /** The type of an erased array */
0 commit comments