Skip to content

Commit

Permalink
more shedding
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertp committed Apr 25, 2023
1 parent 5751b02 commit a1f9039
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ private WithWarnings(Object value, Warning... warnings) {
this.value = value;
}

private WithWarnings(Object value, EconomicSet<Warning> warnings) {
assert !(value instanceof WithWarnings);
this.warnings = cloneSet(warnings);
this.value = value;
}

private WithWarnings(Object value, EconomicSet<Warning> warnings, Warning... additionalWarnings) {
assert !(value instanceof WithWarnings);
this.warnings = cloneSetAndAppend(warnings, additionalWarnings);
Expand All @@ -57,14 +51,6 @@ public static WithWarnings wrap(Object value, Warning... warnings) {
}
}

public static WithWarnings wrap(Object value, EconomicSet<Warning> warnings) {
if (value instanceof WithWarnings with) {
return with.append(warnings);
} else {
return new WithWarnings(value, warnings);
}
}

public Object getValue() {
return value;
}
Expand All @@ -73,10 +59,6 @@ public WithWarnings append(Warning... newWarnings) {
return new WithWarnings(value, warnings, newWarnings);
}

public WithWarnings append(EconomicSet<Warning> newWarnings) {
return new WithWarnings(value, warnings, newWarnings);
}

public WithWarnings prepend(ArrayRope<Warning> newWarnings) {
return new WithWarnings(value, createSetFromArray(newWarnings.toArray(Warning[]::new)), warnings);
}
Expand Down Expand Up @@ -115,10 +97,6 @@ public ArrayRope<Warning> 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++) {
Expand Down Expand Up @@ -236,11 +214,4 @@ private EconomicSet<Warning> cloneSetAndAppend(EconomicSet<Warning> initial, Eco
return set;
}

@CompilerDirectives.TruffleBoundary
@SuppressWarnings("unchecked")
private EconomicSet<Warning> cloneSet(EconomicSet<Warning> initial) {
EconomicSet<Warning> set = EconomicSet.create(new WarningEquivalence());
set.addAll(initial.iterator());
return set;
}
}
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit a1f9039

Please sign in to comment.