Skip to content

Commit

Permalink
Fixes after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Aug 13, 2024
1 parent 056f029 commit ce74f86
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -233,19 +234,19 @@ 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) =>
val defId = defLink.target
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 =
Expand All @@ -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)
Expand All @@ -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),
Expand Down Expand Up @@ -329,18 +330,18 @@ 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
}
}

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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -116,7 +121,7 @@ class FramePointerAnalysisTest extends CompilerTest {
}

val plusUseIr = findAssociatedIr(
aliasGraph.symbolToIds[Graph.Occurrence.Use]("+").head,
aliasGraph.symbolToIds[GraphOccurrence.Use]("+").head,
ir
)
withClue(
Expand All @@ -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))
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
Expand Down

0 comments on commit ce74f86

Please sign in to comment.