@@ -147,7 +147,7 @@ object Types {
147
147
final def exists : Boolean = this .ne(NoType )
148
148
149
149
/** 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
151
151
152
152
/** Is this type a value type? */
153
153
final def isValueType : Boolean = this .isInstanceOf [ValueType ]
@@ -4672,12 +4672,11 @@ object Types {
4672
4672
// ----- Annotated and Import types -----------------------------------------------
4673
4673
4674
4674
/** 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 {
4677
4676
4678
4677
override def underlying (using Context ): Type = parent
4679
4678
4680
- def derivedAnnotatedType (parent : Type , annot : Annotation ): AnnotatedType =
4679
+ def derivedAnnotatedType (parent : Type , annot : Annotation )( using Context ) : AnnotatedType =
4681
4680
if ((parent eq this .parent) && (annot eq this .annot)) this
4682
4681
else AnnotatedType (parent, annot)
4683
4682
@@ -4699,17 +4698,28 @@ object Types {
4699
4698
4700
4699
// equals comes from case class; no matching override is needed
4701
4700
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)
4704
4708
case _ => false
4705
- }
4706
- }
4707
4709
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
4711
4713
}
4712
4714
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
+
4713
4723
// Special type objects and classes -----------------------------------------------------
4714
4724
4715
4725
/** The type of an erased array */
0 commit comments