diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso index 42c3e2d05fa0..2eb01a09aef7 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/IO.enso @@ -2,6 +2,8 @@ import project.Any.Any import project.Data.Text.Text import project.Nothing.Nothing +from project.Data.Boolean import Boolean, False + ## PRIVATE ADVANCED Prints the provided message to standard error. diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java index 22abe24ac061..8b8411af767f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/io/PrintlnNode.java @@ -9,6 +9,7 @@ import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; import org.enso.interpreter.dsl.AcceptsError; +import org.enso.interpreter.dsl.AcceptsWarning; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.callable.InvokeCallableNode; import org.enso.interpreter.runtime.EnsoContext; @@ -31,7 +32,7 @@ public abstract class PrintlnNode extends Node { InvokeCallableNode.DefaultsExecutionMode.EXECUTE, InvokeCallableNode.ArgumentsExecutionMode.PRE_EXECUTED); - abstract Object execute(VirtualFrame frame, State state, @AcceptsError Object message); + abstract Object execute(VirtualFrame frame, State state, @AcceptsWarning @AcceptsError Object message, boolean warnings); @Specialization(guards = {"strings.isString(message)", "!hasWarningsToPrint(warningsLibrary, warnings, message)"}) Object doPrintText( @@ -105,7 +106,7 @@ Object doPrintWithWarnings( return ctx.getNothing(); } - private static boolean hasWarningsToPrint(WarningsLibrary warningsLibrary, boolean shouldPrintWarnings, Object obj) { + static boolean hasWarningsToPrint(WarningsLibrary warningsLibrary, boolean shouldPrintWarnings, Object obj) { return shouldPrintWarnings && warningsLibrary.hasWarnings(obj); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java index bb6ed4c1c563..85c2a85be46e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/EqualsNode.java @@ -322,17 +322,13 @@ boolean equalsWithWarnings(Object selfWithWarnings, Object otherWithWarnings, @CachedLibrary("otherWithWarnings") WarningsLibrary otherWarnLib, @Cached EqualsNode equalsNode ) { - try { - Object self = + Object self = selfWarnLib.hasWarnings(selfWithWarnings) ? selfWarnLib.removeWarnings(selfWithWarnings) : selfWithWarnings; - Object other = + Object other = otherWarnLib.hasWarnings(otherWithWarnings) ? otherWarnLib.removeWarnings(otherWithWarnings) : otherWithWarnings; - return equalsNode.execute(self, other); - } catch (UnsupportedMessageException e) { - throw new IllegalStateException(e); - } + return equalsNode.execute(self, other); } /** Interop libraries **/ diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/HashCodeNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/HashCodeNode.java index 7fc7b75fe8f8..de273bac6463 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/HashCodeNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/HashCodeNode.java @@ -266,11 +266,7 @@ long hashCodeForWarning( Object selfWithWarning, @CachedLibrary("selfWithWarning") WarningsLibrary warnLib, @Cached HashCodeNode hashCodeNode) { - try { - return hashCodeNode.execute(warnLib.removeWarnings(selfWithWarning)); - } catch (UnsupportedMessageException e) { - throw new IllegalStateException(e); - } + return hashCodeNode.execute(warnLib.removeWarnings(selfWithWarning)); } /** Specializations for interop values * */ diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/ordering/LessThanNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/ordering/LessThanNode.java index f9406681732f..8369579ecf5b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/ordering/LessThanNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/ordering/LessThanNode.java @@ -145,17 +145,13 @@ Object lessWithWarnings(Object selfWithWarnings, Object otherWithWarnings, @CachedLibrary("otherWithWarnings") WarningsLibrary otherWarnLib, @Cached LessThanNode lessThanNode ) { - try { - Object self = + Object self = selfWarnLib.hasWarnings(selfWithWarnings) ? selfWarnLib.removeWarnings(selfWithWarnings) : selfWithWarnings; - Object other = + Object other = otherWarnLib.hasWarnings(otherWithWarnings) ? otherWarnLib.removeWarnings(otherWithWarnings) : otherWithWarnings; - return lessThanNode.execute(self, other); - } catch (UnsupportedMessageException e) { - throw new IllegalStateException(e); - } + return lessThanNode.execute(self, other); } @Specialization(limit = "3") diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/util/ExpectStringNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/util/ExpectStringNode.java index 9c5670fd9990..c139d882095a 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/util/ExpectStringNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/text/util/ExpectStringNode.java @@ -36,11 +36,7 @@ String doString(String str) { @Specialization(guards = "warnings.hasWarnings(warning)") String doWarning(Object warning, @CachedLibrary(limit = "3") WarningsLibrary warnings) { - try { - return execute(warnings.removeWarnings(warning)); - } catch (UnsupportedMessageException e) { - throw new IllegalStateException(e); - } + return execute(warnings.removeWarnings(warning)); } @Fallback diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java index cc4271e0be0f..4af4aac829c2 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java @@ -197,6 +197,15 @@ boolean hasWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { return withWarnings; } + @ExportMessage + long countWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { + long count = 0; + for (Object item : items) { + count += warnings.countWarnings(item); + } + return count; + } + @ExportMessage Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary warnings) throws UnsupportedMessageException { @@ -210,8 +219,7 @@ Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary } @ExportMessage - Array removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) - throws UnsupportedMessageException { + Array removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { Object[] items = new Object[this.items.length]; for (int i = 0; i < this.items.length; i++) { if (warnings.hasWarnings(this.items[i])) { 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 b06b25ee231d..73ea6f664688 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 @@ -132,13 +132,18 @@ boolean hasWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { return warnings.hasWarnings(this.storage); } + @ExportMessage + long countWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { + return warnings.countWarnings(this.storage); + } + @ExportMessage Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary warnings) throws UnsupportedMessageException { return warnings.getWarnings(this.storage, location); } @ExportMessage - Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) throws UnsupportedMessageException { + Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { Object newStorage = warnings.removeWarnings(this.storage); return new ArraySlice(newStorage, start, end); } 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 8a626a9d7216..5fd341040603 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 @@ -218,6 +218,11 @@ boolean hasWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { return warnings.hasWarnings(this.storage); } + @ExportMessage + long countWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { + return warnings.countWarnings(this.storage); + } + @ExportMessage Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary warnings) throws UnsupportedMessageException { @@ -225,8 +230,7 @@ Warning[] getWarnings(Node location, @CachedLibrary(limit = "3") WarningsLibrary } @ExportMessage - Vector removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) - throws UnsupportedMessageException { + Vector removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { return new Vector(warnings.removeWarnings(this.storage)); } 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 563113823113..9ead7707ddad 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 @@ -113,7 +113,7 @@ boolean hasWarnings() { @ExportMessage long countWarnings() { - return warnings.size(); + return (long) warnings.size(); } @ExportMessage @@ -127,8 +127,7 @@ Warning[] getWarnings( } @ExportMessage - Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) - throws UnsupportedMessageException { + Object removeWarnings(@CachedLibrary(limit = "3") WarningsLibrary warnings) { if (warnings.hasWarnings(value)) { return warnings.removeWarnings(value); } else {