Skip to content

Commit

Permalink
assert cached value is the same as really expected one
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Aug 28, 2024
1 parent 0a37ddf commit 2765faf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.enso.compiler.context;

import java.util.Objects;
import java.util.function.Supplier;

/**
* A representation of a pointer into a stack frame at a given number of levels above the current.
*/
Expand All @@ -9,4 +12,10 @@ public record FramePointer(int parentLevel, int frameSlotIdx) {
assert parentLevel >= 0;
assert frameSlotIdx >= 0;
}

static <V> V assertSame(String msg, V actual, Supplier<V> expectedSupplier) {
assert Objects.equals(expectedSupplier.get(), actual)
: msg + "\nexpected: " + expectedSupplier.get() + "\nactual: " + actual;
return actual;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ class LocalScope(
lazy val scope: AliasGraph.Scope = scopeProvider()
lazy val dataflowInfo: DataflowAnalysis.Metadata = dataflowInfoProvider()
def allSymbols(where: String): List[String] = {
if (symbolsProvider != null) {
val meta = symbolsProvider()
if (meta != null && meta.variableNames.isDefined) {
return meta.variableNames.get
}
def symbols() = scope.allDefinitions.map(_.symbol)
val meta = if (symbolsProvider == null) null else symbolsProvider()
if (meta != null && meta.variableNames.isDefined) {
val cached = meta.variableNames.get
FramePointer.assertSame(where, cached, () => symbols())
} else {
val result = symbols()
System.err.println(
"BAD!!!! Computing from scope at " + where + " = " + result
)
result
}
val symbols = scope.allDefinitions.map(_.symbol)
System.err.println(
"BAD!!!! Computing from scope at " + where + " = " + symbols
)
symbols
}

private lazy val localFrameSlotIdxs: Map[AliasGraph.Id, Int] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ class IrToTruffle(
)
.unsafeAs[AliasMetadata.RootScope]

new Exception(
System.err.println(
"Method defintions[" + methodDef.methodReference.name + "]: " + s.graph.rootScope.allDefinitions
).printStackTrace()
)
s
}
def dataflowInfo() = methodDef.unsafeGetMetadata(
Expand Down

0 comments on commit 2765faf

Please sign in to comment.