@@ -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,26 @@ 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 = doHash(bs, annot, parent)
4702
+ override def hashIsStable : Boolean = parent.hashIsStable
4703
+
4704
+ override def eql (that : Type ): Boolean = that match
4705
+ case that : AnnotatedType => (parent eq that.parent) && (annot eq that.annot)
4704
4706
case _ => false
4705
- }
4706
- }
4707
4707
4708
- object AnnotatedType {
4709
- def make ( underlying : Type , annots : List [ Annotation ]) : Type =
4710
- annots.foldLeft(underlying)( AnnotatedType (_, _))
4708
+ override def iso ( that : Any , bs : BinderPairs ) : Boolean = that match
4709
+ case that : AnnotatedType => parent.equals(that.parent, bs) && (annot eq that.annot)
4710
+ case _ => false
4711
4711
}
4712
4712
4713
+ class CachedAnnotatedType (parent : Type , annot : Annotation ) extends AnnotatedType (parent, annot)
4714
+
4715
+ object AnnotatedType :
4716
+ def make (underlying : Type , annots : List [Annotation ])(using Context ): Type =
4717
+ annots.foldLeft(underlying)(apply(_, _))
4718
+ def apply (parent : Type , annot : Annotation )(using Context ): AnnotatedType =
4719
+ unique(CachedAnnotatedType (parent, annot))
4720
+
4713
4721
// Special type objects and classes -----------------------------------------------------
4714
4722
4715
4723
/** The type of an erased array */
0 commit comments