@@ -353,6 +353,36 @@ object Inlines:
353353 override def end : Int = endId
354354 }
355355
356+ // Let's reconstruct necessary transform MegaPhases, without anything
357+ // that could cause problems here (like `CrossVersionChecks`).
358+ // The individiual lists here should line up with Compiler.scala, i.e
359+ // separate chunks there should also be kept separate here.
360+ // For now we create a single MegaPhase, since there does not seem to
361+ // be any important checks later (e.g. ForwardDepChecks could be applicable here,
362+ // but the equivalent is also not run in the scala 2's `ctx.typechecks`,
363+ // so let's leave it out for now).
364+ lazy val reconstructedTransformPhases =
365+ val transformPhases : List [List [(Class [? ], () => MiniPhase )]] = List (
366+ List (
367+ (classOf [InlineVals ], () => new InlineVals ),
368+ (classOf [ElimRepeated ], () => new ElimRepeated ),
369+ (classOf [RefChecks ], () => new RefChecks ),
370+ ),
371+ )
372+
373+ transformPhases.flatMap( (megaPhaseList : List [(Class [? ], () => MiniPhase )]) =>
374+ val (newMegaPhasePhases, phaseIds) =
375+ megaPhaseList.flatMap {
376+ case (filteredPhaseClass, miniphaseConstructor) =>
377+ ctx.base.phases
378+ .find(phase => filteredPhaseClass.isInstance(phase))
379+ .map(phase => (miniphaseConstructor(), phase.id))
380+ }
381+ .unzip
382+ if newMegaPhasePhases.isEmpty then None
383+ else Some (MegaPhaseWithCustomPhaseId (newMegaPhasePhases.toArray, phaseIds.head, phaseIds.last))
384+ )
385+
356386 ConstFold (underlyingCodeArg).tpe.widenTermRefExpr match {
357387 case ConstantType (Constant (code : String )) =>
358388 val unitName = " tasty-reflect"
@@ -364,36 +394,6 @@ object Inlines:
364394 ctx.fresh.setNewTyperState().setTyper(new Typer (ctx.nestingLevel + 1 )).setSource(source2)
365395
366396 inContext(newContext) {
367- // Let's reconstruct necessary transform MegaPhases, without anything
368- // that could cause problems here (like `CrossVersionChecks`).
369- // The individiual lists here should line up with Compiler.scala, i.e
370- // separate chunks there should also be kept separate here.
371- // For now we create a single MegaPhase, since there does not seem to
372- // be any important checks later (e.g. ForwardDepChecks could be applicable here,
373- // but the equivalent is also not run in the scala 2's `ctx.typechecks`,
374- // so let's leave it out for now).
375- val transformPhases : List [List [(Class [? ], () => MiniPhase )]] = List (
376- List (
377- (classOf [InlineVals ], () => new InlineVals ),
378- (classOf [ElimRepeated ], () => new ElimRepeated ),
379- (classOf [RefChecks ], () => new RefChecks ),
380- ),
381- )
382-
383- val mergedTransformPhases =
384- transformPhases.flatMap( (megaPhaseList : List [(Class [? ], () => MiniPhase )]) =>
385- val (newMegaPhasePhases, phaseIds) =
386- megaPhaseList
387- .flatMap { filteredPhase =>
388- ctx.base.phases.find(phase => filteredPhase._1.isInstance(phase)).map { a =>
389- (filteredPhase._2(), a.id)
390- }
391- }
392- .unzip
393- if newMegaPhasePhases.isEmpty then None
394- else Some (MegaPhaseWithCustomPhaseId (newMegaPhasePhases.toArray, phaseIds.head, phaseIds.last))
395- )
396-
397397 val tree2 = new Parser (source2).block()
398398 if ctx.reporter.allErrors.nonEmpty then
399399 ctx.reporter.allErrors.map((ErrorKind .Parser , _))
@@ -410,15 +410,14 @@ object Inlines:
410410 compilationUnit.untpdTree = tree2
411411 var units = List (compilationUnit)
412412 atPhase(setRootTree)(setRootTree.runOn(units).head.tpdTree)
413-
414413 ctx.base.inliningPhase match
415414 case inlining : Inlining if ctx.reporter.allErrors.isEmpty =>
416415 val tree6 = atPhase(inlining) { inlining.newTransformer.transform(tree5) }
417- if mergedTransformPhases .nonEmpty then
416+ if ctx.reporter.allErrors.isEmpty && reconstructedTransformPhases .nonEmpty then
418417 var transformTree = tree6
419- for ( phase <- mergedTransformPhases if ctx.reporter.allErrors.isEmpty) {
420- transformTree = atPhase(phase.end + 1 )(phase.transformUnit(transformTree))
421- }
418+ for phase <- reconstructedTransformPhases do
419+ if ctx.reporter.allErrors.isEmpty then
420+ transformTree = atPhase(phase.end + 1 )(phase.transformUnit(transformTree))
422421 case _ =>
423422 case _ =>
424423 ctx.reporter.allErrors.map((ErrorKind .Typer , _))
0 commit comments