Skip to content

Commit

Permalink
Rewriting MetadataStorage into Java (#8366)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Nov 27, 2023
1 parent 893965e commit 7a9a5ba
Show file tree
Hide file tree
Showing 60 changed files with 794 additions and 644 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ case object AliasAnalysis extends IRPass {
case occ: Info.Occurrence =>
occ.copy(graph = copyRootScopeGraph)
}
copyNode.updateMetadata(this -->> newMeta)
copyNode.updateMetadata(new MetadataPair(this, newMeta))
case None =>
}
}
Expand Down Expand Up @@ -243,7 +243,9 @@ case object AliasAnalysis extends IRPass {
topLevelGraph.rootScope,
lambdaReuseScope = true
)
).updateMetadata(this -->> Info.Scope.Root(topLevelGraph))
).updateMetadata(
new MetadataPair(this, Info.Scope.Root(topLevelGraph))
)
case _ =>
throw new CompilerError(
"The body of a method should always be a function."
Expand All @@ -259,7 +261,9 @@ case object AliasAnalysis extends IRPass {
topLevelGraph.rootScope,
lambdaReuseScope = true
)
).updateMetadata(this -->> Info.Scope.Root(topLevelGraph))
).updateMetadata(
new MetadataPair(this, Info.Scope.Root(topLevelGraph))
)
case _ =>
throw new CompilerError(
"The body of a method should always be a function."
Expand Down Expand Up @@ -293,11 +297,13 @@ case object AliasAnalysis extends IRPass {
topLevelGraph.rootScope
)
)
.updateMetadata(this -->> Info.Scope.Root(topLevelGraph))
.updateMetadata(
new MetadataPair(this, Info.Scope.Root(topLevelGraph))
)
}
).updateMetadata(this -->> Info.Scope.Root(graph))
).updateMetadata(new MetadataPair(this, Info.Scope.Root(graph)))
})
).updateMetadata(this -->> Info.Scope.Root(topLevelGraph))
).updateMetadata(new MetadataPair(this, Info.Scope.Root(topLevelGraph)))
case _: Definition.SugaredType =>
throw new CompilerError(
"Complex type definitions should not be present during " +
Expand Down Expand Up @@ -326,7 +332,9 @@ case object AliasAnalysis extends IRPass {
topLevelGraph.rootScope
)
)
.updateMetadata(this -->> Info.Scope.Root(topLevelGraph))
.updateMetadata(
new MetadataPair(this, Info.Scope.Root(topLevelGraph))
)
case err: Error => err
}
}
Expand Down Expand Up @@ -390,7 +398,9 @@ case object AliasAnalysis extends IRPass {
currentScope
)
)
.updateMetadata(this -->> Info.Scope.Child(graph, currentScope))
.updateMetadata(
new MetadataPair(this, Info.Scope.Child(graph, currentScope))
)
case binding @ Expression.Binding(name, expression, _, _, _) =>
if (!parentScope.hasSymbolOccurrenceAs[Occurrence.Def](name.name)) {
val isSuspended = expression match {
Expand Down Expand Up @@ -418,7 +428,9 @@ case object AliasAnalysis extends IRPass {
parentScope
)
)
.updateMetadata(this -->> Info.Occurrence(graph, occurrenceId))
.updateMetadata(
new MetadataPair(this, Info.Occurrence(graph, occurrenceId))
)
} else {
errors.Redefined.Binding(binding)
}
Expand Down Expand Up @@ -467,7 +479,9 @@ case object AliasAnalysis extends IRPass {
memberType = analyseExpression(memberType, graph, memberTypeScope),
value = analyseExpression(value, graph, valueScope)
)
.updateMetadata(this -->> Info.Occurrence(graph, labelId))
.updateMetadata(
new MetadataPair(this, Info.Occurrence(graph, labelId))
)
case x =>
x.mapExpressions(analyseExpression(_, graph, parentScope))
}
Expand Down Expand Up @@ -515,7 +529,9 @@ case object AliasAnalysis extends IRPass {
)
scope.addDefinition(definition)
arg
.updateMetadata(this -->> Info.Occurrence(graph, occurrenceId))
.updateMetadata(
new MetadataPair(this, Info.Occurrence(graph, occurrenceId))
)
.copy(
ascribedType =
arg.ascribedType.map(analyseExpression(_, graph, scope))
Expand Down Expand Up @@ -553,7 +569,9 @@ case object AliasAnalysis extends IRPass {
ascribedType =
arg.ascribedType.map(analyseExpression(_, graph, scope))
)
.updateMetadata(this -->> Info.Occurrence(graph, occurrenceId))
.updateMetadata(
new MetadataPair(this, Info.Occurrence(graph, occurrenceId))
)
} else {
throw new CompilerError(
s"""
Expand Down Expand Up @@ -591,7 +609,9 @@ case object AliasAnalysis extends IRPass {
val newScope = scope.addChild()
tSet
.copy(expression = expr.map(analyseExpression(_, graph, newScope)))
.updateMetadata(this -->> Info.Scope.Child(graph, newScope))
.updateMetadata(
new MetadataPair(this, Info.Scope.Child(graph, newScope))
)
case _: Operator.Binary =>
throw new CompilerError(
"Binary operator occurred during Alias Analysis."
Expand Down Expand Up @@ -622,7 +642,9 @@ case object AliasAnalysis extends IRPass {
}
arg
.copy(value = analyseExpression(expr, graph, currentScope))
.updateMetadata(this -->> Info.Scope.Child(graph, currentScope))
.updateMetadata(
new MetadataPair(this, Info.Scope.Child(graph, currentScope))
)
}
}

Expand Down Expand Up @@ -655,7 +677,9 @@ case object AliasAnalysis extends IRPass {
currentScope
)
)
.updateMetadata(this -->> Info.Scope.Child(graph, currentScope))
.updateMetadata(
new MetadataPair(this, Info.Scope.Child(graph, currentScope))
)
case _: Function.Binding =>
throw new CompilerError(
"Function sugar should not be present during alias analysis."
Expand Down Expand Up @@ -698,7 +722,9 @@ case object AliasAnalysis extends IRPass {
graph.resolveGlobalUsage(occurrence)
}
}
name.updateMetadata(this -->> Info.Occurrence(graph, occurrenceId))
name.updateMetadata(
new MetadataPair(this, Info.Occurrence(graph, occurrenceId))
)
}

/** Performs alias analysis on a case expression.
Expand Down Expand Up @@ -748,7 +774,9 @@ case object AliasAnalysis extends IRPass {
currentScope
)
)
.updateMetadata(this -->> Info.Scope.Child(graph, currentScope))
.updateMetadata(
new MetadataPair(this, Info.Scope.Child(graph, currentScope))
)
}

/** Performs alias analysis on a pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.enso.compiler.pass.analyse

import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
import org.enso.compiler.core.Implicits.AsMetadata
import org.enso.compiler.core.ir.MetadataStorage.MetadataPair
import org.enso.compiler.core.ir.{
CallArgument,
Expression,
Expand All @@ -10,7 +11,6 @@ import org.enso.compiler.core.ir.{
Module,
Name
}
import org.enso.compiler.core.ir.MetadataStorage.ToPair
import org.enso.compiler.core.ir.module.scope.definition
import org.enso.compiler.data.BindingsMap.{Resolution, ResolvedMethod}
import org.enso.compiler.core.CompilerError
Expand Down Expand Up @@ -302,7 +302,9 @@ object AutomaticParallelism extends IRPass {
),
None
)
.updateMetadata(IgnoredBindings -->> IgnoredBindings.State.Ignored)
.updateMetadata(
new MetadataPair(IgnoredBindings, IgnoredBindings.State.Ignored)
)
)

val threadSpawns = threadBlocks.values.map { exprs =>
Expand Down Expand Up @@ -336,7 +338,9 @@ object AutomaticParallelism extends IRPass {
)
Expression
.Binding(freshNameSupply.newName(), spawn, None)
.updateMetadata(IgnoredBindings -->> IgnoredBindings.State.Ignored)
.updateMetadata(
new MetadataPair(IgnoredBindings, IgnoredBindings.State.Ignored)
)
}

val threadJoins = threadSpawns.map { bind =>
Expand All @@ -360,7 +364,9 @@ object AutomaticParallelism extends IRPass {
),
None
)
.updateMetadata(IgnoredBindings -->> IgnoredBindings.State.Ignored)
.updateMetadata(
new MetadataPair(IgnoredBindings, IgnoredBindings.State.Ignored)
)
}

List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.enso.compiler.core.ir.{Expression, Module, Name}
import org.enso.compiler.core.ir.module.scope.Definition
import org.enso.compiler.core.ir.module.scope.definition
import org.enso.compiler.core.ir.module.scope.imports
import org.enso.compiler.core.ir.MetadataStorage.ToPair
import org.enso.compiler.core.ir.MetadataStorage.MetadataPair
import org.enso.compiler.data.BindingsMap
import org.enso.compiler.data.BindingsMap.Cons
import org.enso.compiler.pass.IRPass
Expand Down Expand Up @@ -95,9 +95,12 @@ case object BindingAnalysis extends IRPass {
.flatten
.map(BindingsMap.ModuleMethod)
ir.updateMetadata(
this -->> BindingsMap(
definedSumTypes ++ importedPolyglot ++ moduleMethods,
moduleContext.moduleReference()
new MetadataPair(
this,
BindingsMap(
definedSumTypes ++ importedPolyglot ++ moduleMethods,
moduleContext.moduleReference()
)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ case object CachePreferenceAnalysis extends IRPass {
): Module = {
val weights = WeightInfo()
ir.copy(bindings = ir.bindings.map(analyseModuleDefinition(_, weights)))
.updateMetadata(this -->> weights)
.updateMetadata(new MetadataPair(this, weights))
}

/** Performs the cache preference analysis on an inline expression.
Expand Down Expand Up @@ -93,12 +93,12 @@ case object CachePreferenceAnalysis extends IRPass {
case method: definition.Method.Conversion =>
method
.copy(body = analyseExpression(method.body, weights))
.updateMetadata(this -->> weights)
.updateMetadata(new MetadataPair(this, weights))
case method @ definition.Method
.Explicit(_, body, _, _, _) =>
method
.copy(body = analyseExpression(body, weights))
.updateMetadata(this -->> weights)
.updateMetadata(new MetadataPair(this, weights))
case _: definition.Method.Binding =>
throw new CompilerError(
"Sugared method definitions should not occur during cache " +
Expand Down Expand Up @@ -145,10 +145,10 @@ case object CachePreferenceAnalysis extends IRPass {
.foreach(weights.update(_, Weight.Always))
binding
.copy(
name = binding.name.updateMetadata(this -->> weights),
name = binding.name.updateMetadata(new MetadataPair(this, weights)),
expression = analyseExpression(binding.expression, weights)
)
.updateMetadata(this -->> weights)
.updateMetadata(new MetadataPair(this, weights))
case error: Error =>
error
case expr =>
Expand All @@ -157,7 +157,7 @@ case object CachePreferenceAnalysis extends IRPass {
}
expr
.mapExpressions(analyseExpression(_, weights))
.updateMetadata(this -->> weights)
.updateMetadata(new MetadataPair(this, weights))
}
}

Expand All @@ -175,7 +175,7 @@ case object CachePreferenceAnalysis extends IRPass {
case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _, _) =>
spec
.copy(defaultValue = defValue.map(analyseExpression(_, weights)))
.updateMetadata(this -->> weights)
.updateMetadata(new MetadataPair(this, weights))
}
}

Expand Down
Loading

0 comments on commit 7a9a5ba

Please sign in to comment.