From 2678d35b35c6aa971b5c39e56c18eacbdf20402e Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Tue, 25 Apr 2023 17:05:28 +0200 Subject: [PATCH] remove prepend --- .../IndirectInvokeConversionNode.java | 2 +- .../callable/IndirectInvokeMethodNode.java | 2 +- .../node/callable/InvokeCallableNode.java | 2 +- .../node/callable/InvokeConversionNode.java | 2 +- .../node/callable/InvokeMethodNode.java | 4 +- .../interpreter/runtime/error/Warning.java | 2 +- .../runtime/error/WithWarnings.java | 39 +------------------ 7 files changed, 9 insertions(+), 44 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeConversionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeConversionNode.java index dfb62727b2417..d497adeee9d87 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeConversionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeConversionNode.java @@ -156,7 +156,7 @@ Object doWarning( argumentsExecutionMode, isTail, thatArgumentPosition); - return WithWarnings.prependTo(result, warnings); + return WithWarnings.appendTo(result, warnings); } @Specialization(guards = "interop.isString(that)") diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java index 6229e863bdf2a..79fafca1515cd 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/IndirectInvokeMethodNode.java @@ -134,7 +134,7 @@ Object doWarning( argumentsExecutionMode, isTail, thisArgumentPosition); - return WithWarnings.prependTo(result, warnings); + return WithWarnings.appendTo(result, warnings); } @Specialization diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeCallableNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeCallableNode.java index 8916c6a26f29b..f12789694ad50 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeCallableNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeCallableNode.java @@ -297,7 +297,7 @@ public Object invokeWarnings( if (result instanceof DataflowError) { return result; } else if (result instanceof WithWarnings withWarnings) { - return withWarnings.prepend(extracted); + return withWarnings.append(extracted); } else { return WithWarnings.wrap(result, extracted); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java index 1397e1176217b..3df215b17fb40 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeConversionNode.java @@ -175,7 +175,7 @@ Object doWarning( ArrayRope warnings = that.getReassignedWarningsAsRope(this); Object result = childDispatch.execute(frame, state, conversion, self, that.getValue(), arguments); - return WithWarnings.prependTo(result, warnings); + return WithWarnings.appendTo(result, warnings); } @Specialization(guards = "interop.isString(that)") diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java index 74a672bd9fa88..fa58b5875a5fe 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java @@ -275,7 +275,7 @@ Object doWarning( arguments[thisArgumentPosition] = selfWithoutWarnings; Object result = childDispatch.execute(frame, state, symbol, selfWithoutWarnings, arguments); - return WithWarnings.prependTo(result, arrOfWarnings); + return WithWarnings.appendTo(result, arrOfWarnings); } @ExplodeLoop @@ -327,7 +327,7 @@ Object doPolyglot( Object res = hostMethodCallNode.execute(polyglotCallType, symbol.getName(), self, args); if (anyWarnings) { anyWarningsProfile.enter(); - res = WithWarnings.prependTo(res, accumulatedWarnings); + res = WithWarnings.appendTo(res, accumulatedWarnings); } return res; } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java index a889adc824a73..696befeed81f5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/Warning.java @@ -74,7 +74,7 @@ public Array getReassignments() { @Builtin.Specialize public static WithWarnings attach( EnsoContext ctx, WithWarnings value, Object warning, Object origin) { - return value.prepend(new Warning(warning, origin, ctx.clockTick())); + return value.append(new Warning(warning, origin, ctx.clockTick())); } @Builtin.Method( 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 4f401a75daef8..abd2631ccb0fc 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 @@ -37,12 +37,6 @@ private WithWarnings(Object value, EconomicSet warnings, Warning... add this.value = value; } - private WithWarnings(Object value, EconomicSet warnings, EconomicSet additionalWarnings) { - assert !(value instanceof WithWarnings); - this.warnings = cloneSetAndAppend(warnings, additionalWarnings); - this.value = value; - } - public static WithWarnings wrap(Object value, Warning... warnings) { if (value instanceof WithWarnings with) { return with.append(warnings); @@ -59,12 +53,8 @@ public WithWarnings append(Warning... newWarnings) { return new WithWarnings(value, warnings, newWarnings); } - public WithWarnings prepend(ArrayRope newWarnings) { - return new WithWarnings(value, createSetFromArray(newWarnings.toArray(Warning[]::new)), warnings); - } - - public WithWarnings prepend(Warning... newWarnings) { - return new WithWarnings(value, createSetFromArray(newWarnings), warnings); + public WithWarnings append(ArrayRope newWarnings) { + return new WithWarnings(value, warnings, newWarnings.toArray(Warning[]::new)); } public Warning[] getWarningsArray(WarningsLibrary warningsLibrary) { @@ -116,22 +106,6 @@ public static WithWarnings appendTo(Object target, Warning[] warnings) { } } - public static WithWarnings prependTo(Object target, ArrayRope warnings) { - if (target instanceof WithWarnings) { - return ((WithWarnings) target).prepend(warnings); - } else { - return new WithWarnings(target, warnings.toArray(Warning[]::new)); - } - } - - public static WithWarnings prependTo(Object target, Warning[] warnings) { - if (target instanceof WithWarnings) { - return ((WithWarnings) target).prepend(warnings); - } else { - return new WithWarnings(target, warnings); - } - } - @ExportMessage Object send(Message message, Object[] args, @CachedLibrary(limit = "3") ReflectionLibrary lib) throws Exception { @@ -199,15 +173,6 @@ private EconomicSet cloneSetAndAppend(EconomicSet initial, War return set; } - @CompilerDirectives.TruffleBoundary - @SuppressWarnings("unchecked") - private EconomicSet cloneSetAndAppend(EconomicSet initial, EconomicSet entries) { - EconomicSet set = EconomicSet.create(new WarningEquivalence()); - set.addAll(initial.iterator()); - set.addAll(entries.iterator()); - return set; - } - @Override public String toString() { return "WithWarnings{" + value + " + " + warnings.size() + " warnings}";