From ce74f86d9b1e4e65daec202ca5a0015de9b4e32f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 13 Aug 2024 17:58:15 +0200 Subject: [PATCH] Fixes after rebase --- .../java/org/enso/compiler/dump/IRDumper.java | 12 +++---- .../pass/analyse/FramePointerAnalysis.scala | 21 ++++++------ .../analyse/FramePointerAnalysisTest.scala | 33 +++++++++++-------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/engine/runtime-compiler/src/main/java/org/enso/compiler/dump/IRDumper.java b/engine/runtime-compiler/src/main/java/org/enso/compiler/dump/IRDumper.java index 092b1fc77b9f..93d3077ddb2e 100644 --- a/engine/runtime-compiler/src/main/java/org/enso/compiler/dump/IRDumper.java +++ b/engine/runtime-compiler/src/main/java/org/enso/compiler/dump/IRDumper.java @@ -33,10 +33,8 @@ import org.enso.compiler.data.BindingsMap.ResolvedPolyglotField; import org.enso.compiler.data.BindingsMap.ResolvedPolyglotSymbol; import org.enso.compiler.data.BindingsMap.ResolvedType; -import org.enso.compiler.pass.analyse.alias.Graph; -import org.enso.compiler.pass.analyse.alias.Info; -import org.enso.compiler.pass.analyse.alias.Info$Scope$Child; -import org.enso.compiler.pass.analyse.alias.Info$Scope$Root; +import org.enso.compiler.pass.analyse.alias.AliasMetadata; +import org.enso.compiler.pass.analyse.alias.graph.Graph; import org.enso.compiler.pass.resolve.FullyQualifiedNames.FQNResolution; import org.enso.compiler.pass.resolve.FullyQualifiedNames.ResolvedLibrary; import org.enso.compiler.pass.resolve.FullyQualifiedNames.ResolvedModule; @@ -613,18 +611,18 @@ private void createPassDataGraph(IR ir) { addNode(bmNode); createEdge(ir, bindingsMap, "BindingsMap"); } - case Info.Occurrence occurence -> { + case AliasMetadata.Occurrence occurence -> { bldr.addLabelLine("occurenceId: " + occurence.id()); addNode(bldr.build()); createEdge(ir, occurence, "Alias.Info.Occurence"); } - case Info$Scope$Root rootScope -> { + case AliasMetadata.RootScope rootScope -> { addAliasGraphScopeLabels(bldr, rootScope.graph().rootScope()); var aliasNode = bldr.build(); addNode(aliasNode); createEdge(ir, rootScope, "Alias.Info.Scope.Root"); } - case Info$Scope$Child childScope -> { + case AliasMetadata.ChildScope childScope -> { addAliasGraphScopeLabels(bldr, childScope.scope()); var aliasNode = bldr.build(); addNode(aliasNode); diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala index cdd72ede6fe4..f5f4f12a56b5 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala @@ -24,7 +24,8 @@ import org.enso.compiler.core.ir.module.scope.Definition import org.enso.compiler.core.ir.module.scope.definition.Method import org.enso.compiler.pass.IRPass import org.enso.compiler.pass.IRPass.IRMetadata -import org.enso.compiler.pass.analyse.alias.{Graph, Info} +import org.enso.compiler.pass.analyse.alias.AliasMetadata +import org.enso.compiler.pass.analyse.alias.graph.{Graph, GraphOccurrence} /** This pass attaches [[FramePointer]] as metadata to all the IR elements that already * have [[org.enso.compiler.pass.analyse.alias.Info.Occurrence]] attached. @@ -233,11 +234,11 @@ case object FramePointerAnalysis extends IRPass { graph: Graph ): Unit = { getAliasAnalysisMeta(ir) match { - case Some(Info.Occurrence(_, id)) => + case Some(AliasMetadata.Occurrence(_, id)) => graph.scopeFor(id) match { case Some(scope) => graph.getOccurrence(id) match { - case Some(use: Graph.Occurrence.Use) => + case Some(use: GraphOccurrence.Use) => // Use is allowed to read a variable from some parent scope graph.defLinkFor(use.id) match { case Some(defLink) => @@ -245,7 +246,7 @@ case object FramePointerAnalysis extends IRPass { val defOcc = graph .getOccurrence(defId) .get - .asInstanceOf[Graph.Occurrence.Def] + .asInstanceOf[GraphOccurrence.Def] val defScope = graph.scopeFor(defId).get val parentLevel = getScopeDistance(defScope, scope) val frameSlotIdx = @@ -258,7 +259,7 @@ case object FramePointerAnalysis extends IRPass { // We will not attach any metadata in this case. () } - case Some(defn: Graph.Occurrence.Def) => + case Some(defn: GraphOccurrence.Def) => // The definition cannot write to parent's frame slots. val parentLevel = 0 val frameSlotIdx = getFrameSlotIdxInScope(graph, scope, defn) @@ -285,7 +286,7 @@ case object FramePointerAnalysis extends IRPass { private def getFrameSlotIdxInScope( graph: Graph, scope: Graph.Scope, - defOcc: Graph.Occurrence.Def + defOcc: GraphOccurrence.Def ): Int = { assert( graph.scopeFor(defOcc.id).contains(scope), @@ -329,7 +330,7 @@ case object FramePointerAnalysis extends IRPass { ir: IR ): Option[AliasAnalysis.Metadata] = { ir.passData.get(AliasAnalysis) match { - case Some(aliasInfo: Info) => + case Some(aliasInfo: AliasMetadata) => Some(aliasInfo) case _ => None } @@ -337,10 +338,10 @@ case object FramePointerAnalysis extends IRPass { private def getAliasRootScope( ir: IR - ): Option[Info.Scope.Root] = { + ): Option[AliasMetadata.RootScope] = { ir.passData().get(AliasAnalysis) match { - case Some(root: Info.Scope.Root) => Some(root) - case _ => None + case Some(root: AliasMetadata.RootScope) => Some(root) + case _ => None } } diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/FramePointerAnalysisTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/FramePointerAnalysisTest.scala index 2060fd6c0d67..d0aa7e38b030 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/FramePointerAnalysisTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/FramePointerAnalysisTest.scala @@ -11,9 +11,14 @@ import org.enso.compiler.core.ir.{ Name } import org.enso.compiler.core.Implicits.AsMetadata -import org.enso.compiler.pass.analyse.alias.{Graph, Info} +import org.enso.compiler.pass.analyse.alias.graph.{Graph, GraphOccurrence} +import org.enso.compiler.pass.analyse.alias.AliasMetadata import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager} -import org.enso.compiler.pass.analyse.{AliasAnalysis, FramePointerAnalysis} +import org.enso.compiler.pass.analyse.{ + alias, + AliasAnalysis, + FramePointerAnalysis +} import org.enso.compiler.test.CompilerTest import scala.reflect.ClassTag @@ -96,16 +101,16 @@ class FramePointerAnalysisTest extends CompilerTest { |""".stripMargin.preprocessModule.analyse val aliasGraph = ir.bindings.head .unsafeGetMetadata(AliasAnalysis, "should exist") - .asInstanceOf[Info.Scope.Root] + .asInstanceOf[AliasMetadata.RootScope] .graph val xDefIr = findAssociatedIr( - aliasGraph.symbolToIds[Graph.Occurrence.Def]("x").head, + aliasGraph.symbolToIds[GraphOccurrence.Def]("x").head, ir ) expectFramePointer(xDefIr, new FramePointer(0, 1)) val xUseIr = findAssociatedIr( - aliasGraph.symbolToIds[Graph.Occurrence.Use]("x").head, + aliasGraph.symbolToIds[GraphOccurrence.Use]("x").head, ir ) withClue( @@ -116,7 +121,7 @@ class FramePointerAnalysisTest extends CompilerTest { } val plusUseIr = findAssociatedIr( - aliasGraph.symbolToIds[Graph.Occurrence.Use]("+").head, + aliasGraph.symbolToIds[GraphOccurrence.Use]("+").head, ir ) withClue( @@ -141,29 +146,29 @@ class FramePointerAnalysisTest extends CompilerTest { |""".stripMargin.preprocessModule.analyse val mainScope = ir.bindings.head .unsafeGetMetadata(AliasAnalysis, "should exist") - .asInstanceOf[Info.Scope.Root] + .asInstanceOf[AliasMetadata.RootScope] val allFps = collectAllFramePointers(ir) allFps.size shouldBe 4 val xDefIr = findAssociatedIr( - mainScope.graph.symbolToIds[Graph.Occurrence.Def]("x").head, + mainScope.graph.symbolToIds[GraphOccurrence.Def]("x").head, ir ) expectFramePointer(xDefIr, new FramePointer(0, 1)) val nestedDefIr = findAssociatedIr( - mainScope.graph.symbolToIds[Graph.Occurrence.Def]("nested").head, + mainScope.graph.symbolToIds[GraphOccurrence.Def]("nested").head, ir ) expectFramePointer(nestedDefIr, new FramePointer(0, 2)) val xUseIr = findAssociatedIr( - mainScope.graph.symbolToIds[Graph.Occurrence.Use]("x").head, + mainScope.graph.symbolToIds[GraphOccurrence.Use]("x").head, ir ) expectFramePointer(xUseIr, new FramePointer(2, 1)) val nestedUseIr = findAssociatedIr( - mainScope.graph.symbolToIds[Graph.Occurrence.Use]("nested").head, + mainScope.graph.symbolToIds[GraphOccurrence.Use]("nested").head, ir ) expectFramePointer(nestedUseIr, new FramePointer(0, 2)) @@ -457,7 +462,7 @@ class FramePointerAnalysisTest extends CompilerTest { ): IR = { val irs = moduleIr.preorder().collect { childIr => childIr.getMetadata(AliasAnalysis) match { - case Some(Info.Occurrence(_, occId)) if occId == id => + case Some(AliasMetadata.Occurrence(_, occId)) if occId == id => childIr } } @@ -471,10 +476,10 @@ class FramePointerAnalysisTest extends CompilerTest { private def collectAllOccurences( ir: IR - ): List[(IR, Info.Occurrence)] = { + ): List[(IR, AliasMetadata.Occurrence)] = { ir.preorder().flatMap { childIr => childIr.getMetadata(AliasAnalysis) match { - case Some(occMeta: Info.Occurrence) => + case Some(occMeta: alias.AliasMetadata.Occurrence) => Some((childIr, occMeta)) case _ => None }