Flatten object hierarchy of AliasAnalysis metadata so it is accessible from Java (#10780)

Flatten hierarchy of alias analysis metadata (`or.genso.compiler.pass.alias.Info`) so that it is easily accessible from Java and rename it.

# Important Notes
- Rename `org.enso.compiler.alias.Graph.Occurence` to `org.enso.compiler.alias.graph.GraphOccurence` and flatten the hierarchy.
- Rename `org.enso.compiler.pass.alias.Info` to `org.enso.compiler.pass.alias.AliasMetadata` and flatten the hierarchy.
This commit is contained in:
Pavel Marek 2024-08-12 17:03:41 +02:00 committed by GitHub
parent 6eece5f8d6
commit a79a393ed7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 487 additions and 413 deletions

View File

@ -5,7 +5,7 @@ import org.enso.compiler.core.ConstantsNames;
import org.enso.compiler.core.ir.Name;
import org.enso.compiler.data.BindingsMap;
import org.enso.compiler.pass.analyse.AliasAnalysis$;
import org.enso.compiler.pass.analyse.alias.Info;
import org.enso.compiler.pass.analyse.alias.AliasMetadata;
import org.enso.compiler.pass.resolve.GlobalNames$;
import scala.Option;
@ -30,8 +30,9 @@ import scala.Option;
*/
public abstract class NameResolutionAlgorithm<ResultType, LocalNameLinkType> {
public final ResultType resolveName(Name.Literal name) {
Info.Occurrence occurrenceMetadata =
MetadataInteropHelpers.getMetadata(name, AliasAnalysis$.MODULE$, Info.Occurrence.class);
AliasMetadata.Occurrence occurrenceMetadata =
MetadataInteropHelpers.getMetadata(
name, AliasAnalysis$.MODULE$, AliasMetadata.Occurrence.class);
var maybeLocalLink = findLocalLink(occurrenceMetadata);
if (maybeLocalLink.isDefined()) {
return resolveLocalName(maybeLocalLink.get());
@ -52,7 +53,8 @@ public abstract class NameResolutionAlgorithm<ResultType, LocalNameLinkType> {
return resolveUnresolvedSymbol(name.name());
}
protected abstract Option<LocalNameLinkType> findLocalLink(Info.Occurrence occurrenceMetadata);
protected abstract Option<LocalNameLinkType> findLocalLink(
AliasMetadata.Occurrence occurrenceMetadata);
protected abstract ResultType resolveLocalName(LocalNameLinkType localLink);

View File

@ -1,8 +1,9 @@
package org.enso.compiler.pass.analyse;
import java.io.IOException;
import org.enso.compiler.pass.analyse.alias.Graph;
import org.enso.compiler.pass.analyse.alias.Info;
import org.enso.compiler.pass.analyse.alias.AliasMetadata;
import org.enso.compiler.pass.analyse.alias.graph.Graph;
import org.enso.compiler.pass.analyse.alias.graph.GraphOccurrence;
import org.enso.compiler.pass.analyse.types.TypeInference;
import org.enso.compiler.pass.resolve.DocumentationComments;
import org.enso.compiler.pass.resolve.DocumentationComments$;
@ -57,23 +58,11 @@ import scala.Tuple2$;
@Persistable(clazz = GenericAnnotations$.class, id = 1216)
@Persistable(clazz = ExpressionAnnotations$.class, id = 1217)
@Persistable(clazz = FullyQualifiedNames$.class, id = 1218)
@Persistable(clazz = Info.Occurrence.class, id = 1261, allowInlining = false)
@Persistable(
clazz = org.enso.compiler.pass.analyse.alias.Info$Scope$Root.class,
id = 1262,
allowInlining = false)
@Persistable(
clazz = org.enso.compiler.pass.analyse.alias.Info$Scope$Child.class,
id = 1263,
allowInlining = false)
@Persistable(
clazz = org.enso.compiler.pass.analyse.alias.Graph$Occurrence$Use.class,
id = 1264,
allowInlining = false)
@Persistable(
clazz = org.enso.compiler.pass.analyse.alias.Graph$Occurrence$Def.class,
id = 1265,
allowInlining = false)
@Persistable(clazz = AliasMetadata.Occurrence.class, id = 1261, allowInlining = false)
@Persistable(clazz = AliasMetadata.RootScope.class, id = 1262, allowInlining = false)
@Persistable(clazz = AliasMetadata.ChildScope.class, id = 1263, allowInlining = false)
@Persistable(clazz = GraphOccurrence.Use.class, id = 1264, allowInlining = false)
@Persistable(clazz = GraphOccurrence.Def.class, id = 1265, allowInlining = false)
@Persistable(clazz = Graph.Link.class, id = 1266, allowInlining = false)
@Persistable(clazz = TypeInference.class, id = 1280)
public final class PassPersistance {
@ -131,7 +120,7 @@ public final class PassPersistance {
@SuppressWarnings("unchecked")
protected Graph.Scope readObject(Input in) throws IOException {
var childScopes = in.readInline(scala.collection.immutable.List.class);
var occurrencesValues = (scala.collection.immutable.Set<Graph.Occurrence>) in.readObject();
var occurrencesValues = (scala.collection.immutable.Set<GraphOccurrence>) in.readObject();
var occurrences = occurrencesValues.map(v -> Tuple2$.MODULE$.apply(v.id(), v)).toMap(null);
var allDefinitions = in.readInline(scala.collection.immutable.List.class);
var parent = new Graph.Scope(childScopes, occurrences, allDefinitions);

View File

@ -2,7 +2,7 @@ package org.enso.compiler.pass.analyse.types;
import java.util.HashMap;
import java.util.Map;
import org.enso.compiler.pass.analyse.alias.Graph;
import org.enso.compiler.pass.analyse.alias.graph.Graph;
/**
* A mapping that maps binding definitions from an alias analysis graph to their inferred types.

View File

@ -17,8 +17,9 @@ import org.enso.compiler.core.ir.expression.Application;
import org.enso.compiler.core.ir.expression.Case;
import org.enso.compiler.data.BindingsMap;
import org.enso.compiler.pass.analyse.AliasAnalysis$;
import org.enso.compiler.pass.analyse.alias.Graph;
import org.enso.compiler.pass.analyse.alias.Info;
import org.enso.compiler.pass.analyse.alias.AliasMetadata;
import org.enso.compiler.pass.analyse.alias.graph.Graph;
import org.enso.compiler.pass.analyse.alias.graph.GraphOccurrence;
import org.enso.compiler.pass.resolve.TypeSignatures;
import org.enso.compiler.pass.resolve.TypeSignatures$;
import org.slf4j.Logger;
@ -340,7 +341,7 @@ abstract class TypePropagation {
}
@Override
protected Option<LinkInfo> findLocalLink(Info.Occurrence occurrenceMetadata) {
protected Option<LinkInfo> findLocalLink(AliasMetadata.Occurrence occurrenceMetadata) {
return occurrenceMetadata
.graph()
.defLinkFor(occurrenceMetadata.id())
@ -396,7 +397,7 @@ abstract class TypePropagation {
*/
private void registerBinding(
IR binding, TypeRepresentation type, LocalBindingsTyping localBindingsTyping) {
var metadata = getMetadata(binding, AliasAnalysis$.MODULE$, Info.Occurrence.class);
var metadata = getMetadata(binding, AliasAnalysis$.MODULE$, AliasMetadata.Occurrence.class);
var occurrence = metadata.graph().getOccurrence(metadata.id());
if (occurrence.isEmpty()) {
logger.warn(
@ -404,7 +405,7 @@ abstract class TypePropagation {
return;
}
if (occurrence.get() instanceof org.enso.compiler.pass.analyse.alias.Graph$Occurrence$Def def) {
if (occurrence.get() instanceof GraphOccurrence.Def def) {
localBindingsTyping.registerBindingType(metadata.graph(), def.id(), type);
} else {
throw new CompilerError(

View File

@ -1,7 +1,10 @@
package org.enso.compiler.context
import org.enso.compiler.pass.analyse.DataflowAnalysis
import org.enso.compiler.pass.analyse.alias.{Graph => AliasGraph}
import org.enso.compiler.pass.analyse.alias.graph.{
GraphOccurrence,
Graph => AliasGraph
}
import scala.jdk.CollectionConverters._
@ -140,7 +143,7 @@ class LocalScope(
.getOrElse(Map())
scope.occurrences.foreach {
case (id, x: AliasGraph.Occurrence.Def) =>
case (id, x: GraphOccurrence.Def) =>
parentResult += x.symbol -> new FramePointer(
level,
allFrameSlotIdxs(id)

View File

@ -28,7 +28,9 @@ import org.enso.compiler.core.ir.{
}
import org.enso.compiler.core.{CompilerError, IR}
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.alias.Graph.{Occurrence, Scope}
import org.enso.compiler.pass.analyse.alias.graph.Graph
import org.enso.compiler.pass.analyse.alias.graph.GraphOccurrence
import org.enso.compiler.pass.analyse.alias.graph.Graph.Scope
import org.enso.compiler.pass.desugar._
import org.enso.compiler.pass.lint.UnusedBindings
@ -69,7 +71,7 @@ import scala.collection.mutable
case object AliasAnalysis extends IRPass {
/** Alias information for the IR. */
override type Metadata = alias.Info
override type Metadata = alias.AliasMetadata
override type Config = Configuration
override lazy val precursorPasses: Seq[IRPass] = List(
@ -159,7 +161,7 @@ case object AliasAnalysis extends IRPass {
sourceRootScopeGraphOpt.foreach { sourceRootScopeGraphScope =>
val sourceRootScopeGraph =
sourceRootScopeGraphScope
.asInstanceOf[alias.Info.Scope.Root]
.asInstanceOf[alias.AliasMetadata.RootScope]
.graph
val scopeMapping = mutable.Map[Scope, Scope]()
@ -175,14 +177,14 @@ case object AliasAnalysis extends IRPass {
sourceNode.getMetadata(this) match {
case Some(meta) =>
val newMeta = meta match {
case root: alias.Info.Scope.Root =>
case root: alias.AliasMetadata.RootScope =>
root.copy(graph = copyRootScopeGraph)
case child: alias.Info.Scope.Child =>
case child: alias.AliasMetadata.ChildScope =>
child.copy(
graph = copyRootScopeGraph,
scope = child.scope.deepCopy(scopeMapping)
)
case occ: alias.Info.Occurrence =>
case occ: alias.AliasMetadata.Occurrence =>
occ.copy(graph = copyRootScopeGraph)
}
copyNode.updateMetadata(new MetadataPair(this, newMeta))
@ -228,7 +230,7 @@ case object AliasAnalysis extends IRPass {
def analyseModuleDefinition(
ir: Definition
): Definition = {
val topLevelGraph = new alias.Graph
val topLevelGraph = new Graph
ir match {
case m: definition.Method.Conversion =>
@ -244,7 +246,7 @@ case object AliasAnalysis extends IRPass {
).updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Root(topLevelGraph)
alias.AliasMetadata.RootScope(topLevelGraph)
)
)
case _ =>
@ -265,7 +267,7 @@ case object AliasAnalysis extends IRPass {
).updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Root(topLevelGraph)
alias.AliasMetadata.RootScope(topLevelGraph)
)
)
case _ =>
@ -285,7 +287,7 @@ case object AliasAnalysis extends IRPass {
topLevelGraph.rootScope
),
members = t.members.map(d => {
val graph = new alias.Graph
val graph = new Graph
d.copy(
arguments = analyseArgumentDefs(
d.arguments,
@ -304,16 +306,16 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Root(topLevelGraph)
alias.AliasMetadata.RootScope(topLevelGraph)
)
)
}
).updateMetadata(
new MetadataPair(this, alias.Info.Scope.Root(graph))
new MetadataPair(this, alias.AliasMetadata.RootScope(graph))
)
})
).updateMetadata(
new MetadataPair(this, alias.Info.Scope.Root(topLevelGraph))
new MetadataPair(this, alias.AliasMetadata.RootScope(topLevelGraph))
)
case _: Definition.SugaredType =>
throw new CompilerError(
@ -344,7 +346,7 @@ case object AliasAnalysis extends IRPass {
)
)
.updateMetadata(
new MetadataPair(this, alias.Info.Scope.Root(topLevelGraph))
new MetadataPair(this, alias.AliasMetadata.RootScope(topLevelGraph))
)
case err: Error => err
}
@ -367,7 +369,7 @@ case object AliasAnalysis extends IRPass {
*/
private def analyseExpression(
expression: Expression,
graph: alias.Graph,
graph: Graph,
parentScope: Scope,
lambdaReuseScope: Boolean = false
): Expression = {
@ -412,18 +414,20 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Child(graph, currentScope)
alias.AliasMetadata.ChildScope(graph, currentScope)
)
)
case binding @ Expression.Binding(name, expression, _, _, _) =>
if (!parentScope.hasSymbolOccurrenceAs[Occurrence.Def](name.name)) {
if (
!parentScope.hasSymbolOccurrenceAs[GraphOccurrence.Def](name.name)
) {
val isSuspended = expression match {
case Expression.Block(_, _, _, isSuspended, _, _) => isSuspended
case _ => false
}
val occurrenceId = graph.nextId()
val occurrence =
Occurrence.Def(
GraphOccurrence.Def(
occurrenceId,
name.name,
binding.getId(),
@ -445,7 +449,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Occurrence(graph, occurrenceId)
alias.AliasMetadata.Occurrence(graph, occurrenceId)
)
)
} else {
@ -474,7 +478,7 @@ case object AliasAnalysis extends IRPass {
*/
def analyseType(
value: Type,
graph: alias.Graph,
graph: Graph,
parentScope: Scope
): Type = {
value match {
@ -491,7 +495,12 @@ case object AliasAnalysis extends IRPass {
val labelId = graph.nextId()
val definition =
Occurrence.Def(labelId, label.name, label.getId, label.getExternalId)
GraphOccurrence.Def(
labelId,
label.name,
label.getId,
label.getExternalId
)
parentScope.add(definition)
parentScope.addDefinition(definition)
@ -501,7 +510,10 @@ case object AliasAnalysis extends IRPass {
value = analyseExpression(value, graph, valueScope)
)
.updateMetadata(
new MetadataPair(this, alias.Info.Occurrence(graph, labelId))
new MetadataPair(
this,
alias.AliasMetadata.Occurrence(graph, labelId)
)
)
case x =>
x.mapExpressions(analyseExpression(_, graph, parentScope))
@ -526,7 +538,7 @@ case object AliasAnalysis extends IRPass {
*/
private def analyseArgumentDefs(
args: List[DefinitionArgument],
graph: alias.Graph,
graph: Graph,
scope: Scope
): List[DefinitionArgument] = {
args.map {
@ -542,7 +554,7 @@ case object AliasAnalysis extends IRPass {
// Synthetic `self` must not be added to the scope, but it has to be added as a
// definition for frame index metadata
val occurrenceId = graph.nextId()
val definition = alias.Graph.Occurrence.Def(
val definition = GraphOccurrence.Def(
occurrenceId,
selfName.name,
arg.getId(),
@ -553,7 +565,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Occurrence(graph, occurrenceId)
alias.AliasMetadata.Occurrence(graph, occurrenceId)
)
)
.copy(
@ -571,7 +583,7 @@ case object AliasAnalysis extends IRPass {
_
) =>
val nameOccursInScope =
scope.hasSymbolOccurrenceAs[alias.Graph.Occurrence.Def](
scope.hasSymbolOccurrenceAs[GraphOccurrence.Def](
name.name
)
if (!nameOccursInScope) {
@ -582,7 +594,7 @@ case object AliasAnalysis extends IRPass {
)
val occurrenceId = graph.nextId()
val definition = alias.Graph.Occurrence.Def(
val definition = GraphOccurrence.Def(
occurrenceId,
name.name,
arg.getId(),
@ -601,7 +613,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Occurrence(graph, occurrenceId)
alias.AliasMetadata.Occurrence(graph, occurrenceId)
)
)
} else {
@ -615,7 +627,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Occurrence(graph, f.get.id)
alias.AliasMetadata.Occurrence(graph, f.get.id)
)
)
}
@ -631,8 +643,8 @@ case object AliasAnalysis extends IRPass {
*/
def analyseApplication(
application: Application,
graph: alias.Graph,
scope: alias.Graph.Scope
graph: Graph,
scope: Graph.Scope
): Application = {
application match {
case app @ Application.Prefix(fun, arguments, _, _, _, _) =>
@ -651,7 +663,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Child(graph, newScope)
alias.AliasMetadata.ChildScope(graph, newScope)
)
)
case _: Operator.Binary =>
@ -674,8 +686,8 @@ case object AliasAnalysis extends IRPass {
*/
private def analyseCallArguments(
args: List[CallArgument],
graph: alias.Graph,
parentScope: alias.Graph.Scope
graph: Graph,
parentScope: Graph.Scope
): List[CallArgument] = {
args.map { case arg @ CallArgument.Specified(_, expr, _, _, _) =>
val currentScope = expr match {
@ -687,7 +699,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Child(graph, currentScope)
alias.AliasMetadata.ChildScope(graph, currentScope)
)
)
}
@ -704,7 +716,7 @@ case object AliasAnalysis extends IRPass {
*/
def analyseFunction(
function: Function,
graph: alias.Graph,
graph: Graph,
parentScope: Scope,
lambdaReuseScope: Boolean = false
): Function = {
@ -725,7 +737,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Child(graph, currentScope)
alias.AliasMetadata.ChildScope(graph, currentScope)
)
)
case _: Function.Binding =>
@ -750,19 +762,29 @@ case object AliasAnalysis extends IRPass {
name: Name,
isInPatternContext: Boolean,
isConstructorNameInPatternContext: Boolean,
graph: alias.Graph,
graph: Graph,
parentScope: Scope
): Name = {
val occurrenceId = graph.nextId()
if (isInPatternContext && !isConstructorNameInPatternContext) {
val definition =
Occurrence.Def(occurrenceId, name.name, name.getId, name.getExternalId)
GraphOccurrence.Def(
occurrenceId,
name.name,
name.getId,
name.getExternalId
)
parentScope.add(definition)
parentScope.addDefinition(definition)
} else {
val occurrence =
Occurrence.Use(occurrenceId, name.name, name.getId, name.getExternalId)
GraphOccurrence.Use(
occurrenceId,
name.name,
name.getId,
name.getExternalId
)
parentScope.add(occurrence)
if (!isConstructorNameInPatternContext && !name.isMethod) {
graph.resolveLocalUsage(occurrence)
@ -771,7 +793,10 @@ case object AliasAnalysis extends IRPass {
}
}
name.updateMetadata(
new MetadataPair(this, alias.Info.Occurrence(graph, occurrenceId))
new MetadataPair(
this,
alias.AliasMetadata.Occurrence(graph, occurrenceId)
)
)
}
@ -784,7 +809,7 @@ case object AliasAnalysis extends IRPass {
*/
def analyseCase(
ir: Case,
graph: alias.Graph,
graph: Graph,
parentScope: Scope
): Case = {
ir match {
@ -808,7 +833,7 @@ case object AliasAnalysis extends IRPass {
*/
def analyseCaseBranch(
branch: Case.Branch,
graph: alias.Graph,
graph: Graph,
parentScope: Scope
): Case.Branch = {
val currentScope = parentScope.addChild()
@ -825,7 +850,7 @@ case object AliasAnalysis extends IRPass {
.updateMetadata(
new MetadataPair(
this,
alias.Info.Scope.Child(graph, currentScope)
alias.AliasMetadata.ChildScope(graph, currentScope)
)
)
}
@ -839,7 +864,7 @@ case object AliasAnalysis extends IRPass {
*/
def analysePattern(
pattern: Pattern,
graph: alias.Graph,
graph: Graph,
parentScope: Scope
): Pattern = {
pattern match {

View File

@ -16,6 +16,7 @@ import org.enso.compiler.data.BindingsMap.{Resolution, ResolvedModuleMethod}
import org.enso.compiler.core.CompilerError
import org.enso.compiler.core.ir.expression.{Application, Operator}
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.alias.graph.Graph
import org.enso.compiler.pass.desugar.ComplexType
import org.enso.compiler.pass.resolve.{
IgnoredBindings,
@ -78,7 +79,7 @@ object AutomaticParallelism extends IRPass {
ir: Expression,
parallelismStatus: ParallelismStatus,
id: Int,
assignment: Option[alias.Graph.Id],
assignment: Option[Graph.Id],
dependencies: Set[Int],
blockAssignment: Option[BlockAssignment]
)
@ -215,7 +216,7 @@ object AutomaticParallelism extends IRPass {
AliasAnalysis,
"Alias analysis left a binding behind"
)
.asInstanceOf[alias.Info.Occurrence]
.asInstanceOf[alias.AliasMetadata.Occurrence]
line.copy(assignment = Some(aaInfo.id))
case _ => line
}
@ -233,7 +234,7 @@ object AutomaticParallelism extends IRPass {
n
}
.flatMap(_.getMetadata(AliasAnalysis))
.collect { case occ: alias.Info.Occurrence =>
.collect { case occ: alias.AliasMetadata.Occurrence =>
occ
}
.flatMap(occ => occ.graph.defLinkFor(occ.id))

View File

@ -30,6 +30,7 @@ import org.enso.compiler.core.ir.{
import org.enso.compiler.core.ir.MetadataStorage._
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.DataflowAnalysis.DependencyInfo.Type.asStatic
import org.enso.compiler.pass.analyse.alias.graph.GraphOccurrence
import java.util.UUID
import scala.collection.immutable.ListSet
@ -548,7 +549,7 @@ case object DataflowAnalysis extends IRPass {
"Name occurrence with missing aliasing information."
)
)
.asInstanceOf[alias.Info.Occurrence]
.asInstanceOf[alias.AliasMetadata.Occurrence]
name match {
case _: Name.Blank =>
@ -560,7 +561,7 @@ case object DataflowAnalysis extends IRPass {
val key: DependencyInfo.Type = defIdForName match {
case Some(defLink) =>
aliasInfo.graph.getOccurrence(defLink.target) match {
case Some(alias.Graph.Occurrence.Def(_, _, id, ext, _)) =>
case Some(GraphOccurrence.Def(_, _, id, ext, _)) =>
DependencyInfo.Type.Static(id, ext)
case _ =>
DependencyInfo.Type.Dynamic(name.name, None)

View File

@ -202,7 +202,7 @@ case object DemandAnalysis extends IRPass {
AliasAnalysis,
"Missing alias occurrence information for a name usage"
)
.unsafeAs[alias.Info.Occurrence]
.unsafeAs[alias.AliasMetadata.Occurrence]
aliasInfo.graph.defLinkFor(aliasInfo.id).isDefined
}

View File

@ -0,0 +1,89 @@
package org.enso.compiler.pass.analyse.alias
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.alias.graph.Graph
/** Information about the aliasing state for a given IR node. */
sealed trait AliasMetadata extends IRPass.IRMetadata {
/** The aliasing graph. */
val graph: Graph
}
object AliasMetadata {
sealed trait Scope extends AliasMetadata
/** Aliasing information for a root scope.
*
* A root scope has a 1:1 correspondence with a top-level binding.
*
* @param graph the graph containing the alias information for that node
*/
sealed case class RootScope(override val graph: Graph) extends Scope {
override val metadataName: String = "AliasMetadata.RootScope"
/** @inheritdoc */
override def prepareForSerialization(
compiler: Compiler
): RootScope = this
/** @inheritdoc */
override def restoreFromSerialization(
compiler: Compiler
): Option[RootScope] = Some(this)
/** @inheritdoc */
override def duplicate(): Option[IRPass.IRMetadata] = None
}
/** Aliasing information about a child scope.
*
* @param graph the graph
* @param scope the child scope in `graph`
*/
sealed case class ChildScope(
override val graph: Graph,
scope: Graph.Scope
) extends Scope {
override val metadataName: String = "AliasMetadata.ChildScope"
/** @inheritdoc */
override def prepareForSerialization(
compiler: Compiler
): ChildScope = this
/** @inheritdoc */
override def restoreFromSerialization(
compiler: Compiler
): Option[ChildScope] = Some(this)
/** @inheritdoc */
override def duplicate(): Option[IRPass.IRMetadata] = None
}
/** Aliasing information for a piece of [[IR]] that is contained within a
* [[Scope]].
*
* @param graph the graph in which this IR node can be found
* @param id the identifier of this IR node in `graph`
*/
sealed case class Occurrence(
override val graph: Graph,
id: Graph.Id
) extends AliasMetadata {
override val metadataName: String = "AliasMetadata.Occurrence"
/** @inheritdoc */
override def prepareForSerialization(
compiler: Compiler
): Occurrence = this
/** @inheritdoc */
override def restoreFromSerialization(
compiler: Compiler
): Option[Occurrence] = Some(this)
/** @inheritdoc */
override def duplicate(): Option[IRPass.IRMetadata] = None
}
}

View File

@ -1,89 +0,0 @@
package org.enso.compiler.pass.analyse.alias
import org.enso.compiler.pass.IRPass
/** Information about the aliasing state for a given IR node. */
sealed trait Info extends IRPass.IRMetadata {
/** The aliasing graph. */
val graph: Graph
}
object Info {
sealed trait Scope extends Info
object Scope {
/** Aliasing information for a root scope.
*
* A root scope has a 1:1 correspondence with a top-level binding.
*
* @param graph the graph containing the alias information for that node
*/
sealed case class Root(override val graph: Graph) extends Scope {
override val metadataName: String = "Info.Scope.Root"
/** @inheritdoc */
override def prepareForSerialization(
compiler: Compiler
): Root = this
/** @inheritdoc */
override def restoreFromSerialization(
compiler: Compiler
): Option[Root] = Some(this)
/** @inheritdoc */
override def duplicate(): Option[IRPass.IRMetadata] = None
}
/** Aliasing information about a child scope.
*
* @param graph the graph
* @param scope the child scope in `graph`
*/
sealed case class Child(
override val graph: Graph,
scope: Graph.Scope
) extends Scope {
override val metadataName: String = "Info.Scope.Child"
/** @inheritdoc */
override def prepareForSerialization(
compiler: Compiler
): Child = this
/** @inheritdoc */
override def restoreFromSerialization(
compiler: Compiler
): Option[Child] = Some(this)
/** @inheritdoc */
override def duplicate(): Option[IRPass.IRMetadata] = None
}
}
/** Aliasing information for a piece of [[IR]] that is contained within a
* [[Scope]].
*
* @param graph the graph in which this IR node can be found
* @param id the identifier of this IR node in `graph`
*/
sealed case class Occurrence(
override val graph: Graph,
id: Graph.Id
) extends Info {
override val metadataName: String = "Info.Occurrence"
/** @inheritdoc */
override def prepareForSerialization(
compiler: Compiler
): Occurrence = this
/** @inheritdoc */
override def restoreFromSerialization(
compiler: Compiler
): Option[Occurrence] = Some(this)
/** @inheritdoc */
override def duplicate(): Option[IRPass.IRMetadata] = None
}
}

View File

@ -1,10 +1,9 @@
package org.enso.compiler.pass.analyse.alias
package org.enso.compiler.pass.analyse.alias.graph
import org.enso.compiler.core.{CompilerError, ExternalID, Identifier}
import org.enso.compiler.core.CompilerError
import org.enso.compiler.debug.Debug
import org.enso.compiler.pass.analyse.alias.Graph.{Occurrence, Scope}
import org.enso.compiler.pass.analyse.alias.graph.Graph.Scope
import java.util.UUID
import scala.collection.immutable.HashMap
import scala.collection.mutable
import scala.reflect.ClassTag
@ -17,7 +16,7 @@ sealed class Graph extends Serializable {
private var targetLinks: Map[Graph.Id, Set[Graph.Link]] = new HashMap()
var nextIdCounter = 0
private var globalSymbols: Map[Graph.Symbol, Occurrence.Global] =
private var globalSymbols: Map[Graph.Symbol, GraphOccurrence.Global] =
Map()
/** @return a deep structural copy of `this` */
@ -47,7 +46,7 @@ sealed class Graph extends Serializable {
*
* @param sym the symbol occurrence
*/
def addGlobalSymbol(sym: Occurrence.Global): Unit = {
def addGlobalSymbol(sym: GraphOccurrence.Global): Unit = {
if (!globalSymbols.contains(sym.symbol)) {
globalSymbols = globalSymbols + (sym.symbol -> sym)
}
@ -97,7 +96,7 @@ sealed class Graph extends Serializable {
* @return the link, if it exists
*/
def resolveLocalUsage(
occurrence: Graph.Occurrence.Use
occurrence: GraphOccurrence.Use
): Option[Graph.Link] = {
scopeFor(occurrence.id).flatMap(_.resolveUsage(occurrence).map { link =>
links += link
@ -122,7 +121,7 @@ sealed class Graph extends Serializable {
* @return the link, if it exists
*/
def resolveGlobalUsage(
occurrence: Graph.Occurrence.Use
occurrence: GraphOccurrence.Use
): Option[Graph.Link] = {
scopeFor(occurrence.id) match {
case Some(scope) =>
@ -168,7 +167,7 @@ sealed class Graph extends Serializable {
* @tparam T the role in which `symbol` should occur
* @return a set of all links in which `symbol` occurs with role `T`
*/
def linksFor[T <: Occurrence: ClassTag](
def linksFor[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): Set[Graph.Link] = {
val idsForSym = rootScope.symbolToIds[T](symbol)
@ -184,7 +183,7 @@ sealed class Graph extends Serializable {
* @param id the occurrence identifier
* @return the occurrence for `id`, if it exists
*/
def getOccurrence(id: Graph.Id): Option[Occurrence] =
def getOccurrence(id: Graph.Id): Option[GraphOccurrence] =
scopeFor(id).flatMap(_.getOccurrence(id))
/** Gets the link from an id to the definition of the symbol it represents.
@ -196,8 +195,8 @@ sealed class Graph extends Serializable {
linksFor(id).find { edge =>
val occ = getOccurrence(edge.target)
occ match {
case Some(Occurrence.Def(_, _, _, _, _)) => true
case _ => false
case Some(GraphOccurrence.Def(_, _, _, _, _)) => true
case _ => false
}
}
}
@ -217,7 +216,7 @@ sealed class Graph extends Serializable {
* @tparam T the role in which `symbol` occurs
* @return all the scopes where `symbol` occurs with role `T`
*/
def scopesFor[T <: Graph.Occurrence: ClassTag](
def scopesFor[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): List[Graph.Scope] = {
rootScope.scopesForSymbol[T](symbol)
@ -249,8 +248,8 @@ sealed class Graph extends Serializable {
scopeFor(id)
.flatMap(
_.getOccurrence(id).flatMap {
case d: Occurrence.Def => Some(d)
case _ => None
case d: GraphOccurrence.Def => Some(d)
case _ => None
}
)
.isDefined
@ -267,25 +266,25 @@ sealed class Graph extends Serializable {
* @return the bindings shadowed by `definition`
*/
def knownShadowedDefinitions(
definition: Occurrence
): Set[Graph.Occurrence] = {
definition: GraphOccurrence
): Set[GraphOccurrence] = {
def getShadowedIds(
scope: Graph.Scope
): Set[Graph.Occurrence] = {
): Set[GraphOccurrence] = {
scope.occurrences.values.collect {
case d: Occurrence.Def if d.symbol == definition.symbol => d
case g: Occurrence.Global if g.symbol == definition.symbol => g
case d: GraphOccurrence.Def if d.symbol == definition.symbol => d
case g: GraphOccurrence.Global if g.symbol == definition.symbol => g
} ++ scope.parent.map(getShadowedIds).getOrElse(Set())
}.toSet
definition match {
case d: Occurrence.Def =>
case d: GraphOccurrence.Def =>
scopeFor(d.id).flatMap(_.parent) match {
case Some(scope) => getShadowedIds(scope) // + globals
case None => Set()
}
case _: Occurrence.Global => Set()
case _: Occurrence.Use => Set()
case _: GraphOccurrence.Global => Set()
case _: GraphOccurrence.Use => Set()
}
}
@ -315,7 +314,7 @@ sealed class Graph extends Serializable {
* @tparam T the role in which `symbol` should occur
* @return a list of identifiers for that symbol
*/
def symbolToIds[T <: Occurrence: ClassTag](
def symbolToIds[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): List[Graph.Id] = {
rootScope.symbolToIds[T](symbol)
@ -348,9 +347,9 @@ object Graph {
* Note that there may not be a link for all these definitions.
*/
sealed class Scope(
var childScopes: List[Scope] = List(),
var occurrences: Map[Id, Occurrence] = HashMap(),
var allDefinitions: List[Occurrence.Def] = List()
var childScopes: List[Scope] = List(),
var occurrences: Map[Id, GraphOccurrence] = HashMap(),
var allDefinitions: List[GraphOccurrence.Def] = List()
) extends Serializable {
var parent: Option[Scope] = None
@ -436,7 +435,7 @@ object Graph {
*
* @param occurrence the occurrence to add
*/
def add(occurrence: Occurrence): Unit = {
def add(occurrence: GraphOccurrence): Unit = {
if (occurrences.contains(occurrence.id)) {
throw new CompilerError(
s"Multiple occurrences found for ID ${occurrence.id}."
@ -451,7 +450,7 @@ object Graph {
*
* @param definition The definition to add.
*/
def addDefinition(definition: Occurrence.Def): Unit = {
def addDefinition(definition: GraphOccurrence.Def): Unit = {
allDefinitions = allDefinitions ++ List(definition)
}
@ -461,7 +460,7 @@ object Graph {
* @param id the occurrence identifier
* @return the occurrence for `id`, if it exists
*/
def getOccurrence(id: Graph.Id): Option[Occurrence] = {
def getOccurrence(id: Graph.Id): Option[GraphOccurrence] = {
occurrences.get(id)
}
@ -472,9 +471,9 @@ object Graph {
* @tparam T the role for the symbol
* @return the occurrences for `name`, if they exist
*/
def getOccurrences[T <: Occurrence: ClassTag](
def getOccurrences[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): Set[Occurrence] = {
): Set[GraphOccurrence] = {
occurrences.values.collect {
case o: T if o.symbol == symbol => o
}.toSet
@ -488,7 +487,7 @@ object Graph {
* @param id the occurrence identifier
* @return the occurrence for `id`
*/
def unsafeGetOccurrence(id: Graph.Id): Occurrence = {
def unsafeGetOccurrence(id: Graph.Id): GraphOccurrence = {
getOccurrence(id).get
}
@ -499,7 +498,7 @@ object Graph {
* @return `true` if `symbol` occurs in role `T` in this scope, `false`
* otherwise
*/
def hasSymbolOccurrenceAs[T <: Occurrence: ClassTag](
def hasSymbolOccurrenceAs[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): Boolean = {
occurrences.values.collectFirst {
@ -516,11 +515,11 @@ object Graph {
* exists
*/
def resolveUsage(
occurrence: Graph.Occurrence.Use,
occurrence: GraphOccurrence.Use,
parentCounter: Int = 0
): Option[Graph.Link] = {
val definition = occurrences.values.find {
case Graph.Occurrence.Def(_, name, _, _, _) =>
case GraphOccurrence.Def(_, name, _, _, _) =>
name == occurrence.symbol
case _ => false
}
@ -613,7 +612,7 @@ object Graph {
* @tparam T the role in which `name` occurs
* @return all the scopes where `name` occurs with role `T`
*/
def scopesForSymbol[T <: Occurrence: ClassTag](
def scopesForSymbol[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): List[Scope] = {
val occursInThisScope = hasSymbolOccurrenceAs[T](symbol)
@ -646,7 +645,7 @@ object Graph {
* @tparam T the role in which `symbol` should occur
* @return a list of identifiers for that symbol
*/
def symbolToIds[T <: Occurrence: ClassTag](
def symbolToIds[T <: GraphOccurrence: ClassTag](
symbol: Graph.Symbol
): List[Graph.Id] = {
val scopes =
@ -694,8 +693,8 @@ object Graph {
/** A link in the [[Graph]].
*
* The source of the link should always be an [[Occurrence.Use]] while the
* target of the link should always be an [[Occurrence.Def]].
* The source of the link should always be an [[GraphOccurrence.Use]] while the
* target of the link should always be an [[GraphOccurrence.Def]].
*
* @param source the source ID of the link in the graph
* @param scopeCount the number of scopes that the link traverses
@ -703,59 +702,4 @@ object Graph {
*/
sealed case class Link(source: Id, scopeCount: Int, target: Id)
extends Serializable
/** An occurrence of a given symbol in the aliasing graph. */
sealed trait Occurrence extends Serializable {
val id: Id
val symbol: Graph.Symbol
}
object Occurrence {
/** The definition of a symbol in the aliasing graph.
*
* @param id the identifier of the name in the graph
* @param symbol the text of the name
* @param identifier the identifier of the symbol
* @param externalId the external identifier for the IR node defining
* the symbol
* @param isLazy whether or not the symbol is defined as lazy
*/
sealed case class Def(
override val id: Id,
override val symbol: Graph.Symbol,
identifier: UUID @Identifier,
externalId: Option[UUID @ExternalID],
isLazy: Boolean = false
) extends Occurrence
/** A usage of a symbol in the aliasing graph
*
* Name usages _need not_ correspond to name definitions, as dynamic
* symbol resolution means that a name used at runtime _may not_ be
* statically visible in the scope.
*
* @param id the identifier of the name in the graph
* @param symbol the text of the name
* @param identifier the identifier of the symbol
* @param externalId the external identifier for the IR node defining
* the symbol
*/
sealed case class Use(
override val id: Id,
override val symbol: Graph.Symbol,
identifier: UUID @Identifier,
externalId: Option[UUID @ExternalID]
) extends Occurrence
// TODO [AA] At some point the analysis should make use of these.
/** Represents a global symbol that has been _asked for_ in the program.
*
* @param id the identifier of the name in the graph
* @param symbol the text of the name
*/
sealed case class Global(
override val id: Id,
override val symbol: Graph.Symbol
) extends Occurrence
}
}

View File

@ -0,0 +1,65 @@
package org.enso.compiler.pass.analyse.alias.graph
import org.enso.compiler.core.{ExternalID, Identifier}
import org.enso.compiler.pass.analyse.alias.graph.Graph.Id
import java.util.UUID
/** An occurrence of a given symbol in the aliasing graph.
* Note that this is not present in the metadata attached to the [[org.enso.compiler.core.IR]] elements,
* but only in the alias [[Graph]].
*/
sealed trait GraphOccurrence extends Serializable {
val id: Id
val symbol: Graph.Symbol
}
object GraphOccurrence {
/** The definition of a symbol in the aliasing graph.
*
* @param id the identifier of the name in the graph
* @param symbol the text of the name
* @param identifier the identifier of the symbol
* @param externalId the external identifier for the IR node defining
* the symbol
* @param isLazy whether or not the symbol is defined as lazy
*/
sealed case class Def(
override val id: Id,
override val symbol: Graph.Symbol,
identifier: UUID @Identifier,
externalId: Option[UUID @ExternalID],
isLazy: Boolean = false
) extends GraphOccurrence
/** A usage of a symbol in the aliasing graph
*
* Name usages _need not_ correspond to name definitions, as dynamic
* symbol resolution means that a name used at runtime _may not_ be
* statically visible in the scope.
*
* @param id the identifier of the name in the graph
* @param symbol the text of the name
* @param identifier the identifier of the symbol
* @param externalId the external identifier for the IR node defining
* the symbol
*/
sealed case class Use(
override val id: Id,
override val symbol: Graph.Symbol,
identifier: UUID @Identifier,
externalId: Option[UUID @ExternalID]
) extends GraphOccurrence
// TODO [AA] At some point the analysis should make use of these.
/** Represents a global symbol that has been _asked for_ in the program.
*
* @param id the identifier of the name in the graph
* @param symbol the text of the name
*/
sealed case class Global(
override val id: Id,
override val symbol: Graph.Symbol
) extends GraphOccurrence
}

View File

@ -16,7 +16,7 @@ import org.enso.compiler.core.ir.expression.{errors, warnings, Case, Foreign}
import org.enso.compiler.core.CompilerError
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.AliasAnalysis
import org.enso.compiler.pass.analyse.alias.{Info => AliasInfo}
import org.enso.compiler.pass.analyse.alias.{AliasMetadata => AliasInfo}
import org.enso.compiler.pass.desugar._
import org.enso.compiler.pass.optimise.LambdaConsolidate
import org.enso.compiler.pass.resolve.{ExpressionAnnotations, IgnoredBindings}

View File

@ -16,16 +16,17 @@ import org.enso.compiler.core.ir.{
import org.enso.compiler.core.ir.expression.warnings
import org.enso.compiler.core.ir.expression.errors
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.alias.graph.{
GraphOccurrence,
Graph => AliasGraph
}
import org.enso.compiler.pass.analyse.{
AliasAnalysis,
DataflowAnalysis,
DemandAnalysis,
TailCall
}
import org.enso.compiler.pass.analyse.alias.{
Graph => AliasGraph,
Info => AliasInfo
}
import org.enso.compiler.pass.analyse.alias.{AliasMetadata => AliasInfo}
import org.enso.compiler.pass.desugar._
import org.enso.compiler.pass.resolve.IgnoredBindings
@ -364,7 +365,7 @@ case object LambdaConsolidate extends IRPass {
.flatMap(occ => Some(aliasInfo.graph.knownShadowedDefinitions(occ)))
.getOrElse(Set())
}
.foldLeft(Set[AliasGraph.Occurrence]())(_ ++ _)
.foldLeft(Set[GraphOccurrence]())(_ ++ _)
.map(_.id)
}
@ -397,7 +398,7 @@ case object LambdaConsolidate extends IRPass {
.map(link => aliasInfo.graph.getOccurrence(link.source))
.collect {
case Some(
AliasGraph.Occurrence.Use(_, _, identifier, _)
GraphOccurrence.Use(_, _, identifier, _)
) =>
identifier
}

View File

@ -25,7 +25,7 @@ import org.enso.compiler.core.Implicits.{AsDiagnostics, AsMetadata}
import org.enso.compiler.core.ir.expression.Application
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.{AliasAnalysis, BindingAnalysis}
import org.enso.compiler.pass.analyse.alias.{Info => AliasInfo}
import org.enso.compiler.pass.analyse.alias.{AliasMetadata => AliasInfo}
import org.enso.compiler.pass.desugar.Imports
import org.enso.editions.LibraryName

View File

@ -27,7 +27,7 @@ import org.enso.compiler.core.ConstantsNames
import org.enso.compiler.core.ir.expression.Application
import org.enso.compiler.pass.IRPass
import org.enso.compiler.pass.analyse.{AliasAnalysis, BindingAnalysis}
import org.enso.compiler.pass.analyse.alias.{Info => AliasInfo}
import org.enso.compiler.pass.analyse.alias.{AliasMetadata => AliasInfo}
/** Resolves name occurences in non-pattern contexts.
*

View File

@ -16,8 +16,9 @@ import org.enso.compiler.core.ir.module.scope.Definition
import org.enso.compiler.core.ir.module.scope.definition
import org.enso.compiler.pass.PassConfiguration._
import org.enso.compiler.pass.analyse.AliasAnalysis
import org.enso.compiler.pass.analyse.alias.Graph.{Link, Occurrence}
import org.enso.compiler.pass.analyse.alias.{Graph, Info}
import org.enso.compiler.pass.analyse.alias.graph.Graph.Link
import org.enso.compiler.pass.analyse.alias.AliasMetadata
import org.enso.compiler.pass.analyse.alias.graph.{Graph, GraphOccurrence}
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
import org.enso.compiler.test.CompilerTest
@ -94,19 +95,19 @@ class AliasAnalysisTest extends CompilerTest {
val childOfChildOfChild = childOfChild.addChild()
val aDefId = graph.nextId()
val aDef = Occurrence.Def(aDefId, "a", genId, None)
val aDef = GraphOccurrence.Def(aDefId, "a", genId, None)
val bDefId = graph.nextId()
val bDef = Occurrence.Def(bDefId, "b", genId, None)
val bDef = GraphOccurrence.Def(bDefId, "b", genId, None)
val aUseId = graph.nextId()
val aUse = Occurrence.Use(aUseId, "a", genId, None)
val aUse = GraphOccurrence.Use(aUseId, "a", genId, None)
val bUseId = graph.nextId()
val bUse = Occurrence.Use(bUseId, "b", genId, None)
val bUse = GraphOccurrence.Use(bUseId, "b", genId, None)
val cUseId = graph.nextId()
val cUse = Occurrence.Use(cUseId, "c", genId, None)
val cUse = GraphOccurrence.Use(cUseId, "c", genId, None)
// Add occurrences to the scopes
complexScope.add(aDef)
@ -144,7 +145,9 @@ class AliasAnalysisTest extends CompilerTest {
}
"find the occurrence for an name in the current scope if it exists" in {
complexScope.getOccurrences[Occurrence](aDef.symbol) shouldEqual Set(aDef)
complexScope.getOccurrences[GraphOccurrence](aDef.symbol) shouldEqual Set(
aDef
)
}
"find no occurrences if they do not exist" in {
@ -163,12 +166,16 @@ class AliasAnalysisTest extends CompilerTest {
}
"correctly find the scopes in which a given symbol occurs" in {
complexScope.scopesForSymbol[Occurrence.Def]("a").length shouldEqual 1
complexScope.scopesForSymbol[Occurrence.Use]("a").length shouldEqual 1
complexScope
.scopesForSymbol[GraphOccurrence.Def]("a")
.length shouldEqual 1
complexScope
.scopesForSymbol[GraphOccurrence.Use]("a")
.length shouldEqual 1
complexScope.scopesForSymbol[Occurrence]("a").length shouldEqual 2
complexScope.scopesForSymbol[GraphOccurrence]("a").length shouldEqual 2
complexScope.scopesForSymbol[Occurrence]("a") shouldEqual List(
complexScope.scopesForSymbol[GraphOccurrence]("a") shouldEqual List(
complexScope,
childOfChildOfChild
)
@ -179,12 +186,17 @@ class AliasAnalysisTest extends CompilerTest {
}
"check correctly for specified occurrences of a symbol" in {
complexScope.hasSymbolOccurrenceAs[Occurrence.Def]("a") shouldEqual true
complexScope.hasSymbolOccurrenceAs[Occurrence]("b") shouldEqual false
complexScope.hasSymbolOccurrenceAs[GraphOccurrence.Def](
"a"
) shouldEqual true
complexScope.hasSymbolOccurrenceAs[GraphOccurrence]("b") shouldEqual false
}
"be able to convert from a symbol to identifiers that use it" in {
complexScope.symbolToIds[Occurrence]("a") shouldEqual List(aDefId, aUseId)
complexScope.symbolToIds[GraphOccurrence]("a") shouldEqual List(
aDefId,
aUseId
)
}
"be able to convert from an identifier to the associated symbol" in {
@ -221,19 +233,19 @@ class AliasAnalysisTest extends CompilerTest {
val childScope = rootScope.addChild()
val aDefId = graph.nextId()
val aDef = Occurrence.Def(aDefId, "a", genId, None)
val aDef = GraphOccurrence.Def(aDefId, "a", genId, None)
val bDefId = graph.nextId()
val bDef = Occurrence.Def(bDefId, "b", genId, None)
val bDef = GraphOccurrence.Def(bDefId, "b", genId, None)
val aUse1Id = graph.nextId()
val aUse1 = Occurrence.Use(aUse1Id, "a", genId, None)
val aUse1 = GraphOccurrence.Use(aUse1Id, "a", genId, None)
val aUse2Id = graph.nextId()
val aUse2 = Occurrence.Use(aUse2Id, "a", genId, None)
val aUse2 = GraphOccurrence.Use(aUse2Id, "a", genId, None)
val cUseId = graph.nextId()
val cUse = Occurrence.Use(cUseId, "c", genId, None)
val cUse = GraphOccurrence.Use(cUseId, "c", genId, None)
rootScope.add(aDef)
rootScope.add(aUse1)
@ -306,10 +318,10 @@ class AliasAnalysisTest extends CompilerTest {
}
"find all scopes where a given symbol occurs" in {
val aDefs = graph.scopesFor[Occurrence.Def]("a")
val aUses = graph.scopesFor[Occurrence.Use]("a")
val aOccs = graph.scopesFor[Occurrence]("a")
val dOccs = graph.scopesFor[Occurrence]("d")
val aDefs = graph.scopesFor[GraphOccurrence.Def]("a")
val aUses = graph.scopesFor[GraphOccurrence.Use]("a")
val aOccs = graph.scopesFor[GraphOccurrence]("a")
val dOccs = graph.scopesFor[GraphOccurrence]("d")
aDefs.length shouldEqual 1
aUses.length shouldEqual 2
@ -343,28 +355,28 @@ class AliasAnalysisTest extends CompilerTest {
val grandChild = child1.addChild()
val aDefInRootId = graph.nextId()
val aDefInRoot = Occurrence.Def(aDefInRootId, "a", genId, None)
val aDefInRoot = GraphOccurrence.Def(aDefInRootId, "a", genId, None)
rootScope.add(aDefInRoot)
val aDefInChild1Id = graph.nextId()
val aDefInChild1 = Occurrence.Def(aDefInChild1Id, "a", genId, None)
val aDefInChild1 = GraphOccurrence.Def(aDefInChild1Id, "a", genId, None)
child1.add(aDefInChild1)
val aDefInChild2Id = graph.nextId()
val aDefInChild2 = Occurrence.Def(aDefInChild2Id, "a", genId, None)
val aDefInChild2 = GraphOccurrence.Def(aDefInChild2Id, "a", genId, None)
child2.add(aDefInChild2)
val aDefInGrandChildId = graph.nextId()
val aDefInGrandChild =
Occurrence.Def(aDefInGrandChildId, "a", genId, None)
GraphOccurrence.Def(aDefInGrandChildId, "a", genId, None)
grandChild.add(aDefInGrandChild)
val bDefInRootId = graph.nextId()
val bDefInRoot = Occurrence.Def(bDefInRootId, "b", genId, None)
val bDefInRoot = GraphOccurrence.Def(bDefInRootId, "b", genId, None)
rootScope.add(bDefInRoot)
val bDefInChild2Id = graph.nextId()
val bDefInChild2 = Occurrence.Def(bDefInChild2Id, "b", genId, None)
val bDefInChild2 = GraphOccurrence.Def(bDefInChild2Id, "b", genId, None)
child2.add(bDefInChild2)
graph.knownShadowedDefinitions(aDefInGrandChild) shouldEqual Set(
@ -383,7 +395,7 @@ class AliasAnalysisTest extends CompilerTest {
}
"correctly return all links for a given symbol" in {
graph.linksFor[Occurrence]("a") shouldEqual Set(
graph.linksFor[GraphOccurrence]("a") shouldEqual Set(
use1Link.get,
use2Link.get
)
@ -413,7 +425,7 @@ class AliasAnalysisTest extends CompilerTest {
.members
.head
val goodMeta = goodAtom.getMetadata(AliasAnalysis)
val goodGraph = goodMeta.get.unsafeAs[Info.Scope.Root].graph
val goodGraph = goodMeta.get.unsafeAs[AliasMetadata.RootScope].graph
val badAtom =
"""
@ -424,29 +436,29 @@ class AliasAnalysisTest extends CompilerTest {
.members
.head
val badMeta = badAtom.getMetadata(AliasAnalysis)
val badGraph = badMeta.get.unsafeAs[Info.Scope.Root].graph
val badGraph = badMeta.get.unsafeAs[AliasMetadata.RootScope].graph
"assign Info.Scope.Root metadata to the atom" in {
goodMeta shouldBe defined
goodMeta.get shouldBe a[Info.Scope.Root]
goodMeta.get shouldBe a[AliasMetadata.RootScope]
}
"create definition occurrences in the atom's scope" in {
goodGraph.rootScope.hasSymbolOccurrenceAs[Occurrence.Def]("a")
goodGraph.rootScope.hasSymbolOccurrenceAs[Occurrence.Def]("b")
goodGraph.rootScope.hasSymbolOccurrenceAs[Occurrence.Def]("c")
goodGraph.rootScope.hasSymbolOccurrenceAs[GraphOccurrence.Def]("a")
goodGraph.rootScope.hasSymbolOccurrenceAs[GraphOccurrence.Def]("b")
goodGraph.rootScope.hasSymbolOccurrenceAs[GraphOccurrence.Def]("c")
}
"create defaults in the same scope as the argument" in {
goodGraph.nesting shouldEqual 1
goodGraph.rootScope.hasSymbolOccurrenceAs[Occurrence.Use]("a")
goodGraph.rootScope.hasSymbolOccurrenceAs[GraphOccurrence.Use]("a")
}
"create usage links where valid" in {
val aDefId = goodAtom.arguments.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val aUseId = goodAtom
.arguments(2)
@ -454,7 +466,7 @@ class AliasAnalysisTest extends CompilerTest {
.get
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
goodGraph.getLinks() should contain(Link(aUseId, 0, aDefId))
@ -481,7 +493,7 @@ class AliasAnalysisTest extends CompilerTest {
methodWithLambda
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
.graph
val graphLinks = methodWithLambdaGraph.getLinks()
@ -507,21 +519,21 @@ class AliasAnalysisTest extends CompilerTest {
val meta = methodWithLambda.getMetadata(AliasAnalysis)
meta shouldBe defined
meta.get shouldBe a[Info.Scope.Root]
meta.get shouldBe a[AliasMetadata.RootScope]
}
"assign Info.Scope.Child to all child scopes" in {
methodWithLambda.body
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
methodWithLambda.body
.asInstanceOf[Function.Lambda]
.body
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
methodWithLambda.body
.asInstanceOf[Function.Lambda]
@ -530,16 +542,16 @@ class AliasAnalysisTest extends CompilerTest {
.body
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
topLambdaBody
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
childLambda.body
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
}
"not allocate additional scopes unnecessarily" in {
@ -556,7 +568,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val cLamBlockScope =
@ -570,7 +582,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Expression.Block]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
cLamScope shouldEqual cLamBlockScope
@ -579,7 +591,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
aLamScope shouldEqual methodWithLambdaGraph.rootScope
@ -591,7 +603,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val bLambdaScope = methodWithLambda.body
@ -600,7 +612,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val cLambdaScope = methodWithLambda.body
@ -611,13 +623,13 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val mainBlockScope = topLambdaBody
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val dALambdaScope = topLambdaBody.expressions.head
@ -626,7 +638,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val gScope = topLambdaBody
@ -636,7 +648,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Expression.Block]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val cUseScope = topLambdaBody.returnValue
@ -646,7 +658,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[CallArgument.Specified]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
topScope.childScopes should contain(bLambdaScope)
@ -656,29 +668,36 @@ class AliasAnalysisTest extends CompilerTest {
mainBlockScope.childScopes should contain(cUseScope)
}
"assign Info.Occurrence to definitions and usages of symbols" in {
"assign Info.GraphOccurrence to definitions and usages of symbols" in {
topLambda.arguments.foreach(arg =>
arg.getMetadata(AliasAnalysis).get.as[Info.Occurrence] shouldBe defined
arg
.getMetadata(AliasAnalysis)
.get
.as[AliasMetadata.Occurrence] shouldBe defined
)
topLambdaBody.expressions.foreach(
_.asInstanceOf[Expression.Binding]
.getMetadata(AliasAnalysis)
.get
.as[Info.Occurrence] shouldBe defined
.as[AliasMetadata.Occurrence] shouldBe defined
)
childLambda.arguments.foreach(arg =>
arg.getMetadata(AliasAnalysis).get.as[Info.Occurrence] shouldBe defined
arg
.getMetadata(AliasAnalysis)
.get
.as[AliasMetadata.Occurrence] shouldBe defined
)
childLambdaBody.function
.getMetadata(AliasAnalysis)
.get
.as[Info.Occurrence] shouldBe defined
.as[AliasMetadata.Occurrence] shouldBe defined
childLambdaBody.arguments.foreach(
_.getMetadata(AliasAnalysis).get.as[Info.Scope.Child] shouldBe defined
_.getMetadata(AliasAnalysis).get
.as[AliasMetadata.ChildScope] shouldBe defined
)
}
@ -692,14 +711,14 @@ class AliasAnalysisTest extends CompilerTest {
.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val nestedLambdaADefId =
childLambda.arguments.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val nestedLambdaBDefId =
childLambda.body
@ -708,7 +727,7 @@ class AliasAnalysisTest extends CompilerTest {
.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val nestedLambdaAUseId = childLambdaBody
@ -716,7 +735,7 @@ class AliasAnalysisTest extends CompilerTest {
.function
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val nestedLambdaBUseId = childLambdaBody
@ -727,21 +746,21 @@ class AliasAnalysisTest extends CompilerTest {
.value
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val dDefId = topLambdaBody.expressions.head
.asInstanceOf[Expression.Binding]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val dUseId = topLambdaBody.returnValue
.asInstanceOf[Application.Prefix]
.function
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val dDefCUseId = topLambdaBody.returnValue
.asInstanceOf[Application.Prefix]
@ -751,7 +770,7 @@ class AliasAnalysisTest extends CompilerTest {
.value
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
graphLinks should contain(Link(nestedLambdaAUseId, 1, nestedLambdaADefId))
@ -772,13 +791,13 @@ class AliasAnalysisTest extends CompilerTest {
.function
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
methodWithLambdaGraph.linksFor(unknownPlusId) shouldBe empty
methodWithLambdaGraph
.getOccurrence(unknownPlusId)
.get shouldBe an[Occurrence.Use]
.get shouldBe an[GraphOccurrence.Use]
}
}
@ -798,28 +817,28 @@ class AliasAnalysisTest extends CompilerTest {
methodWithBlock
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
.graph
"assign Info.Scope.Root metadata to the method" in {
val meta1 = methodWithBlock.getMetadata(AliasAnalysis)
meta1 shouldBe defined
meta1.get shouldBe a[Info.Scope.Root]
meta1.get shouldBe a[AliasMetadata.RootScope]
}
"assign Info.Scope.Child to all child scopes" in {
methodWithBlock.body
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
methodWithBlock.body
.asInstanceOf[Function.Lambda]
.body
.asInstanceOf[Expression.Block]
.getMetadata(AliasAnalysis)
.get shouldBe an[Info.Scope.Child]
.get shouldBe an[AliasMetadata.ChildScope]
}
"not allocate additional scopes unnecessarily" in {
@ -831,7 +850,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Function.Lambda]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val blockChildBlockScope =
methodWithBlock.body
@ -840,7 +859,7 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Expression.Block]
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
blockChildBlockScope shouldEqual methodWithBlockGraph.rootScope
@ -861,7 +880,7 @@ class AliasAnalysisTest extends CompilerTest {
val graph = addMethod
.unsafeGetMetadata(AliasAnalysis, "Missing aliasing info")
.unsafeAs[Info.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
.graph
val graphLinks = graph.getLinks()
@ -879,7 +898,7 @@ class AliasAnalysisTest extends CompilerTest {
val lambdaScope = lambda
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
topScope shouldEqual lambdaScope
@ -889,7 +908,7 @@ class AliasAnalysisTest extends CompilerTest {
.arguments(1)
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
lambda.body shouldBe an[Application.Prefix]
val app = lambda.body.asInstanceOf[Application.Prefix]
@ -898,7 +917,7 @@ class AliasAnalysisTest extends CompilerTest {
.value
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
// No link between self.x and self
graphLinks shouldEqual Set(Link(valueUseId, 1, valueDefId))
@ -910,7 +929,7 @@ class AliasAnalysisTest extends CompilerTest {
val lambdaScope = lambda
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
lambdaScope.allDefinitions.length shouldBe 2
@ -931,7 +950,7 @@ class AliasAnalysisTest extends CompilerTest {
val graph = conversionMethod
.unsafeGetMetadata(AliasAnalysis, "Missing aliasing info")
.unsafeAs[Info.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
.graph
val graphLinks = graph.getLinks()
@ -943,12 +962,16 @@ class AliasAnalysisTest extends CompilerTest {
val meta = conversionMethod.getMetadata(AliasAnalysis)
meta shouldBe defined
meta.get shouldBe an[Info.Scope.Root]
meta.get shouldBe an[AliasMetadata.RootScope]
}
"assign Info.Scope.Child to all child scopes" in {
lambda.getMetadata(AliasAnalysis).get shouldBe an[Info.Scope.Child]
lambdaBody.getMetadata(AliasAnalysis).get shouldBe an[Info.Scope.Child]
lambda
.getMetadata(AliasAnalysis)
.get shouldBe an[AliasMetadata.ChildScope]
lambdaBody
.getMetadata(AliasAnalysis)
.get shouldBe an[AliasMetadata.ChildScope]
}
"not allocate additional scopes unnecessarily" in {
@ -959,12 +982,12 @@ class AliasAnalysisTest extends CompilerTest {
val lambdaScope = lambda
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val blockScope = lambdaBody
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
topScope shouldEqual lambdaScope
@ -976,22 +999,25 @@ class AliasAnalysisTest extends CompilerTest {
val arg1Scope = app.arguments.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val arg2Scope = app
.arguments(1)
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
topScope.childScopes should contain(arg1Scope)
topScope.childScopes should contain(arg2Scope)
}
"assign Info.Occurrence to definitions and usages of symbols" in {
"assign Info.GraphOccurrence to definitions and usages of symbols" in {
lambda.arguments.foreach(arg =>
arg.getMetadata(AliasAnalysis).get.as[Info.Occurrence] shouldBe defined
arg
.getMetadata(AliasAnalysis)
.get
.as[AliasMetadata.Occurrence] shouldBe defined
)
val firstAppArg =
app.arguments.head.value.asInstanceOf[Application.Prefix]
@ -999,7 +1025,7 @@ class AliasAnalysisTest extends CompilerTest {
innerAppArg
.getMetadata(AliasAnalysis)
.get
.as[Info.Occurrence] shouldBe defined
.as[AliasMetadata.Occurrence] shouldBe defined
}
"create the correct usage links for resolvable entities" in {
@ -1007,7 +1033,7 @@ class AliasAnalysisTest extends CompilerTest {
.arguments(1)
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val valueUseId = app.arguments.head.value
.asInstanceOf[Application.Prefix]
@ -1016,7 +1042,7 @@ class AliasAnalysisTest extends CompilerTest {
.value
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
graphLinks should contain(Link(valueUseId, 2, valueDefId))
@ -1028,11 +1054,11 @@ class AliasAnalysisTest extends CompilerTest {
.value
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
graph.linksFor(unknownHereId) shouldBe empty
graph.getOccurrence(unknownHereId).get shouldBe an[Occurrence.Use]
graph.getOccurrence(unknownHereId).get shouldBe an[GraphOccurrence.Use]
}
}
@ -1058,21 +1084,21 @@ class AliasAnalysisTest extends CompilerTest {
val graph = methodWithCase
.getMetadata(AliasAnalysis)
.get
.as[Info.Scope.Root]
.as[AliasMetadata.RootScope]
.get
.graph
"expose the scrutinee in the parent scope" in {
val scrutBindingId = scrutBinding
.unsafeGetMetadata(AliasAnalysis, "")
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
graph.rootScope.getOccurrence(scrutBindingId) shouldBe defined
val scrutineeId = caseExpr.scrutinee
.getMetadata(AliasAnalysis)
.get
.as[Info.Occurrence]
.as[AliasMetadata.Occurrence]
.get
.id
graph.rootScope.getOccurrence(scrutineeId) shouldBe defined
@ -1081,7 +1107,7 @@ class AliasAnalysisTest extends CompilerTest {
val scrutBindingExprId = scrutBindingExpr
.unsafeGetMetadata(AliasAnalysis, "")
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
graph.rootScope.getOccurrence(scrutBindingExprId) shouldBe defined
@ -1089,7 +1115,7 @@ class AliasAnalysisTest extends CompilerTest {
.arguments(1)
.getMetadata(AliasAnalysis)
.get
.as[Info.Occurrence]
.as[AliasMetadata.Occurrence]
.get
.id
graph.rootScope.getOccurrence(aDefId) shouldBe defined
@ -1101,28 +1127,28 @@ class AliasAnalysisTest extends CompilerTest {
val consBranchScope = caseExpr.branches.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val nilBranchScope =
caseExpr
.branches(1)
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val tpeBranchScope =
caseExpr
.branches(2)
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val fallbackBranchScope =
caseExpr
.branches(3)
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
val rootScope = graph.rootScope
@ -1137,7 +1163,7 @@ class AliasAnalysisTest extends CompilerTest {
val consBranchScope = caseExpr.branches.head
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
.scope
consBranchScope.allDefinitions.length shouldBe 2
@ -1158,14 +1184,14 @@ class AliasAnalysisTest extends CompilerTest {
consBranchADef
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val consBranchBDef = pattern.fields(1).asInstanceOf[Pattern.Name].name
val consBranchBDefId = consBranchBDef
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val aUse = body.arguments.head
@ -1173,7 +1199,11 @@ class AliasAnalysisTest extends CompilerTest {
.value
.asInstanceOf[Name.Literal]
val aUseId =
aUse.getMetadata(AliasAnalysis).get.unsafeAs[Info.Occurrence].id
aUse
.getMetadata(AliasAnalysis)
.get
.unsafeAs[AliasMetadata.Occurrence]
.id
val bUse = body
.arguments(1)
@ -1181,7 +1211,11 @@ class AliasAnalysisTest extends CompilerTest {
.value
.asInstanceOf[Name.Literal]
val bUseId =
bUse.getMetadata(AliasAnalysis).get.unsafeAs[Info.Occurrence].id
bUse
.getMetadata(AliasAnalysis)
.get
.unsafeAs[AliasMetadata.Occurrence]
.id
graph.getLinks() should contain(Link(aUseId, 1, consBranchADefId))
graph.getLinks() should contain(Link(bUseId, 1, consBranchBDefId))
@ -1198,13 +1232,13 @@ class AliasAnalysisTest extends CompilerTest {
tpeBranchNameDef
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val tpeBranchTpeDefId =
tpeTpeBranchTpeDef
.getMetadata(AliasAnalysis)
.get
.unsafeAs[Info.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
.id
val numUse = body
@ -1213,7 +1247,11 @@ class AliasAnalysisTest extends CompilerTest {
.value
.asInstanceOf[Name.Literal]
val numUseId =
numUse.getMetadata(AliasAnalysis).get.unsafeAs[Info.Occurrence].id
numUse
.getMetadata(AliasAnalysis)
.get
.unsafeAs[AliasMetadata.Occurrence]
.id
val integerUse = body
.arguments(1)
@ -1221,7 +1259,11 @@ class AliasAnalysisTest extends CompilerTest {
.value
.asInstanceOf[Name.Literal]
val integerUseId =
integerUse.getMetadata(AliasAnalysis).get.unsafeAs[Info.Occurrence].id
integerUse
.getMetadata(AliasAnalysis)
.get
.unsafeAs[AliasMetadata.Occurrence]
.id
graph.getLinks() should contain(Link(numUseId, 1, tpeBranchNameDefId))
graph.getLinks() should not contain (Link(
@ -1248,7 +1290,9 @@ class AliasAnalysisTest extends CompilerTest {
.asInstanceOf[Expression.Block]
val blockScope =
block.unsafeGetMetadata(AliasAnalysis, "").unsafeAs[Info.Scope.Child]
block
.unsafeGetMetadata(AliasAnalysis, "")
.unsafeAs[AliasMetadata.ChildScope]
"create a new scope for the literal" in {
if (!block.returnValue.isInstanceOf[errors.Syntax]) {
@ -1257,7 +1301,7 @@ class AliasAnalysisTest extends CompilerTest {
val literalScope =
literal
.unsafeGetMetadata(AliasAnalysis, "")
.unsafeAs[Info.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
blockScope.scope.childScopes should contain(literalScope.scope)
}
}

View File

@ -45,18 +45,16 @@ import org.enso.compiler.core.ir.module.scope.definition.Method
import org.enso.compiler.data.BindingsMap.{ResolvedConstructor, ResolvedModule}
import org.enso.compiler.data.{BindingsMap, CompilerConfig}
import org.enso.compiler.exception.BadPatternMatch
import org.enso.compiler.pass.analyse.alias.Graph.{Scope => AliasScope}
import org.enso.compiler.pass.analyse.alias.Info.Scope
import org.enso.compiler.pass.analyse.alias.graph.Graph.{Scope => AliasScope}
import org.enso.compiler.pass.analyse.{
alias,
AliasAnalysis,
BindingAnalysis,
DataflowAnalysis,
TailCall
}
import org.enso.compiler.pass.analyse.alias.{
Graph => AliasGraph,
Info => AliasInfo
}
import org.enso.compiler.pass.analyse.alias.AliasMetadata
import org.enso.compiler.pass.analyse.alias.graph.{Graph => AliasGraph}
import org.enso.compiler.pass.resolve.{
ExpressionAnnotations,
GenericAnnotations,
@ -277,7 +275,7 @@ class IrToTruffle(
AliasAnalysis,
"No root scope on an atom definition."
)
.unsafeAs[AliasInfo.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = atomDefn.unsafeGetMetadata(
DataflowAnalysis,
@ -309,7 +307,7 @@ class IrToTruffle(
AliasAnalysis,
"No occurrence on an argument definition."
)
.unsafeAs[AliasInfo.Occurrence]
.unsafeAs[alias.AliasMetadata.Occurrence]
val slotIdx = localScope.getVarSlotIdx(occInfo.id)
argDefs(idx) = arg
val readArg =
@ -382,7 +380,7 @@ class IrToTruffle(
s"Missing scope information for method " +
s"`${methodDef.typeName.map(_.name + ".").getOrElse("")}${methodDef.methodName.name}`."
)
.unsafeAs[AliasInfo.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = methodDef.unsafeGetMetadata(
DataflowAnalysis,
"Method definition missing dataflow information."
@ -559,7 +557,7 @@ class IrToTruffle(
scopeElements.init
.mkString(Constants.SCOPE_SEPARATOR)
)
.unsafeAs[Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = annotation.unsafeGetMetadata(
DataflowAnalysis,
"Missing dataflow information for annotation " +
@ -776,7 +774,7 @@ class IrToTruffle(
s"Missing scope information for conversion " +
s"`${methodDef.typeName.map(_.name + ".").getOrElse("")}${methodDef.methodName.name}`."
)
.unsafeAs[AliasInfo.Scope.Root]
.unsafeAs[AliasMetadata.RootScope]
val dataflowInfo = methodDef.unsafeGetMetadata(
DataflowAnalysis,
"Method definition missing dataflow information."
@ -1340,7 +1338,7 @@ class IrToTruffle(
AliasAnalysis,
"Missing scope information on block."
)
.unsafeAs[AliasInfo.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
val childFactory = this.createChild(
"suspended-block",
@ -1454,7 +1452,7 @@ class IrToTruffle(
AliasAnalysis,
"No scope information on a case branch."
)
.unsafeAs[AliasInfo.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
val childProcessor =
this.createChild(
@ -1830,7 +1828,7 @@ class IrToTruffle(
AliasAnalysis,
"Binding with missing occurrence information."
)
.unsafeAs[AliasInfo.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
currentVarName = binding.name.name
@ -1854,7 +1852,7 @@ class IrToTruffle(
): RuntimeExpression = {
val scopeInfo = function
.unsafeGetMetadata(AliasAnalysis, "No scope info on a function.")
.unsafeAs[AliasInfo.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
if (function.body.isInstanceOf[Function]) {
throw new CompilerError(
@ -1949,7 +1947,7 @@ class IrToTruffle(
private class RuntimeNameResolution
extends NameResolutionAlgorithm[RuntimeExpression, FramePointer] {
override protected def findLocalLink(
occurrenceMetadata: org.enso.compiler.pass.analyse.alias.Info.Occurrence
occurrenceMetadata: org.enso.compiler.pass.analyse.alias.AliasMetadata.Occurrence
): Option[FramePointer] =
scope.getFramePointer(occurrenceMetadata.id)
@ -2198,7 +2196,7 @@ class IrToTruffle(
AliasAnalysis,
"No occurrence on an argument definition."
)
.unsafeAs[AliasInfo.Occurrence]
.unsafeAs[AliasMetadata.Occurrence]
val slotIdx = scope.getVarSlotIdx(occInfo.id)
val readArg =
@ -2432,7 +2430,7 @@ class IrToTruffle(
AliasAnalysis,
"No scope attached to a call argument."
)
.unsafeAs[AliasInfo.Scope.Child]
.unsafeAs[AliasMetadata.ChildScope]
def valueHasSomeTypeCheck() =
value.getMetadata(TypeSignatures).isDefined