@@ -378,7 +378,7 @@ object Semantic:
378378// ----- Checker State -----------------------------------
379379
380380 /** The state that threads through the interpreter */
381- type Contextual [T ] = (Context , Trace , Promoted , Cache .Data , Reporter ) ?=> T
381+ type Contextual [T ] = (Context , Trace , Promoted , Cache .Data , Reporter , TreeCache . CacheData ) ?=> T
382382
383383// ----- Error Handling -----------------------------------
384384
@@ -443,6 +443,29 @@ object Semantic:
443443
444444 inline def reporter (using r : Reporter ): Reporter = r
445445
446+ // ----- Cache for Trees -----------------------------
447+
448+ object TreeCache :
449+ class CacheData :
450+ private val emptyTrees = mutable.Set [ValOrDefDef ]()
451+
452+ extension (tree : ValOrDefDef )
453+ def getRhs (using Context ): Tree =
454+ def getTree : Tree =
455+ val errorCount = ctx.reporter.errorCount
456+ val rhs = tree.rhs
457+
458+ if (ctx.reporter.errorCount > errorCount)
459+ emptyTrees.add(tree)
460+ report.warning(" Ignoring analyses of " + tree.name + " due to error in reading TASTy." )
461+ EmptyTree
462+ else
463+ rhs
464+
465+ if (emptyTrees.contains(tree)) EmptyTree
466+ else getTree
467+ end TreeCache
468+
446469// ----- Operations on domains -----------------------------
447470 extension (a : Value )
448471 def join (b : Value ): Value =
@@ -562,7 +585,7 @@ object Semantic:
562585 case ref : Ref =>
563586 val target = if needResolve then resolve(ref.klass, field) else field
564587 if target.is(Flags .Lazy ) then
565- val rhs = target.defTree.asInstanceOf [ValDef ].rhs
588+ val rhs = target.defTree.asInstanceOf [ValDef ].getRhs
566589 eval(rhs, ref, target.owner.asClass, cacheResult = true )
567590 else if target.exists then
568591 val obj = ref.objekt
@@ -577,7 +600,7 @@ object Semantic:
577600 // return `Hot` here, errors are reported in checking `ThisRef`
578601 Hot
579602 else if target.hasSource then
580- val rhs = target.defTree.asInstanceOf [ValOrDefDef ].rhs
603+ val rhs = target.defTree.asInstanceOf [ValOrDefDef ].getRhs
581604 eval(rhs, ref, target.owner.asClass, cacheResult = true )
582605 else
583606 val error = CallUnknown (field)(trace)
@@ -701,7 +724,7 @@ object Semantic:
701724 else
702725 reporter.reportAll(tryReporter.errors)
703726 extendTrace(ddef) {
704- eval(ddef.rhs , ref, cls, cacheResult = true )
727+ eval(ddef.getRhs , ref, cls, cacheResult = true )
705728 }
706729 else if ref.canIgnoreMethodCall(target) then
707730 Hot
@@ -768,7 +791,7 @@ object Semantic:
768791 val tpl = cls.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
769792 extendTrace(cls.defTree) { init(tpl, ref, cls) }
770793 else
771- val initCall = ddef.rhs match
794+ val initCall = ddef.getRhs match
772795 case Block (call :: _, _) => call
773796 case call => call
774797 extendTrace(ddef) { eval(initCall, ref, cls) }
@@ -787,7 +810,7 @@ object Semantic:
787810 extendTrace(cls.defTree) { eval(tpl, ref, cls, cacheResult = true ) }
788811 ref
789812 else
790- extendTrace(ddef) { eval(ddef.rhs , ref, cls, cacheResult = true ) }
813+ extendTrace(ddef) { eval(ddef.getRhs , ref, cls, cacheResult = true ) }
791814 else if ref.canIgnoreMethodCall(ctor) then
792815 Hot
793816 else
@@ -897,8 +920,7 @@ object Semantic:
897920
898921 case Cold => Cold
899922
900- case ref : Ref => eval(vdef.rhs, ref, enclosingClass, cacheResult = sym.is(Flags .Lazy ))
901-
923+ case ref : Ref => eval(vdef.getRhs, ref, enclosingClass, cacheResult = sym.is(Flags .Lazy ))
902924 case _ =>
903925 report.error(" [Internal error] unexpected this value when accessing local variable, sym = " + sym.show + " , thisValue = " + thisValue2.show + Trace .show, Trace .position)
904926 Hot
@@ -1105,7 +1127,7 @@ object Semantic:
11051127 *
11061128 * The class to be checked must be an instantiable concrete class.
11071129 */
1108- private def checkClass (classSym : ClassSymbol )(using Cache .Data , Context ): Unit =
1130+ private def checkClass (classSym : ClassSymbol )(using Cache .Data , Context , TreeCache . CacheData ): Unit =
11091131 val thisRef = ThisRef (classSym)
11101132 val tpl = classSym.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
11111133
@@ -1140,6 +1162,7 @@ object Semantic:
11401162 */
11411163 def checkClasses (classes : List [ClassSymbol ])(using Context ): Unit =
11421164 given Cache .Data ()
1165+ given TreeCache .CacheData ()
11431166 for classSym <- classes if isConcreteClass(classSym) do
11441167 checkClass(classSym)
11451168
@@ -1298,7 +1321,7 @@ object Semantic:
12981321 }
12991322
13001323 case closureDef(ddef) =>
1301- Fun (ddef.rhs , thisV, klass)
1324+ Fun (ddef.getRhs , thisV, klass)
13021325
13031326 case PolyFun (body) =>
13041327 Fun (body, thisV, klass)
@@ -1353,7 +1376,7 @@ object Semantic:
13531376
13541377 case vdef : ValDef =>
13551378 // local val definition
1356- eval(vdef.rhs , thisV, klass)
1379+ eval(vdef.getRhs , thisV, klass)
13571380
13581381 case ddef : DefDef =>
13591382 // local method
@@ -1571,8 +1594,8 @@ object Semantic:
15711594
15721595 // class body
15731596 if thisV.isThisRef || ! thisV.asInstanceOf [Warm ].isPopulatingParams then tpl.body.foreach {
1574- case vdef : ValDef if ! vdef.symbol.is(Flags .Lazy ) && ! vdef.rhs .isEmpty =>
1575- val res = eval(vdef.rhs , thisV, klass)
1597+ case vdef : ValDef if ! vdef.symbol.is(Flags .Lazy ) && ! vdef.getRhs .isEmpty =>
1598+ val res = eval(vdef.getRhs , thisV, klass)
15761599 // TODO: Improve promotion to avoid handling enum initialization specially
15771600 //
15781601 // The failing case is tests/init/pos/i12544.scala due to promotion failure.
0 commit comments