From a1f903964980d2425a27ab7094b174eb880e70c4 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 25 Apr 2023 15:35:18 +0200 Subject: [PATCH] more shedding --- .../interpreter/runtime/data/ArraySlice.java | 1 - .../enso/interpreter/runtime/data/Vector.java | 1 - .../runtime/error/WarningsLibrary.java | 1 - .../runtime/error/WithWarnings.java | 29 ------------ .../enso/interpreter/test/WarningsTest.java | 45 +++++++++++++++++-- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java index 5415f53fc3b44..cca1a46d29334 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java @@ -14,7 +14,6 @@ import org.enso.interpreter.runtime.error.Warning; import org.enso.interpreter.runtime.error.WarningsLibrary; import org.enso.interpreter.runtime.error.WithWarnings; -import org.graalvm.collections.EconomicSet; @ExportLibrary(InteropLibrary.class) @ExportLibrary(WarningsLibrary.class) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java index 0569618726183..494651cf8ebef 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java @@ -22,7 +22,6 @@ import org.enso.interpreter.runtime.error.WarningsLibrary; import org.enso.interpreter.runtime.error.WithWarnings; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; -import org.graalvm.collections.EconomicSet; @ExportLibrary(InteropLibrary.class) @ExportLibrary(TypesLibrary.class) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WarningsLibrary.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WarningsLibrary.java index c1f12ac12cc34..31fc820d917d3 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WarningsLibrary.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WarningsLibrary.java @@ -5,7 +5,6 @@ import com.oracle.truffle.api.library.Library; import com.oracle.truffle.api.library.LibraryFactory; import com.oracle.truffle.api.nodes.Node; -import org.graalvm.collections.EconomicSet; @GenerateLibrary public abstract class WarningsLibrary extends Library { diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WithWarnings.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WithWarnings.java index 9e0e650960720..4a291277910fd 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WithWarnings.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/WithWarnings.java @@ -31,12 +31,6 @@ private WithWarnings(Object value, Warning... warnings) { this.value = value; } - private WithWarnings(Object value, EconomicSet warnings) { - assert !(value instanceof WithWarnings); - this.warnings = cloneSet(warnings); - this.value = value; - } - private WithWarnings(Object value, EconomicSet warnings, Warning... additionalWarnings) { assert !(value instanceof WithWarnings); this.warnings = cloneSetAndAppend(warnings, additionalWarnings); @@ -57,14 +51,6 @@ public static WithWarnings wrap(Object value, Warning... warnings) { } } - public static WithWarnings wrap(Object value, EconomicSet warnings) { - if (value instanceof WithWarnings with) { - return with.append(warnings); - } else { - return new WithWarnings(value, warnings); - } - } - public Object getValue() { return value; } @@ -73,10 +59,6 @@ public WithWarnings append(Warning... newWarnings) { return new WithWarnings(value, warnings, newWarnings); } - public WithWarnings append(EconomicSet newWarnings) { - return new WithWarnings(value, warnings, newWarnings); - } - public WithWarnings prepend(ArrayRope newWarnings) { return new WithWarnings(value, createSetFromArray(newWarnings.toArray(Warning[]::new)), warnings); } @@ -115,10 +97,6 @@ public ArrayRope getReassignedWarningsAsRope(Node location) { return new ArrayRope<>(getReassignedWarnings(location, null)); } - public Warning[] getReassignedWarnings(Node location) { - return getReassignedWarnings(location, null); - } - public Warning[] getReassignedWarnings(Node location, WarningsLibrary warningsLibrary) { Warning[] warnings = getWarningsArray(warningsLibrary); for (int i = 0; i < warnings.length; i++) { @@ -236,11 +214,4 @@ private EconomicSet cloneSetAndAppend(EconomicSet initial, Eco return set; } - @CompilerDirectives.TruffleBoundary - @SuppressWarnings("unchecked") - private EconomicSet cloneSet(EconomicSet initial) { - EconomicSet set = EconomicSet.create(new WarningEquivalence()); - set.addAll(initial.iterator()); - return set; - } } diff --git a/engine/runtime/src/test/java/org/enso/interpreter/test/WarningsTest.java b/engine/runtime/src/test/java/org/enso/interpreter/test/WarningsTest.java index fbbe272005cc6..cf63411846f0c 100644 --- a/engine/runtime/src/test/java/org/enso/interpreter/test/WarningsTest.java +++ b/engine/runtime/src/test/java/org/enso/interpreter/test/WarningsTest.java @@ -1,17 +1,54 @@ package org.enso.interpreter.test; +import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.error.Warning; import org.enso.interpreter.runtime.error.WarningsLibrary; import org.enso.interpreter.runtime.error.WithWarnings; -import org.junit.Assert; +import org.enso.polyglot.LanguageInfo; +import org.enso.polyglot.MethodNames; +import org.enso.polyglot.RuntimeOptions; +import org.graalvm.polyglot.Context; +import org.junit.*; + import static org.junit.Assert.assertEquals; -import org.junit.Test; +import static org.junit.Assert.assertNotNull; + +import java.io.OutputStream; +import java.nio.file.Paths; public class WarningsTest { + + private static Context ctx; + + @BeforeClass + public static void initEnsoContext() { + ctx = + Context.newBuilder() + .allowExperimentalOptions(true) + .allowIO(true) + .option( + RuntimeOptions.LANGUAGE_HOME_OVERRIDE, + Paths.get("../../distribution/component").toFile().getAbsolutePath()) + .logHandler(OutputStream.nullOutputStream()) + .allowAllAccess(true) + .build(); + assertNotNull("Enso language is supported", ctx.getEngine().getLanguages().get("enso")); + } + + @AfterClass + public static void disposeContext() { + ctx.close(); + } + @Test public void doubleWithWarningsWrap() { - var warn1 = new Warning("w1", this, 1L); - var warn2 = new Warning("w2", this, 2L); + var ensoContext = + (EnsoContext) + ctx.getBindings(LanguageInfo.ID) + .invokeMember(MethodNames.TopScope.LEAK_CONTEXT) + .asHostObject(); + var warn1 = Warning.create(ensoContext, "w1", this); + var warn2 = Warning.create(ensoContext, "w2", this); var value = 42; var with1 = WithWarnings.wrap(42, warn1);