From 1a0f94602d754ddd8a351aadc118a4fb17f207bb Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 18 Oct 2024 18:36:33 +0200 Subject: [PATCH 01/36] [WIP] Add Stack_Size_Spec --- .../src/Runtime/Stack_Size_Spec.enso | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 test/Base_Tests/src/Runtime/Stack_Size_Spec.enso diff --git a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso new file mode 100644 index 000000000000..33a3224b9d73 --- /dev/null +++ b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso @@ -0,0 +1,129 @@ +# Tests regression of the overall stack trace size when calling nested +# Vector.map. It is tested by invoking a subprocess with smaller thread +# stack size (`-Xss` cmdline option). + +private + +from Standard.Base import all +import Standard.Base.Runtime.Ref.Ref +import Standard.Base.System.Process.Process_Builder.Process_Result + + +## Find the Enso binary under the `built-distribution` directory +enso_bin -> File = + find_prefix dir prefix = + vec = dir.list name_filter=prefix+"*" + if vec.length == 1 then vec.at 0 else + msg = "Cannot find " + prefix + "* in " + dir.to_text + '\n' + err = dir.list.fold msg t-> f-> + t + f.to_text + '\n' + Panic.throw err + + project_root = File.new enso_project.root.to_text + repository_root = project_root . parent . parent + built_distribution = find_prefix repository_root "built-distribution" + enso_engine = find_prefix built_distribution "enso-engine-" + enso = find_prefix enso_engine "enso-" + bin = find_prefix enso "bin" + + exe = File.new bin / if Platform.os == Platform.OS.Windows then "enso.bat" else "enso" + + if exe.is_regular_file.not then Panic.throw "Cannot find "+exe.to_text + + exe + +## Generates code for mapping over a vector with the given nesting level. + Returns code of the main method that is meant to be pasted into a separate module. + + Example of the code is (for nesting_level 2): + ``` + main = + vec = [[42]] + vec.map e0-> + e0.map e1-> + e1 + 1 + ``` + + Arguments: + - nesting_level How many times should the vector be nested +generate_code nesting_level:Integer -> Text = + bldr = Vector.Builder.new + bldr.append "from Standard.Base import all" + bldr.append '\n' + bldr.append <| "main = " + bldr.append <| " " + + "vec = " + + ("[" * nesting_level) + + "42" + + ("]" * nesting_level) + bldr.append <| " " + + "vec.map e0->" + 0.up_to (nesting_level - 1) . each \i -> + bldr.append <| (" " * (i + 2)) + + "e" + + i.to_text + + ".map e" + + (i + 1).to_text + + "-> " + bldr.append <| (" " * (nesting_level + 1)) + + "e" + + (nesting_level - 1).to_text + + " + 1" + + '\n' + vec = bldr.to_vector + vec.reduce \first_line:Text second_line:Text -> + first_line + '\n' + second_line + + +run_with_stack_size stack_size:Text enso_args:Vector -> Process_Result = + java_opts = "-Xss" + stack_size + + " " + + "-Dpolyglot.engine.Compilation=false" + args = ["JAVA_OPTS="+java_opts, enso_bin.path] + enso_args + Process.run "env" (args + enso_args) + + +failed_with_stack_overflow res:Process_Result -> Boolean = + case res.exit_code of + Exit_Code.Success -> False + Exit_Code.Failure _ -> + first_line = res.stdout.split '\n' . first + first_line.contains "Stack overflow" + +## Runs enso as a subprocess with specified stack size and nesting level of Vector.map + Returns False if the process failed with StackOverflowError, True if it succeeded. + + Arguments: + - nesting Level of nesting of `Vector.map` method calls. + - stack_size Size of the stack, passed to `-Xss` cmd line opt. +run nesting:Integer stack_size:Text -> Boolean = + tmp_file = File.create_temporary_file suffix=".enso" + code = generate_code nesting + code.write tmp_file + proc_res = run_with_stack_size stack_size ["--run", tmp_file.path] + failed_with_stack_overflow proc_res . not + + +run_all = + stack_sizes = ["256k", "300k"] + nestings = [3, 6, 9] + stack_sizes.each \stack_size -> + so_encountered = Ref.new False + nestings.each \nesting -> + header_msg = "{nesting: " + nesting.to_text + ", stack_size: " + stack_size.to_text + "} " + case so_encountered.get of + True -> + IO.println <| header_msg + "SKIPPED (SO already encountered with the same stack size in lower nesting levels)" + False -> + result = run nesting stack_size + case result of + False -> + IO.println <| header_msg + "FAILED with StackOverflow" + # It is certain that the rest of nesting levels will fail now + so_encountered.put True + True -> + IO.println <| header_msg + "SUCCEEDED" + + +main = + run_all From 695eeb36fcbaf12fe5e7bfdeb57540eb064a98fc Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 21 Oct 2024 18:29:45 +0200 Subject: [PATCH 02/36] Problem_Behavior is builtin type --- .../src/Errors/Problem_Behavior.enso | 1 + .../builtin/error/ProblemBehavior.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ProblemBehavior.java diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Problem_Behavior.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Problem_Behavior.enso index 262a8bdd4759..d0c91409a4ee 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Problem_Behavior.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Problem_Behavior.enso @@ -4,6 +4,7 @@ import project.Error.Error import project.Warning.Warning ## Specifies how to handle problems. +@Builtin_Type type Problem_Behavior ## Ignore the problem and attempt to complete the operation Ignore diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ProblemBehavior.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ProblemBehavior.java new file mode 100644 index 000000000000..a5c89445ff31 --- /dev/null +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ProblemBehavior.java @@ -0,0 +1,27 @@ +package org.enso.interpreter.node.expression.builtin.error; + +import java.util.List; +import org.enso.interpreter.dsl.BuiltinType; +import org.enso.interpreter.node.expression.builtin.Builtin; +import org.enso.interpreter.runtime.data.atom.AtomConstructor; + +@BuiltinType(name = "Standard.Base.Errors.Problem_Behavior.Problem_Behavior") +public class ProblemBehavior extends Builtin { + + @Override + protected List getDeclaredConstructors() { + return List.of(new Cons("Ignore"), new Cons("Report_Warning"), new Cons("Report_Error")); + } + + public AtomConstructor getIgnore() { + return getConstructors()[0]; + } + + public AtomConstructor getReportWarning() { + return getConstructors()[1]; + } + + public AtomConstructor getReportError() { + return getConstructors()[2]; + } +} From 8753d0750ec03e9de7ef098ddb64d0bb79bb72d7 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 21 Oct 2024 18:30:40 +0200 Subject: [PATCH 03/36] No_Wrap is builtin type --- .../lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso | 1 + .../node/expression/builtin/error/NoWrap.java | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index 13d71a160c5d..c0c0676b17f5 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -1548,6 +1548,7 @@ type Map_Error ## PRIVATE Indicates that a method should not wrap thrown errors in `Map_Error`. +@Builtin_Type type No_Wrap ## PRIVATE diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java new file mode 100644 index 000000000000..78a8a52f03c0 --- /dev/null +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java @@ -0,0 +1,9 @@ +package org.enso.interpreter.node.expression.builtin.error; + +import org.enso.interpreter.dsl.BuiltinType; +import org.enso.interpreter.node.expression.builtin.Builtin; + +@BuiltinType(name = "Standard.Base.Data.Vector.No_Wrap") +public class NoWrap extends Builtin { + // Empty on purpose - does not have any constructors +} From 400f0fbbde3ccfd572a4a1a7f50c76fda124a169 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 21 Oct 2024 18:32:14 +0200 Subject: [PATCH 04/36] vector_from_function is builtin method --- .../src/Internal/Array_Like_Helpers.enso | 27 +--- .../runtime/data/vector/ArrayLikeHelpers.java | 32 ----- .../data/vector/VectorFromFunctionNode.java | 132 ++++++++++++++++++ .../runtime/warning/AppendWarningNode.java | 2 + 4 files changed, 138 insertions(+), 55 deletions(-) create mode 100644 engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso index f308849ce30c..071bcd6088d0 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso @@ -45,8 +45,8 @@ at array_like index = @Builtin_Method "Array_Like_Helpers.at" vector_to_array : (Vector | Array) -> Array vector_to_array array_like = @Builtin_Method "Array_Like_Helpers.vector_to_array" -vector_from_function_primitive : Integer -> (Integer -> Any) -> Vector Any -vector_from_function_primitive length constructor = @Builtin_Method "Array_Like_Helpers.vector_from_function" +vector_from_function_primitive : Integer -> (Integer -> Any) -> Problem_Behavior -> Vector Any +vector_from_function_primitive length constructor on_problems = @Builtin_Method "Array_Like_Helpers.vector_from_function" flatten : (Vector | Array) -> Vector flatten array_like = @Builtin_Method "Array_Like_Helpers.flatten" @@ -85,27 +85,8 @@ slice vector start end = @Builtin_Method "Array_Like_Helpers.slice" ignored. vector_from_function : Integer -> (Integer -> Any) -> Problem_Behavior | No_Wrap -> Vector Any vector_from_function length function on_problems:(Problem_Behavior | No_Wrap)=..Report_Error = - num_errors = Ref.new 0 - wrapped_function i = - result = function i - if result.is_error.not then result else - case on_problems of - Problem_Behavior.Ignore -> - Nothing - Problem_Behavior.Report_Error -> - result.catch_primitive caught-> - Error.throw (Map_Error.Error i caught) - No_Wrap -> result - Problem_Behavior.Report_Warning -> - with_error_maybe = if num_errors.get >= MAX_MAP_WARNINGS then Nothing else - result.catch_primitive caught-> - Warning.attach caught Nothing - num_errors.modify (_+1) - with_error_maybe - results = vector_from_function_primitive length wrapped_function - if num_errors.get <= MAX_MAP_WARNINGS then results else - err = Additional_Warnings.Error num_errors.get-MAX_MAP_WARNINGS - Warning.attach err results + vector_from_function_primitive length function on_problems + ## PRIVATE The maximum number of warnings attached to result values in diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayLikeHelpers.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayLikeHelpers.java index ce59def7643f..75255bb9abd9 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayLikeHelpers.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayLikeHelpers.java @@ -1,18 +1,11 @@ package org.enso.interpreter.runtime.data.vector; import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.library.CachedLibrary; import java.nio.ByteBuffer; import org.enso.interpreter.dsl.Builtin; -import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; -import org.enso.interpreter.runtime.callable.function.Function; import org.enso.interpreter.runtime.data.EnsoObject; -import org.enso.interpreter.runtime.error.DataflowError; -import org.enso.interpreter.runtime.state.State; -import org.enso.interpreter.runtime.warning.WarningsLibrary; /** Publicly available operations on array-like classes. */ @Builtin(pkg = "immutable", stdlibName = "Standard.Base.Internal.Array_Like_Helpers") @@ -75,31 +68,6 @@ public static EnsoObject allocate(long size) { return Array.allocate(size); } - @Builtin.Method( - name = "vector_from_function", - description = "Creates new Vector with given length and provided elements.", - autoRegister = false) - @Builtin.Specialize() - @SuppressWarnings("generic-enso-builtin-type") - public static Object vectorFromFunction( - VirtualFrame frame, - long length, - Function fun, - State state, - @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, - @CachedLibrary(limit = "3") WarningsLibrary warnings) { - var len = Math.toIntExact(length); - var target = ArrayBuilder.newBuilder(len); - for (int i = 0; i < len; i++) { - var value = invokeFunctionNode.execute(fun, frame, state, new Long[] {(long) i}); - if (value instanceof DataflowError) { - return value; - } - target.add(value, warnings); - } - return target.asVector(true); - } - @Builtin.Method( name = "vector_to_array", description = "Returns an Array representation of this Vector.") diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java new file mode 100644 index 000000000000..14b8d485b533 --- /dev/null +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -0,0 +1,132 @@ +package org.enso.interpreter.runtime.data.vector; + +import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.library.CachedLibrary; +import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.profiles.BranchProfile; +import org.enso.interpreter.dsl.BuiltinMethod; +import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; +import org.enso.interpreter.node.expression.builtin.error.NoWrap; +import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; +import org.enso.interpreter.runtime.EnsoContext; +import org.enso.interpreter.runtime.callable.function.Function; +import org.enso.interpreter.runtime.data.atom.Atom; +import org.enso.interpreter.runtime.error.DataflowError; +import org.enso.interpreter.runtime.error.PanicException; +import org.enso.interpreter.runtime.state.State; +import org.enso.interpreter.runtime.warning.AppendWarningNode; +import org.enso.interpreter.runtime.warning.WarningsLibrary; + +@BuiltinMethod( + type = "Array_Like_Helpers", + name = "vector_from_function", + description = "Creates a vector from a function.") +public abstract class VectorFromFunctionNode extends Node { + public static VectorFromFunctionNode build() { + return VectorFromFunctionNodeGen.create(); + } + + private static final int MAX_MAP_WARNINGS = 10; + + /** + * @param length Length of the vector to create. + * @param func Callback function called with index as argument. + * @param onProblems Can be either {@code Problem_Behavior} or {@code No_Wrap}. + * @return Vector constructed from the given function. + */ + abstract Object execute( + VirtualFrame frame, State state, long length, Function func, Atom onProblems); + + @Specialization + Object doIt( + VirtualFrame frame, + State state, + long length, + Function func, + Atom onProblemsAtom, + @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, + @Cached("build()") AppendWarningNode appendWarningNode, + @CachedLibrary(limit = "3") WarningsLibrary warnsLib, + @Cached BranchProfile errorEncounteredProfile) { + var ctx = EnsoContext.get(this); + var onProblems = processOnProblemsArg(onProblemsAtom); + var len = Math.toIntExact(length); + var nothing = ctx.getNothing(); + var target = ArrayBuilder.newBuilder(len); + var errorsEncountered = 0; + for (int i = 0; i < len; i++) { + var value = invokeFunctionNode.execute(func, frame, state, new Long[] {(long) i}); + Object valueToAdd = value; + if (value instanceof DataflowError err) { + errorEncounteredProfile.enter(); + switch (onProblems) { + case IGNORE -> valueToAdd = nothing; + case REPORT_ERROR -> { + var mapErr = ctx.getBuiltins().error().makeMapError(i, err); + return mapErr; + } + case REPORT_WARNING -> { + errorsEncountered++; + if (errorsEncountered >= MAX_MAP_WARNINGS) { + valueToAdd = nothing; + } else { + var wrappedInWarn = appendWarningNode.executeAppend(frame, nothing, err); + valueToAdd = wrappedInWarn; + } + } + case NO_WRAP -> { + // nop + } + } + } + target.add(valueToAdd, warnsLib); + } + // TODO: Add additional warn if number of errors exceeds MAX_MAP_WARNINGS + return target.asVector(true); + } + + private OnProblems processOnProblemsArg(Atom onProblems) { + var ctx = EnsoContext.get(this); + var problemBehaviorBuiltin = ctx.getBuiltins().getBuiltinType(ProblemBehavior.class); + var noWrapBuiltin = ctx.getBuiltins().getBuiltinType(NoWrap.class); + if (isIgnore(onProblems, problemBehaviorBuiltin)) { + return OnProblems.IGNORE; + } else if (isReportError(onProblems, problemBehaviorBuiltin)) { + return OnProblems.REPORT_ERROR; + } else if (isReportWarning(onProblems, problemBehaviorBuiltin)) { + return OnProblems.REPORT_WARNING; + } else if (isNoWrap(onProblems, noWrapBuiltin)) { + return OnProblems.NO_WRAP; + } + var typeError = + ctx.getBuiltins() + .error() + .makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); + throw new PanicException(typeError, this); + } + + private static boolean isNoWrap(Atom onProblems, NoWrap noWrapBuiltin) { + return onProblems.getConstructor().getType() == noWrapBuiltin.getType(); + } + + private static boolean isReportWarning(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { + return onProblems.getConstructor() == problemBehaviorBuiltin.getReportWarning(); + } + + private static boolean isReportError(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { + return onProblems.getConstructor() == problemBehaviorBuiltin.getReportError(); + } + + private static boolean isIgnore(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { + return onProblems.getConstructor() == problemBehaviorBuiltin.getIgnore(); + } + + private enum OnProblems { + IGNORE, + REPORT_ERROR, + REPORT_WARNING, + NO_WRAP + } +} diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java index 8c196adfd30a..1377816f5fd4 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/AppendWarningNode.java @@ -4,6 +4,7 @@ import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.GenerateUncached; +import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.interop.InteropLibrary; @@ -24,6 +25,7 @@ @GenerateUncached public abstract class AppendWarningNode extends Node { + @NeverDefault public static AppendWarningNode build() { return AppendWarningNodeGen.create(); } From a0fb709b747b171ecb26d6dc6ff347823d73472e Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 21 Oct 2024 18:56:05 +0200 Subject: [PATCH 05/36] vector_from_function accepts No_Wrap as onProblems argument --- .../data/vector/VectorFromFunctionNode.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 14b8d485b533..ec853e8a37cd 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -15,6 +15,7 @@ import org.enso.interpreter.runtime.data.atom.Atom; import org.enso.interpreter.runtime.error.DataflowError; import org.enso.interpreter.runtime.error.PanicException; +import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; import org.enso.interpreter.runtime.state.State; import org.enso.interpreter.runtime.warning.AppendWarningNode; import org.enso.interpreter.runtime.warning.WarningsLibrary; @@ -33,11 +34,12 @@ public static VectorFromFunctionNode build() { /** * @param length Length of the vector to create. * @param func Callback function called with index as argument. - * @param onProblems Can be either {@code Problem_Behavior} or {@code No_Wrap}. + * @param onProblems Can be either an atom of type {@code Problem_Behavior} or {@code No_Wrap} + * type. * @return Vector constructed from the given function. */ abstract Object execute( - VirtualFrame frame, State state, long length, Function func, Atom onProblems); + VirtualFrame frame, State state, long length, Function func, Object onProblems); @Specialization Object doIt( @@ -45,13 +47,14 @@ Object doIt( State state, long length, Function func, - Atom onProblemsAtom, + Object onProblemsAtom, @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, @Cached("build()") AppendWarningNode appendWarningNode, @CachedLibrary(limit = "3") WarningsLibrary warnsLib, + @CachedLibrary(limit = "3") TypesLibrary typesLib, @Cached BranchProfile errorEncounteredProfile) { var ctx = EnsoContext.get(this); - var onProblems = processOnProblemsArg(onProblemsAtom); + var onProblems = processOnProblemsArg(onProblemsAtom, typesLib); var len = Math.toIntExact(length); var nothing = ctx.getNothing(); var target = ArrayBuilder.newBuilder(len); @@ -87,30 +90,33 @@ Object doIt( return target.asVector(true); } - private OnProblems processOnProblemsArg(Atom onProblems) { + private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib) { var ctx = EnsoContext.get(this); var problemBehaviorBuiltin = ctx.getBuiltins().getBuiltinType(ProblemBehavior.class); var noWrapBuiltin = ctx.getBuiltins().getBuiltinType(NoWrap.class); - if (isIgnore(onProblems, problemBehaviorBuiltin)) { - return OnProblems.IGNORE; - } else if (isReportError(onProblems, problemBehaviorBuiltin)) { - return OnProblems.REPORT_ERROR; - } else if (isReportWarning(onProblems, problemBehaviorBuiltin)) { - return OnProblems.REPORT_WARNING; - } else if (isNoWrap(onProblems, noWrapBuiltin)) { - return OnProblems.NO_WRAP; - } var typeError = ctx.getBuiltins() .error() .makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); + if (onProblems instanceof Atom onProblemsAtom) { + if (isIgnore(onProblemsAtom, problemBehaviorBuiltin)) { + return OnProblems.IGNORE; + } else if (isReportError(onProblemsAtom, problemBehaviorBuiltin)) { + return OnProblems.REPORT_ERROR; + } else if (isReportWarning(onProblemsAtom, problemBehaviorBuiltin)) { + return OnProblems.REPORT_WARNING; + } + } + if (!typesLib.hasType(onProblems)) { + throw new PanicException(typeError, this); + } + var onProblemsType = typesLib.getType(onProblems); + if (onProblemsType == noWrapBuiltin.getType()) { + return OnProblems.NO_WRAP; + } throw new PanicException(typeError, this); } - private static boolean isNoWrap(Atom onProblems, NoWrap noWrapBuiltin) { - return onProblems.getConstructor().getType() == noWrapBuiltin.getType(); - } - private static boolean isReportWarning(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { return onProblems.getConstructor() == problemBehaviorBuiltin.getReportWarning(); } From 0487d00e75b480834b46aa8739af6c515d0f8d09 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 21 Oct 2024 18:56:20 +0200 Subject: [PATCH 06/36] Stack_Size_Spec will be a regression test --- test/Base_Tests/src/Runtime/Stack_Size_Spec.enso | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso index 33a3224b9d73..bd65fa62a997 100644 --- a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso +++ b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso @@ -105,8 +105,8 @@ run nesting:Integer stack_size:Text -> Boolean = run_all = - stack_sizes = ["256k", "300k"] - nestings = [3, 6, 9] + stack_sizes = ["256k"] + nestings = 1.up_to 20 . to_vector stack_sizes.each \stack_size -> so_encountered = Ref.new False nestings.each \nesting -> @@ -124,6 +124,6 @@ run_all = True -> IO.println <| header_msg + "SUCCEEDED" - +# TODO: Convert this to test - we will require at least, e.g., 12 nesting levels to succeed with stack 256k main = run_all From 6e0c7f80709e341bb63e147daddb56d8921491ad Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 22 Oct 2024 11:40:49 +0200 Subject: [PATCH 07/36] Report_Error unwraps payload --- .../interpreter/runtime/data/vector/VectorFromFunctionNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index ec853e8a37cd..06579864feb0 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -67,7 +67,7 @@ Object doIt( switch (onProblems) { case IGNORE -> valueToAdd = nothing; case REPORT_ERROR -> { - var mapErr = ctx.getBuiltins().error().makeMapError(i, err); + var mapErr = ctx.getBuiltins().error().makeMapError(i, err.getPayload()); return mapErr; } case REPORT_WARNING -> { From 935fbdc6492bf55b03db388bfd2dac7b1def66a4 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 22 Oct 2024 11:51:33 +0200 Subject: [PATCH 08/36] Report_Error returns DataflowError --- .../interpreter/runtime/data/vector/VectorFromFunctionNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 06579864feb0..f41dca2a1833 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -68,7 +68,7 @@ Object doIt( case IGNORE -> valueToAdd = nothing; case REPORT_ERROR -> { var mapErr = ctx.getBuiltins().error().makeMapError(i, err.getPayload()); - return mapErr; + return DataflowError.withDefaultTrace(state, mapErr, this); } case REPORT_WARNING -> { errorsEncountered++; From 3e32eb4486e1cf7c35c6c37af0d313331a8b0a60 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 22 Oct 2024 11:54:48 +0200 Subject: [PATCH 09/36] No_Wrap immediately returns error --- .../interpreter/runtime/data/vector/VectorFromFunctionNode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index f41dca2a1833..3f5332a15e4d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -80,7 +80,7 @@ Object doIt( } } case NO_WRAP -> { - // nop + return err; } } } From d1eb427368b36eae171410c52e0ce5868cacc12f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 22 Oct 2024 12:27:17 +0200 Subject: [PATCH 10/36] Report_Warning correctly attaches warning --- .../runtime/data/vector/VectorFromFunctionNode.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 3f5332a15e4d..c87fc9ef76e6 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -18,6 +18,7 @@ import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; import org.enso.interpreter.runtime.state.State; import org.enso.interpreter.runtime.warning.AppendWarningNode; +import org.enso.interpreter.runtime.warning.Warning; import org.enso.interpreter.runtime.warning.WarningsLibrary; @BuiltinMethod( @@ -75,7 +76,8 @@ Object doIt( if (errorsEncountered >= MAX_MAP_WARNINGS) { valueToAdd = nothing; } else { - var wrappedInWarn = appendWarningNode.executeAppend(frame, nothing, err); + var wrappedInWarn = + Warning.attach(ctx, nothing, err.getPayload(), null, appendWarningNode); valueToAdd = wrappedInWarn; } } From f02665427940ba792c19798d733f2bc79dfe8c50 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 22 Oct 2024 13:16:41 +0200 Subject: [PATCH 11/36] Attach additional warnings when limit is reached --- .../Base/0.0.0-dev/src/Errors/Common.enso | 1 + .../builtin/error/AdditionalWarnings.java | 19 +++++++++++++++++++ .../data/vector/VectorFromFunctionNode.java | 16 +++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/AdditionalWarnings.java diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso index d1f6f53c3b56..07663a59595b 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Errors/Common.enso @@ -509,6 +509,7 @@ type Missing_Argument Error.throw (Missing_Argument.Error argument_name function_name call_location) ## Warning when additional warnings occurred. +@Builtin_Type type Additional_Warnings ## PRIVATE Error (count:Integer) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/AdditionalWarnings.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/AdditionalWarnings.java new file mode 100644 index 000000000000..9ac272137c8d --- /dev/null +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/AdditionalWarnings.java @@ -0,0 +1,19 @@ +package org.enso.interpreter.node.expression.builtin.error; + +import java.util.List; +import org.enso.interpreter.dsl.BuiltinType; +import org.enso.interpreter.node.expression.builtin.UniquelyConstructibleBuiltin; + +@BuiltinType +public class AdditionalWarnings extends UniquelyConstructibleBuiltin { + + @Override + protected String getConstructorName() { + return "Error"; + } + + @Override + protected List getConstructorParamNames() { + return List.of("count"); + } +} diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index c87fc9ef76e6..4b45803e7539 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -8,6 +8,7 @@ import com.oracle.truffle.api.profiles.BranchProfile; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; +import org.enso.interpreter.node.expression.builtin.error.AdditionalWarnings; import org.enso.interpreter.node.expression.builtin.error.NoWrap; import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; import org.enso.interpreter.runtime.EnsoContext; @@ -73,7 +74,7 @@ Object doIt( } case REPORT_WARNING -> { errorsEncountered++; - if (errorsEncountered >= MAX_MAP_WARNINGS) { + if (errorsEncountered > MAX_MAP_WARNINGS) { valueToAdd = nothing; } else { var wrappedInWarn = @@ -88,8 +89,17 @@ Object doIt( } target.add(valueToAdd, warnsLib); } - // TODO: Add additional warn if number of errors exceeds MAX_MAP_WARNINGS - return target.asVector(true); + var vector = target.asVector(true); + if (errorsEncountered >= MAX_MAP_WARNINGS) { + var additionalWarnsBuiltin = ctx.getBuiltins().getBuiltinType(AdditionalWarnings.class); + long additionalWarnsCnt = errorsEncountered - MAX_MAP_WARNINGS; + var additionalWarns = additionalWarnsBuiltin.newInstance(additionalWarnsCnt); + var vecWithAdditionalWarns = + Warning.attach(ctx, vector, additionalWarns, null, appendWarningNode); + return vecWithAdditionalWarns; + } else { + return vector; + } } private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib) { From 1eb8edc02bbed67c5b4cb1054198b4c5791ccd8a Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 22 Oct 2024 13:28:06 +0200 Subject: [PATCH 12/36] Remove unused code --- .../Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso | 6 ------ 1 file changed, 6 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso index 071bcd6088d0..c02ca2473fb3 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso @@ -87,12 +87,6 @@ vector_from_function : Integer -> (Integer -> Any) -> Problem_Behavior | No_Wrap vector_from_function length function on_problems:(Problem_Behavior | No_Wrap)=..Report_Error = vector_from_function_primitive length function on_problems - -## PRIVATE - The maximum number of warnings attached to result values in - `vector_from_function`. -MAX_MAP_WARNINGS = 10 - ## PRIVATE Creates a new vector where for each range, a corresponding section of the source vector is added to the result. From 847c4969e4601c4203a0a45fb3df77692d5707f9 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 23 Oct 2024 15:01:34 +0200 Subject: [PATCH 13/36] vector_from_function is builtin --- .../lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso | 2 +- .../Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index c0c0676b17f5..4ce7c5bdb47b 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -71,7 +71,7 @@ type Vector a Vector.new my_vec.length (ix -> my_vec.at ix) new : Integer -> (Integer -> Any) -> Vector Any - new length constructor = Array_Like_Helpers.vector_from_function length constructor + new length constructor = Array_Like_Helpers.vector_from_function length constructor Problem_Behavior.Report_Error ## PRIVATE ADVANCED diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso index c02ca2473fb3..aaf244294082 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso @@ -45,9 +45,6 @@ at array_like index = @Builtin_Method "Array_Like_Helpers.at" vector_to_array : (Vector | Array) -> Array vector_to_array array_like = @Builtin_Method "Array_Like_Helpers.vector_to_array" -vector_from_function_primitive : Integer -> (Integer -> Any) -> Problem_Behavior -> Vector Any -vector_from_function_primitive length constructor on_problems = @Builtin_Method "Array_Like_Helpers.vector_from_function" - flatten : (Vector | Array) -> Vector flatten array_like = @Builtin_Method "Array_Like_Helpers.flatten" @@ -84,8 +81,7 @@ slice vector start end = @Builtin_Method "Array_Like_Helpers.slice" - Ignore: The result is `Nothing`, and the error is ignored. vector_from_function : Integer -> (Integer -> Any) -> Problem_Behavior | No_Wrap -> Vector Any -vector_from_function length function on_problems:(Problem_Behavior | No_Wrap)=..Report_Error = - vector_from_function_primitive length function on_problems +vector_from_function length constructor on_problems = @Builtin_Method "Array_Like_Helpers.vector_from_function" ## PRIVATE Creates a new vector where for each range, a corresponding section of the From 990ee6a54431cd14e65291ac9bf223b3dae04e1d Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 23 Oct 2024 19:39:50 +0200 Subject: [PATCH 14/36] Convert Stack_Size_Spec to (regression) test --- test/Base_Tests/src/Main.enso | 2 + .../src/Runtime/Stack_Size_Spec.enso | 104 +++++++++--------- 2 files changed, 56 insertions(+), 50 deletions(-) diff --git a/test/Base_Tests/src/Main.enso b/test/Base_Tests/src/Main.enso index a12834f9fdb6..9231667f1454 100644 --- a/test/Base_Tests/src/Main.enso +++ b/test/Base_Tests/src/Main.enso @@ -78,6 +78,7 @@ import project.Runtime.Missing_Required_Arguments_Spec import project.Runtime.Ref_Spec import project.Runtime.State_Spec import project.Runtime.Stack_Traces_Spec +import project.Runtime.Stack_Size_Spec import project.System.Environment_Spec import project.System.File_Spec @@ -160,6 +161,7 @@ main filter=Nothing = Missing_Required_Arguments_Spec.add_specs suite_builder Lazy_Generator_Spec.add_specs suite_builder Stack_Traces_Spec.add_specs suite_builder + Stack_Size_Spec.add_specs suite_builder Text_Spec.add_specs suite_builder Time_Spec.add_specs suite_builder URI_Spec.add_specs suite_builder diff --git a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso index bd65fa62a997..e9681c388d92 100644 --- a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso +++ b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso @@ -1,6 +1,14 @@ # Tests regression of the overall stack trace size when calling nested -# Vector.map. It is tested by invoking a subprocess with smaller thread -# stack size (`-Xss` cmdline option). +# `Vector.map`. It is tested by invoking a subprocess on a generated code +# that contains `n` nested `Vector.map` calls. +# The subprocess has Truffle compiler disabled with `-Dpolyglot.engine.Compiler=false` +# to ensure there are no (Java) stack frames dropped. Moreover, we +# set explicitly `-XX:MaxJavaStackTraceDepth=...` for the subprocess to overcome +# the default length (1024) of `RuntimeException.getStackTrace` which is too low. +# +# The test runs two subprocesses with different nesting and computes the +# difference of Java stack sizes. This difference must not exceed certain limit. + private @@ -8,6 +16,8 @@ from Standard.Base import all import Standard.Base.Runtime.Ref.Ref import Standard.Base.System.Process.Process_Builder.Process_Result +from Standard.Test import all + ## Find the Enso binary under the `built-distribution` directory enso_bin -> File = @@ -34,6 +44,7 @@ enso_bin -> File = ## Generates code for mapping over a vector with the given nesting level. Returns code of the main method that is meant to be pasted into a separate module. + The code prints the count of Java frames to stdout in the deepest `Vector.map` call. Example of the code is (for nesting_level 2): ``` @@ -41,7 +52,8 @@ enso_bin -> File = vec = [[42]] vec.map e0-> e0.map e1-> - e1 + 1 + cnt = RuntimeException.new.getStackTrace.length + IO.println 'java_stack_frames='+cnt.to_text ``` Arguments: @@ -49,6 +61,7 @@ enso_bin -> File = generate_code nesting_level:Integer -> Text = bldr = Vector.Builder.new bldr.append "from Standard.Base import all" + bldr.append "polyglot java import java.lang.RuntimeException" bldr.append '\n' bldr.append <| "main = " bldr.append <| " " @@ -66,64 +79,55 @@ generate_code nesting_level:Integer -> Text = + (i + 1).to_text + "-> " bldr.append <| (" " * (nesting_level + 1)) - + "e" - + (nesting_level - 1).to_text - + " + 1" + + "cnt = RuntimeException.new.getStackTrace.length" + bldr.append <| (" " * (nesting_level + 1)) + + "IO.println <| 'java_stack_frames=' + cnt.to_text" + '\n' - vec = bldr.to_vector - vec.reduce \first_line:Text second_line:Text -> + bldr.to_vector.reduce \first_line:Text second_line:Text -> first_line + '\n' + second_line -run_with_stack_size stack_size:Text enso_args:Vector -> Process_Result = - java_opts = "-Xss" + stack_size - + " " - + "-Dpolyglot.engine.Compilation=false" +## Runs Enso subprocess with disabled Truffle compiler, with + larger thread stack and also with larger stack trace element collected + (which is needed for `new RuntimeException().getStackTrace().length`) + as this value is by default set only to 1024. + + The thread stack size is also set to a sufficiently large value + to ensure there is no StackOverflow. +run_without_compiler enso_args:Vector -> Process_Result = + java_opts = "-Dpolyglot.engine.Compilation=false " + + "-XX:MaxJavaStackTraceDepth=18000 " + + "-Xms16M" args = ["JAVA_OPTS="+java_opts, enso_bin.path] + enso_args Process.run "env" (args + enso_args) -failed_with_stack_overflow res:Process_Result -> Boolean = - case res.exit_code of - Exit_Code.Success -> False - Exit_Code.Failure _ -> - first_line = res.stdout.split '\n' . first - first_line.contains "Stack overflow" - -## Runs enso as a subprocess with specified stack size and nesting level of Vector.map - Returns False if the process failed with StackOverflowError, True if it succeeded. +## Runs enso as a subprocess with the specified nesting level of `Vector.map` calls. + Returns count of Java stack frames from the deepest `Vector.map` call. Arguments: - nesting Level of nesting of `Vector.map` method calls. - - stack_size Size of the stack, passed to `-Xss` cmd line opt. -run nesting:Integer stack_size:Text -> Boolean = +run nesting:Integer -> Integer = tmp_file = File.create_temporary_file suffix=".enso" code = generate_code nesting code.write tmp_file - proc_res = run_with_stack_size stack_size ["--run", tmp_file.path] - failed_with_stack_overflow proc_res . not - - -run_all = - stack_sizes = ["256k"] - nestings = 1.up_to 20 . to_vector - stack_sizes.each \stack_size -> - so_encountered = Ref.new False - nestings.each \nesting -> - header_msg = "{nesting: " + nesting.to_text + ", stack_size: " + stack_size.to_text + "} " - case so_encountered.get of - True -> - IO.println <| header_msg + "SKIPPED (SO already encountered with the same stack size in lower nesting levels)" - False -> - result = run nesting stack_size - case result of - False -> - IO.println <| header_msg + "FAILED with StackOverflow" - # It is certain that the rest of nesting levels will fail now - so_encountered.put True - True -> - IO.println <| header_msg + "SUCCEEDED" - -# TODO: Convert this to test - we will require at least, e.g., 12 nesting levels to succeed with stack 256k -main = - run_all + proc_res = run_without_compiler ["--run", tmp_file.path] + # FInd and parse a specific line from the process stdout + j_frames_line = proc_res.stdout.split '\n' . find \line -> + line.contains "java_stack_frames" + j_frames_line.split '=' . last . parse_integer + + +add_specs suite_builder = + suite_builder.group "Stack size" \group_builder -> + group_builder.specify "Java stack size of nested Vector.map should be kept reasonably low" <| + nesting_10 = run 10 + nesting_11 = run 11 + stack_size = nesting_11 - nesting_10 + (stack_size < 115) . should_be_true + + +main filter=Nothing = + suite = Test.build \suite_builder -> + add_specs suite_builder + suite.run_with_filter filter From 6de3d1be6c04a9cb2a767283f10815ada66967d0 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 24 Oct 2024 14:11:28 +0200 Subject: [PATCH 15/36] Add clue to the test --- test/Base_Tests/src/Runtime/Stack_Size_Spec.enso | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso index e9681c388d92..07d8e44c2532 100644 --- a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso +++ b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso @@ -124,7 +124,8 @@ add_specs suite_builder = nesting_10 = run 10 nesting_11 = run 11 stack_size = nesting_11 - nesting_10 - (stack_size < 115) . should_be_true + Test.with_clue ("Stack size of `Vector.map` should be low, but was " + stack_size.to_text + " ") <| + (stack_size < 40) . should_be_true main filter=Nothing = From e0063aab6596fcdcdb7298e2d05250c63e243866 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 24 Oct 2024 14:12:59 +0200 Subject: [PATCH 16/36] Vector.map and Array_Like_Helpers.map are tail calls --- distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso | 2 +- .../Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index 4ce7c5bdb47b..27c9bed4382a 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -700,7 +700,7 @@ type Vector a [1, 2, 3] . map +1 map : (Any -> Any) -> Problem_Behavior | No_Wrap -> Vector Any map self function on_problems:(Problem_Behavior | No_Wrap)=..Report_Error = - Array_Like_Helpers.map self function on_problems + @Tail_Call Array_Like_Helpers.map self function on_problems ## ICON union Applies a function to each element of the vector, returning the `Vector` diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso index aaf244294082..416be3d4a512 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso @@ -229,7 +229,7 @@ transpose vec_of_vecs = Vector.from_polyglot_array proxy map vector function on_problems = - vector_from_function vector.length (i-> function (vector.at i)) on_problems + @Tail_Call vector_from_function vector.length (i-> function (vector.at i)) on_problems map_with_index vector function on_problems = vector_from_function vector.length (i-> function i (vector.at i)) on_problems From 9c3d18fb3b8bceeb66662c603e0e9c1b90ecdd42 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 24 Oct 2024 14:21:36 +0200 Subject: [PATCH 17/36] Revert "Set stack size to 16M (#11327)" This reverts commit 07d0015f2f11c38c7b386337de3b701e0832fc7a. --- distribution/bin/enso | 2 +- distribution/bin/enso.bat | 2 +- distribution/manifest.template.yaml | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/distribution/bin/enso b/distribution/bin/enso index 519aa4b8391e..1939fc99dcd9 100755 --- a/distribution/bin/enso +++ b/distribution/bin/enso @@ -1,5 +1,5 @@ COMP_PATH=$(dirname "$0")/../component -JAVA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED -Xss16M $JAVA_OPTS" +JAVA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED $JAVA_OPTS" exec java --module-path $COMP_PATH $JAVA_OPTS -m org.enso.runner/org.enso.runner.Main "$@" exit diff --git a/distribution/bin/enso.bat b/distribution/bin/enso.bat index 3066c21040fa..11acf005409e 100644 --- a/distribution/bin/enso.bat +++ b/distribution/bin/enso.bat @@ -1,5 +1,5 @@ @echo off set comp-dir=%~dp0\..\component -set JAVA_OPTS=%JAVA_OPTS% --add-opens=java.base/java.nio=ALL-UNNAMED -Xss16M +set JAVA_OPTS=%JAVA_OPTS% --add-opens=java.base/java.nio=ALL-UNNAMED java --module-path %comp-dir% -Dpolyglot.compiler.IterativePartialEscape=true %JAVA_OPTS% -m org.enso.runner/org.enso.runner.Main %* exit /B %errorlevel% diff --git a/distribution/manifest.template.yaml b/distribution/manifest.template.yaml index 2b0d5f4c245a..69bd6ac58527 100644 --- a/distribution/manifest.template.yaml +++ b/distribution/manifest.template.yaml @@ -3,4 +3,3 @@ minimum-project-manager-version: 2023.2.1-nightly.2023.11.2 jvm-options: - value: "-Dgraal.PrintGraph=Network" - value: "--add-opens=java.base/java.nio=ALL-UNNAMED" - - value: "-Xss16M" From 6e23ed6d95c7dcfd202c10182cc3bb17651d0b7f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 24 Oct 2024 17:09:22 +0200 Subject: [PATCH 18/36] Fix after merge --- .../runtime/data/vector/VectorFromFunctionNode.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 4b45803e7539..65aa9a055047 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -17,6 +17,7 @@ import org.enso.interpreter.runtime.error.DataflowError; import org.enso.interpreter.runtime.error.PanicException; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; +import org.enso.interpreter.runtime.state.HasContextEnabledNode; import org.enso.interpreter.runtime.state.State; import org.enso.interpreter.runtime.warning.AppendWarningNode; import org.enso.interpreter.runtime.warning.Warning; @@ -54,7 +55,8 @@ Object doIt( @Cached("build()") AppendWarningNode appendWarningNode, @CachedLibrary(limit = "3") WarningsLibrary warnsLib, @CachedLibrary(limit = "3") TypesLibrary typesLib, - @Cached BranchProfile errorEncounteredProfile) { + @Cached BranchProfile errorEncounteredProfile, + @Cached HasContextEnabledNode hasContextEnabledNode) { var ctx = EnsoContext.get(this); var onProblems = processOnProblemsArg(onProblemsAtom, typesLib); var len = Math.toIntExact(length); @@ -70,7 +72,7 @@ Object doIt( case IGNORE -> valueToAdd = nothing; case REPORT_ERROR -> { var mapErr = ctx.getBuiltins().error().makeMapError(i, err.getPayload()); - return DataflowError.withDefaultTrace(state, mapErr, this); + return DataflowError.withDefaultTrace(state, mapErr, this, hasContextEnabledNode); } case REPORT_WARNING -> { errorsEncountered++; From ece75fb17c509485775cdc619c9b8a4a3cea799f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 24 Oct 2024 18:14:32 +0200 Subject: [PATCH 19/36] Builtins.getBuiltinType method call is behind truffle boundary --- .../interpreter/runtime/data/vector/VectorFromFunctionNode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 65aa9a055047..cd115994e3f1 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -1,5 +1,6 @@ package org.enso.interpreter.runtime.data.vector; +import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; @@ -93,6 +94,7 @@ Object doIt( } var vector = target.asVector(true); if (errorsEncountered >= MAX_MAP_WARNINGS) { + CompilerDirectives.transferToInterpreter(); var additionalWarnsBuiltin = ctx.getBuiltins().getBuiltinType(AdditionalWarnings.class); long additionalWarnsCnt = errorsEncountered - MAX_MAP_WARNINGS; var additionalWarns = additionalWarnsBuiltin.newInstance(additionalWarnsCnt); From e76a6bd7cde44aa187e8d12035e8e06094c7388d Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 24 Oct 2024 18:22:12 +0200 Subject: [PATCH 20/36] Remove NeverDefault warning --- .../enso/interpreter/runtime/state/HasContextEnabledNode.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/HasContextEnabledNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/HasContextEnabledNode.java index 9a494dcf679d..48f0dbd7c77e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/HasContextEnabledNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/HasContextEnabledNode.java @@ -3,6 +3,7 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.GenerateUncached; +import com.oracle.truffle.api.dsl.NeverDefault; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.nodes.Node; import org.enso.interpreter.runtime.EnsoContext; @@ -18,6 +19,7 @@ public static HasContextEnabledNode getUncached() { return HasContextEnabledNodeGen.getUncached(); } + @NeverDefault public static HasContextEnabledNode create() { return HasContextEnabledNodeGen.create(); } From e16961ffc33a78c8c7a243b4993e46c0df9bd0cc Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 25 Oct 2024 11:40:20 +0200 Subject: [PATCH 21/36] MetaObjectTest.compareQualifiedAndSimpleTypeName skips singleton types --- .../enso/interpreter/test/MetaObjectTest.java | 6 ++++++ .../enso/interpreter/test/ValuesGenerator.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java index 621dce9a01b7..6988f6df116d 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java @@ -16,6 +16,7 @@ import java.util.LinkedHashSet; import java.util.Set; import org.enso.common.MethodNames; +import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.type.ConstantsGen; import org.enso.interpreter.test.ValuesGenerator.Language; import org.enso.test.utils.ContextUtils; @@ -383,6 +384,11 @@ public void compareQualifiedAndSimpleTypeNameForTypes() throws Exception { // skip Nothing continue; } + var type = (Type) ContextUtils.unwrapValue(ctx, typ); + if (type.isEigenType()) { + // Skip singleton types + continue; + } var simpleName = sn.execute(typ).asString(); var metaName = typ.getMetaSimpleName() + ".type"; diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java index a0897f13bea2..9f3d5a725a48 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java @@ -302,6 +302,23 @@ public Value typeVector() { .type(); } + public Value typeNoWrap() { + return v("typeNoWrap", """ + import Standard.Base.Data.Vector.No_Wrap + """, "No_Wrap") + .type(); + } + + public Value typeProblemBehavior() { + return v( + "typeProblemBehavior", + """ + import Standard.Base.Errors.Problem_Behavior.Problem_Behavior + """, + "Problem_Behavior") + .type(); + } + public Value typeMap() { return v( "typeMap", From bf28a1216cd82f03d6653fd558f0ac8040d34859 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 25 Oct 2024 11:50:05 +0200 Subject: [PATCH 22/36] singleton builtin types are skipped in other tests as well --- .../enso/interpreter/test/MetaObjectTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java index 6988f6df116d..a41448435dc9 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaObjectTest.java @@ -416,6 +416,11 @@ private void checkAllTypesSatisfy(Check check) throws Exception { if (t.isNull()) { continue; } + var type = (Type) ContextUtils.unwrapValue(ctx, t); + if (type.isEigenType()) { + // Skip checking singleton types + continue; + } switch (t.getMetaSimpleName()) { // represented as primitive values without meta object case "Float" -> {} @@ -438,6 +443,17 @@ private void checkAllTypesSatisfy(Check check) throws Exception { @FunctionalInterface interface Check { + + /** + * @param v Instance of the type + * @param type Type. Nullable. + * @param expecting Set of types that are tested. The check should remove the currently tested + * type from this set. + * @param successfullyRemoved Set of types that already were tested. The check should add the + * currently tested type to this set. + * @param w StringBuilder for the error message that will be printed at the end in case of a + * failure. + */ void check( Value v, Value type, Set expecting, Set successfullyRemoved, StringBuilder w); } From ea6b09f59ff7e34bc0454722648b2b1ee136b52f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 25 Oct 2024 12:03:36 +0200 Subject: [PATCH 23/36] Add instances of Problem_Behavior to meta tests --- .../interpreter/test/ValuesGenerator.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java index 9f3d5a725a48..90c8b7b836b5 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java @@ -47,6 +47,11 @@ private ValuesGenerator(Context ctx, Set languages) { this.languages = languages; } + /** + * @param type Either an atom or a type. + * @param check An executable that checks if the value is of the given type. Takes a single + * parameter. + */ private record ValueInfo(Value type, Value check) {} public static ValuesGenerator create(Context ctx, Language... langs) { @@ -61,6 +66,13 @@ private ValueInfo v(String key, String prelude, String typeOrValue) { return v(key, prelude, typeOrValue, key != null ? typeOrValue : null); } + /** + * @param key Used as a key in {@link #values}. If the key is already there, nothing is created. + * Nullable. + * @param prelude Additional code inserted before {@code typeOrValue} expression, like imports. + * @param typeOrValue An expression that results in an atom or a type. + * @param typeCheck If not null, this is used as a type name and the value is checked against it. + */ private ValueInfo v(String key, String prelude, String typeOrValue, String typeCheck) { if (key == null) { key = typeOrValue; @@ -840,8 +852,16 @@ public List runtimeSystems() { collect.add(typeNothing()); } - if (languages.contains(Language.JAVA)) {} + return collect; + } + public List problemBehaviors() { + var collect = new ArrayList(); + if (languages.contains(Language.ENSO)) { + var prelude = "import Standard.Base.Errors.Problem_Behavior.Problem_Behavior"; + collect.add(v(null, prelude, "Problem_Behavior.Report_Error").type()); + collect.add(v(null, prelude, "Problem_Behavior.Ignore").type()); + } return collect; } From 204d5fbc138987ca1f3e310ca31f2462a38fe24f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 25 Oct 2024 13:18:35 +0200 Subject: [PATCH 24/36] No_Wrap and Problem_Behavior are builtins in EnsoContext --- .../interpreter/runtime/builtin/Builtins.java | 24 +++++++++++++++++++ .../data/vector/VectorFromFunctionNode.java | 12 ++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java index 746908d52d3a..5aadffd2f243 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java @@ -32,7 +32,10 @@ import org.enso.interpreter.node.expression.builtin.Nothing; import org.enso.interpreter.node.expression.builtin.Polyglot; import org.enso.interpreter.node.expression.builtin.debug.Debug; +import org.enso.interpreter.node.expression.builtin.error.AdditionalWarnings; import org.enso.interpreter.node.expression.builtin.error.CaughtPanic; +import org.enso.interpreter.node.expression.builtin.error.NoWrap; +import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; import org.enso.interpreter.node.expression.builtin.error.Warning; import org.enso.interpreter.node.expression.builtin.immutable.Vector; import org.enso.interpreter.node.expression.builtin.io.File; @@ -117,6 +120,9 @@ public static class Debug { private final Builtin timeOfDay; private final Builtin timeZone; private final Builtin warning; + private final Builtin noWrap; + private final ProblemBehavior problemBehavior; + private final AdditionalWarnings additionalWarnings; /** * Creates an instance with builtin methods installed. @@ -168,6 +174,9 @@ public Builtins(EnsoContext context) { timeOfDay = builtins.get(org.enso.interpreter.node.expression.builtin.date.TimeOfDay.class); timeZone = builtins.get(org.enso.interpreter.node.expression.builtin.date.TimeZone.class); warning = builtins.get(Warning.class); + noWrap = builtins.get(NoWrap.class); + problemBehavior = getBuiltinType(ProblemBehavior.class); + additionalWarnings = getBuiltinType(AdditionalWarnings.class); error = new Error(this, context); system = new System(this); @@ -602,6 +611,21 @@ public Type warning() { return warning.getType(); } + /** Returns the {@code Problem_Behavior} type. */ + public ProblemBehavior problemBehavior() { + return problemBehavior; + } + + /** Returns the {@code No_Wrap} atom constructor. */ + public Type noWrap() { + return noWrap.getType(); + } + + /** Returns the {@code Additional_Warnings} atom constructor. */ + public AdditionalWarnings additionalWarnings() { + return additionalWarnings; + } + /** * Returns the {@code File} atom constructor. * diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index cd115994e3f1..5dc03757ba1b 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -1,6 +1,5 @@ package org.enso.interpreter.runtime.data.vector; -import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; @@ -9,8 +8,6 @@ import com.oracle.truffle.api.profiles.BranchProfile; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; -import org.enso.interpreter.node.expression.builtin.error.AdditionalWarnings; -import org.enso.interpreter.node.expression.builtin.error.NoWrap; import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.callable.function.Function; @@ -94,8 +91,7 @@ Object doIt( } var vector = target.asVector(true); if (errorsEncountered >= MAX_MAP_WARNINGS) { - CompilerDirectives.transferToInterpreter(); - var additionalWarnsBuiltin = ctx.getBuiltins().getBuiltinType(AdditionalWarnings.class); + var additionalWarnsBuiltin = ctx.getBuiltins().additionalWarnings(); long additionalWarnsCnt = errorsEncountered - MAX_MAP_WARNINGS; var additionalWarns = additionalWarnsBuiltin.newInstance(additionalWarnsCnt); var vecWithAdditionalWarns = @@ -108,8 +104,8 @@ Object doIt( private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib) { var ctx = EnsoContext.get(this); - var problemBehaviorBuiltin = ctx.getBuiltins().getBuiltinType(ProblemBehavior.class); - var noWrapBuiltin = ctx.getBuiltins().getBuiltinType(NoWrap.class); + var problemBehaviorBuiltin = ctx.getBuiltins().problemBehavior(); + var noWrapBuiltin = ctx.getBuiltins().noWrap(); var typeError = ctx.getBuiltins() .error() @@ -127,7 +123,7 @@ private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib throw new PanicException(typeError, this); } var onProblemsType = typesLib.getType(onProblems); - if (onProblemsType == noWrapBuiltin.getType()) { + if (onProblemsType == noWrapBuiltin) { return OnProblems.NO_WRAP; } throw new PanicException(typeError, this); From fcbb60aa7111081484a3adca7e68366b8a1e6050 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 25 Oct 2024 16:41:20 +0200 Subject: [PATCH 25/36] type error panic is hidden behind TruffleBoundary --- .../data/vector/VectorFromFunctionNode.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 5dc03757ba1b..3f0ddd55f01d 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -1,5 +1,6 @@ package org.enso.interpreter.runtime.data.vector; +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; @@ -106,10 +107,6 @@ private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib var ctx = EnsoContext.get(this); var problemBehaviorBuiltin = ctx.getBuiltins().problemBehavior(); var noWrapBuiltin = ctx.getBuiltins().noWrap(); - var typeError = - ctx.getBuiltins() - .error() - .makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); if (onProblems instanceof Atom onProblemsAtom) { if (isIgnore(onProblemsAtom, problemBehaviorBuiltin)) { return OnProblems.IGNORE; @@ -120,13 +117,20 @@ private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib } } if (!typesLib.hasType(onProblems)) { - throw new PanicException(typeError, this); + throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); } var onProblemsType = typesLib.getType(onProblems); if (onProblemsType == noWrapBuiltin) { return OnProblems.NO_WRAP; } - throw new PanicException(typeError, this); + throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); + } + + @TruffleBoundary + private PanicException makeTypeError(Object expected, Object actual, String name) { + var ctx = EnsoContext.get(this); + var typeError = ctx.getBuiltins().error().makeTypeError(expected, actual, name); + return new PanicException(typeError, this); } private static boolean isReportWarning(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { From 3949ed8125ee44baaefc05eee0ed6408e3fea25f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 28 Oct 2024 17:08:24 +0100 Subject: [PATCH 26/36] Stack_Size_Spec runs only on LInux --- test/Base_Tests/src/Runtime/Stack_Size_Spec.enso | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso index 07d8e44c2532..c5d0d89497d5 100644 --- a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso +++ b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso @@ -118,8 +118,11 @@ run nesting:Integer -> Integer = j_frames_line.split '=' . last . parse_integer +only_on_linux = if System.os == "linux" then Nothing else "Test runs only on Linux" + + add_specs suite_builder = - suite_builder.group "Stack size" \group_builder -> + suite_builder.group "Stack size" pending=only_on_linux \group_builder -> group_builder.specify "Java stack size of nested Vector.map should be kept reasonably low" <| nesting_10 = run 10 nesting_11 = run 11 From eb38c357ac622aaebaa1548960c2d6bbc924ef7a Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 28 Oct 2024 17:08:53 +0100 Subject: [PATCH 27/36] Fix native image run tests - add java.lang.RuntimeException to NI --- .../lib/Standard/Base/0.0.0-dev/src/Internal/Extra_Imports.enso | 2 ++ test/Base_Tests/src/Runtime/Stack_Size_Spec.enso | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Extra_Imports.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Extra_Imports.enso index 36ab602a278a..267cd93141a0 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Extra_Imports.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Extra_Imports.enso @@ -22,6 +22,7 @@ polyglot java import java.time.LocalDate polyglot java import java.time.LocalDateTime polyglot java import java.util.function.Function polyglot java import java.lang.Exception as JException +polyglot java import java.lang.RuntimeException as JRuntimeException polyglot java import java.lang.Thread polyglot java import java.lang.Thread.State polyglot java import java.lang.Float @@ -39,3 +40,4 @@ CaseFoldedString=JCaseFoldedString Text_Utils=JText_Utils BreakIterator=JBreakIterator Exception=JException +RuntimeException=JRuntimeException diff --git a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso index c5d0d89497d5..860f67eb07d2 100644 --- a/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso +++ b/test/Base_Tests/src/Runtime/Stack_Size_Spec.enso @@ -61,7 +61,7 @@ enso_bin -> File = generate_code nesting_level:Integer -> Text = bldr = Vector.Builder.new bldr.append "from Standard.Base import all" - bldr.append "polyglot java import java.lang.RuntimeException" + bldr.append "import Standard.Base.Internal.Extra_Imports.RuntimeException" bldr.append '\n' bldr.append <| "main = " bldr.append <| " " From a445a310fd83fca0ff4e0dcccb1717cb3b78deb2 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 28 Oct 2024 17:18:25 +0100 Subject: [PATCH 28/36] Skip singleton builtin types in MetaIsATest --- .../test/java/org/enso/interpreter/test/MetaIsATest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaIsATest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaIsATest.java index 76e70b59d74f..a4d0889081e4 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaIsATest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/MetaIsATest.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.test.ValuesGenerator.Language; import org.enso.test.utils.ContextUtils; import org.graalvm.polyglot.Context; @@ -259,6 +260,11 @@ public void typesAreNotInstancesOfThemselves() throws Exception { if (v.equals(generator().typeAny())) { continue; } + var unwrappedV = ContextUtils.unwrapValue(ctx, v); + if (unwrappedV instanceof Type type && type.isEigenType()) { + // Skip singleton types + continue; + } var r = isACheck.execute(v, v); if (v.equals(generator().typeNothing())) { assertTrue("Nothing is instance of itself", r.asBoolean()); From 89b5e59f4d7fe38d063e4aeb598a138fc7aae350 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 29 Oct 2024 12:45:22 +0100 Subject: [PATCH 29/36] Cache onProblems parameter --- .../data/vector/VectorFromFunctionNode.java | 71 ++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 3f0ddd55f01d..7831a2d28867 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -2,6 +2,7 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; +import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.library.CachedLibrary; @@ -43,19 +44,73 @@ public static VectorFromFunctionNode build() { abstract Object execute( VirtualFrame frame, State state, long length, Function func, Object onProblems); - @Specialization - Object doIt( + @Specialization(guards = "onProblemsAtom == onProblemsAtomCached", limit = "3") + Object doItCached( VirtualFrame frame, State state, long length, Function func, Object onProblemsAtom, - @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, - @Cached("build()") AppendWarningNode appendWarningNode, - @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @CachedLibrary(limit = "3") TypesLibrary typesLib, - @Cached BranchProfile errorEncounteredProfile, - @Cached HasContextEnabledNode hasContextEnabledNode) { + @Cached("onProblemsAtom") Object onProblemsAtomCached, + @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, + @Shared @Cached("build()") AppendWarningNode appendWarningNode, + @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, + @Shared @CachedLibrary(limit = "3") TypesLibrary typesLib, + @Shared @Cached BranchProfile errorEncounteredProfile, + @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { + return doIt( + frame, + state, + length, + func, + onProblemsAtomCached, + warnsLib, + typesLib, + invokeFunctionNode, + appendWarningNode, + errorEncounteredProfile, + hasContextEnabledNode); + } + + @Specialization(replaces = "doItCached") + Object doItUncached( + VirtualFrame frame, + State state, + long length, + Function func, + Object onProblemsAtom, + @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, + @Shared @Cached("build()") AppendWarningNode appendWarningNode, + @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, + @Shared @CachedLibrary(limit = "3") TypesLibrary typesLib, + @Shared @Cached BranchProfile errorEncounteredProfile, + @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { + return doIt( + frame, + state, + length, + func, + onProblemsAtom, + warnsLib, + typesLib, + invokeFunctionNode, + appendWarningNode, + errorEncounteredProfile, + hasContextEnabledNode); + } + + private Object doIt( + VirtualFrame frame, + State state, + long length, + Function func, + Object onProblemsAtom, + WarningsLibrary warnsLib, + TypesLibrary typesLib, + InvokeFunctionNode invokeFunctionNode, + AppendWarningNode appendWarningNode, + BranchProfile errorEncounteredProfile, + HasContextEnabledNode hasContextEnabledNode) { var ctx = EnsoContext.get(this); var onProblems = processOnProblemsArg(onProblemsAtom, typesLib); var len = Math.toIntExact(length); From 6ac51d78594396fb9dda048970e1c4e3614ef66c Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 29 Oct 2024 17:23:34 +0100 Subject: [PATCH 30/36] Add filtering for benchmarks --- .../lib/Standard/Test/0.0.0-dev/src/Bench.enso | 14 +++++++++++--- test/Benchmarks/src/Vector/Operations.enso | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso b/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso index 09893ac057ae..76a613a9b81b 100644 --- a/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso +++ b/distribution/lib/Standard/Test/0.0.0-dev/src/Bench.enso @@ -154,7 +154,7 @@ type Bench Duration.new seconds=total_seconds ## Run the specified set of benchmarks. - run_main self = + run_main self (filter : Text | Nothing = Nothing) = count = self.total_specs IO.println <| "Found " + count.to_text + " cases to execute (ETA " + self.estimated_runtime.to_display_text + ")" @@ -167,11 +167,19 @@ type Bench line = 'Label,Phase,"Invocations count","Average time (ms)","Time Stdev"' line.write f on_existing_file=Existing_File_Behavior.Backup + should_skip (bench_name : Text) -> Boolean = + if filter == Nothing then False else + bench_name.match filter . not + self.fold Nothing _-> g-> s-> c = g.configuration bench_name = g.name + "." + s.name - IO.println <| "Benchmarking '" + bench_name + "' with configuration: " + c.to_text - Bench.measure bench_name c.warmup c.measure (s.code 0) + case should_skip bench_name of + False -> + IO.println <| "Benchmarking '" + bench_name + "' with configuration: " + c.to_text + Bench.measure bench_name c.warmup c.measure (s.code 0) + True -> + IO.println <| "Skipping '" + bench_name + "' benchmark" ## Measure the amount of time it takes to execute a given computation. diff --git a/test/Benchmarks/src/Vector/Operations.enso b/test/Benchmarks/src/Vector/Operations.enso index ca4dd8fef600..9d0a8f214c4e 100644 --- a/test/Benchmarks/src/Vector/Operations.enso +++ b/test/Benchmarks/src/Vector/Operations.enso @@ -86,4 +86,5 @@ collect_benches = Bench.build builder-> State.run Number 0 <| random_vec.each stateful_fun -main = collect_benches . run_main +main filter=Nothing = + collect_benches . run_main filter From e13a77a38aad34ef3a784eba5c9518de205da430 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 30 Oct 2024 13:30:15 +0100 Subject: [PATCH 31/36] Add docs for tracing compilation for runtime-benchmarks --- docs/infrastructure/benchmarks.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/infrastructure/benchmarks.md b/docs/infrastructure/benchmarks.md index 4b63843e95e3..7a2754967417 100644 --- a/docs/infrastructure/benchmarks.md +++ b/docs/infrastructure/benchmarks.md @@ -65,6 +65,27 @@ sbt:runtime-benchmarks> run -w 1 -i 1 -f 1 -jvmArgs -agentlib:jdwp=transport=dt_ This command will run the `importStandardLibraries` benchmark in fork waiting for the debugger to attach. +### Dumping the compilation info of the benchmark + +The following command enables the compilation tracing output from the Truffle +compiler: + +``` +sbt:runtime-benchmarks> run -jvmArgs -Dpolyglot.engine.TraceCompilation=true org.enso.interpreter.bench.benchmarks.semantic.IfVsCaseBenchmarks.ifBench6In +``` + +The output will contain lines like: + +``` +[error] [engine] opt done id=1067 ifBench6In.My_Type.Value |Tier 2|Time 22( 18+4 )ms|AST 1|Inlined 0Y 0N|IR 17/ 20|CodeSize 186|Addr 0x7acf0380f280|Timestamp 96474787822678|Src n/a +``` + +You can, e.g., dump Graal graphs with: + +``` +sbt:runtime-benchmarks> run -jvmArgs -Dgraal.Dump=Truffle:2 org.enso.interpreter.bench.benchmarks.semantic.IfVsCaseBenchmarks.ifBench6In +``` + ## Standard library benchmarks Unlike the Engine micro benchmarks, these benchmarks are written entirely in From ab27a4dda443dbe992568ce2ba498e6dc53ad70f Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 4 Nov 2024 17:29:45 +0100 Subject: [PATCH 32/36] Close context in TypePatternBenchmarks --- .../benchmarks/semantic/TypePatternBenchmarks.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/runtime-benchmarks/src/main/java/org/enso/interpreter/bench/benchmarks/semantic/TypePatternBenchmarks.java b/engine/runtime-benchmarks/src/main/java/org/enso/interpreter/bench/benchmarks/semantic/TypePatternBenchmarks.java index 9343bd153a04..142fa81819f4 100644 --- a/engine/runtime-benchmarks/src/main/java/org/enso/interpreter/bench/benchmarks/semantic/TypePatternBenchmarks.java +++ b/engine/runtime-benchmarks/src/main/java/org/enso/interpreter/bench/benchmarks/semantic/TypePatternBenchmarks.java @@ -4,6 +4,7 @@ import java.util.function.Function; import org.enso.common.MethodNames.Module; import org.enso.compiler.benchmarks.Utils; +import org.graalvm.polyglot.Context; import org.graalvm.polyglot.Value; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -14,6 +15,7 @@ import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.infra.BenchmarkParams; import org.openjdk.jmh.infra.Blackhole; @@ -28,10 +30,11 @@ public class TypePatternBenchmarks { private Value patternMatch; private Value avg; private Value vec; + private Context ctx; @Setup public void initializeBenchmark(BenchmarkParams params) throws Exception { - var ctx = Utils.createDefaultContextBuilder().build(); + ctx = Utils.createDefaultContextBuilder().build(); var code = """ from Standard.Base import Integer, Vector, Any, Float @@ -76,6 +79,11 @@ public void initializeBenchmark(BenchmarkParams params) throws Exception { this.avg = getMethod.apply("avg_pattern"); } + @TearDown + public void tearDown() { + ctx.close(); + } + /** * Adding @ExplodeLoop in {@link * org.enso.interpreter.node.controlflow.caseexpr.CatchTypeBranchNode} specialization decreases From 5b9644421dcf01be018d4bcc1a643151b98872a9 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 4 Nov 2024 19:06:17 +0100 Subject: [PATCH 33/36] No_Wrap is an uniquely constructible builtin --- .../Base/0.0.0-dev/src/Data/Statistics.enso | 8 ++-- .../Base/0.0.0-dev/src/Data/Vector.enso | 1 + .../Base/0.0.0-dev/src/Network/HTTP.enso | 4 +- .../Standard/Base/0.0.0-dev/src/Warning.enso | 2 +- .../src/Internal/DDL_Transaction.enso | 4 +- .../0.0.0-dev/src/Internal/IR/Context.enso | 4 +- .../Upload/Helpers/Argument_Checks.enso | 4 +- .../Internal/Upload/Helpers/SQL_Helpers.enso | 2 +- .../0.0.0-dev/src/Take_Drop_Helpers.enso | 2 +- .../Standard/Table/0.0.0-dev/src/Column.enso | 4 +- .../Table/0.0.0-dev/src/Data_Formatter.enso | 8 ++-- .../src/Internal/Aggregate_Column_Helper.enso | 4 +- .../0.0.0-dev/src/Internal/Java_Problems.enso | 2 +- .../0.0.0-dev/src/Internal/Join_Helpers.enso | 4 +- .../src/Internal/Lookup_Helpers.enso | 2 +- .../0.0.0-dev/src/Internal/Table_Helpers.enso | 2 +- .../0.0.0-dev/src/Internal/Table_Ref.enso | 4 +- .../src/Internal/Value_Type_Helpers.enso | 2 +- .../Standard/Table/0.0.0-dev/src/Table.enso | 12 +++--- .../node/expression/builtin/error/NoWrap.java | 15 ++++++- .../interpreter/runtime/builtin/Builtins.java | 8 ++-- .../data/vector/VectorFromFunctionNode.java | 43 ++++++++----------- test/Base_Tests/src/Data/Vector_Spec.enso | 32 +++++++------- 23 files changed, 89 insertions(+), 84 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso index 162010f525e9..c4336db1bd45 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso @@ -190,7 +190,7 @@ type Statistic compute_bulk : Vector -> Vector Statistic -> Vector Any compute_bulk data statistics:Vector=[Statistic.Count, Statistic.Sum] = resolved_stats = statistics.map (r-> r:Statistic) - moment_order = resolved_stats.map on_problems=No_Wrap .order + moment_order = resolved_stats.map on_problems=No_Wrap.Value .order has_min_max = resolved_stats.any (s-> s == Statistic.Minimum || s == Statistic.Maximum) has_product = resolved_stats.any (s-> s == Statistic.Product) max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max @@ -202,7 +202,7 @@ type Statistic Error.throw (Illegal_Argument.Error ("Can only compute " + stat.to_text + " on numerical data sets.")) if max_moment_order > 0 && counter.moments.is_nothing then report_error resolved_stats else - resolved_stats.map on_problems=No_Wrap statistic-> case statistic of + resolved_stats.map on_problems=No_Wrap.Value statistic-> case statistic of Statistic.Covariance series -> check_if_empty counter.count <| calculate_correlation_statistics data series . covariance Statistic.Pearson series -> check_if_empty counter.count <| calculate_correlation_statistics data series . pearsonCorrelation Statistic.R_Squared series -> check_if_empty counter.count <| calculate_correlation_statistics data series . rSquared @@ -229,7 +229,7 @@ type Statistic running_bulk data statistics=[Statistic.Count, Statistic.Sum] = resolved_stats = statistics.map (r-> r:Statistic) check_running_support resolved_stats <| - moment_order = resolved_stats.map on_problems=No_Wrap .order + moment_order = resolved_stats.map on_problems=No_Wrap.Value .order has_min_max = resolved_stats.any (s-> s == Statistic.Minimum || s == Statistic.Maximum) has_product = resolved_stats.any (s-> s == Statistic.Product) max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max @@ -241,7 +241,7 @@ type Statistic data.fold counter current->value-> result = compute_fold current value - row = Panic.rethrow_wrapped_if_error <| resolved_stats.map on_problems=No_Wrap s-> case s of + row = Panic.rethrow_wrapped_if_error <| resolved_stats.map on_problems=No_Wrap.Value s-> case s of Statistic.Maximum -> if result.count == 0 then Nothing else result.maximum Statistic.Minimum -> if result.count == 0 then Nothing else result.minimum _ -> result.compute s diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index 27c9bed4382a..55919fd0f765 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -1550,6 +1550,7 @@ type Map_Error Indicates that a method should not wrap thrown errors in `Map_Error`. @Builtin_Type type No_Wrap + Value ## PRIVATE Wrapped_Error.from (that : Map_Error) = Wrapped_Error.Value that that.inner_error diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso index 5d8575906eed..778e5d1b86d1 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso @@ -128,7 +128,7 @@ type HTTP boundary = body_publisher_and_boundary.second boundary_header_list = if boundary.is_nothing then [] else [Header.multipart_form_data boundary] all_headers = headers + boundary_header_list - mapped_headers = all_headers.map on_problems=No_Wrap .to_java_pair + mapped_headers = all_headers.map on_problems=No_Wrap.Value .to_java_pair response = Response.Value (EnsoSecretHelper.makeRequest self.internal_http_client builder req.uri.to_java_representation mapped_headers) if error_on_failure_code.not || response.code.is_success then response else @@ -186,7 +186,7 @@ type HTTP ## PRIVATE parse_headers : Vector (Header | Pair Text Text) -> Vector Header parse_headers headers = - headers . map on_problems=No_Wrap h-> case h of + headers . map on_problems=No_Wrap.Value h-> case h of _ : Vector -> Header.new (h.at 0) (h.at 1) _ : Pair -> Header.new (h.at 0) (h.at 1) _ : Function -> h:Header diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso index 213aec0af397..b2c8ffd9ad70 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso @@ -296,7 +296,7 @@ set_array value warnings = @Builtin_Method "Warning.set_array" map_attached_warnings_helper : (Any -> Maybe Any) -> Any -> Integer -> Any map_attached_warnings_helper mapper value frames_to_drop = warnings = Warning.get_all value - mapped_warnings = warnings.map on_problems=No_Wrap warning-> + mapped_warnings = warnings.map on_problems=No_Wrap.Value warning-> case mapper warning.value of Maybe.Some new_payload -> self_call_name = "Warning.map_attached_warnings_helper" diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso index 024952786c5f..e44085b868b5 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso @@ -71,7 +71,7 @@ run_transaction_with_tables connection (tables : Vector Transactional_Table_Desc ## PRIVATE private create_tables_inside_transaction connection (tables : Vector Transactional_Table_Description) (callback : Vector DB_Table -> Any) -> Any = connection.jdbc_connection.run_within_transaction <| - created = tables.map on_problems=No_Wrap t-> t.create connection + created = tables.map on_problems=No_Wrap.Value t-> t.create connection created.if_not_error <| result = callback created @@ -89,7 +89,7 @@ private create_tables_outside_transaction connection (tables : Vector Transactio Panic.throw caught_panic Panic.catch Any handler=handle_panic <| - created = tables.map on_problems=No_Wrap t-> + created = tables.map on_problems=No_Wrap.Value t-> table = t.create connection # We only register a table for cleanup if it was successfully created. table.if_not_error <| diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso index 64d9796edc02..a703af4eb084 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso @@ -162,8 +162,8 @@ type Context rewrite_internal_column column = Internal_Column.Value column.name column.sql_type_reference (SQL_Expression.Column alias column.name) - new_columns = column_lists.map on_problems=No_Wrap columns-> - columns.map on_problems=No_Wrap rewrite_internal_column + new_columns = column_lists.map on_problems=No_Wrap.Value columns-> + columns.map on_problems=No_Wrap.Value rewrite_internal_column encapsulated_columns = column_lists.flat_map columns-> columns.map column-> [column.name, column.expression] diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso index 39f523a50959..ef5741eab8fb 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso @@ -34,7 +34,7 @@ check_target_table_for_update target_table ~action = case target_table of resolve_primary_key structure primary_key = case primary_key of Nothing -> Nothing _ : Vector -> if primary_key.is_empty then Nothing else - validated = primary_key.map on_problems=No_Wrap key-> + validated = primary_key.map on_problems=No_Wrap.Value key-> if key.is_a Text then key else Error.throw (Illegal_Argument.Error ("Primary key must be a vector of column names, instead got a " + (Meta.type_of key . to_display_text))) validated.if_not_error <| @@ -74,6 +74,6 @@ check_update_arguments_structure_match source_table target_table key_columns upd if missing_target_key_columns.not_empty then Error.throw (Missing_Input_Columns.Error missing_target_key_columns.to_vector "the target table") else if (update_action != Update_Action.Insert) && key_columns.is_empty then Error.throw (Illegal_Argument.Error "For the `update_action = "+update_action.to_text+"`, the `key_columns` must be specified to define how to match the records.") else # Verify type matching - problems = source_table.columns.flat_map on_problems=No_Wrap check_source_column + problems = source_table.columns.flat_map on_problems=No_Wrap.Value check_source_column problems.if_not_error <| on_problems.attach_problems_before problems action diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso index 96262569d69d..07eddec1d993 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso @@ -30,7 +30,7 @@ make_batched_insert_template connection table_name column_names = prepare_create_table_statement : Connection -> Text -> Vector Column_Description -> Vector Text -> Boolean -> Problem_Behavior -> SQL_Statement prepare_create_table_statement connection table_name columns primary_key temporary on_problems:Problem_Behavior = type_mapping = connection.dialect.get_type_mapping - column_descriptors = columns.map on_problems=No_Wrap def-> + column_descriptors = columns.map on_problems=No_Wrap.Value def-> sql_type = type_mapping.value_type_to_sql def.value_type on_problems sql_type_text = type_mapping.sql_type_to_text sql_type Create_Column_Descriptor.Value def.name sql_type_text def.constraints diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso index d6a86236e77c..f7da4f0842da 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso @@ -31,7 +31,7 @@ take_drop_helper take_drop table selector:(Index_Sub_Range | Range | Integer) = row_column_name = table.make_temp_column_name table_with_row_number = table.add_row_number name=row_column_name from=0 - subqueries = ranges.map on_problems=No_Wrap range-> + subqueries = ranges.map on_problems=No_Wrap.Value range-> generate_subquery table_with_row_number row_column_name range combined = subqueries.reduce (a-> b-> a.union b) combined.remove_columns row_column_name diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso index 88138269b922..82cac218ae30 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso @@ -2101,7 +2101,7 @@ type Column map : (Any -> Any) -> Boolean -> Value_Type | Auto -> Column ! Invalid_Value_Type map self function skip_nothing=True expected_value_type=Auto = new_fn = if skip_nothing then (x-> if x.is_nothing then Nothing else function x) else function - new_st = self.to_vector.map on_problems=No_Wrap new_fn + new_st = self.to_vector.map on_problems=No_Wrap.Value new_fn Column.from_vector self.name new_st value_type=expected_value_type ## ALIAS combine, join by row position, merge @@ -2149,7 +2149,7 @@ type Column function x y False -> function new_name = naming_helper.binary_operation_name "x" self that - vec = self.to_vector.zip on_problems=No_Wrap that.to_vector new_fn + vec = self.to_vector.zip on_problems=No_Wrap.Value that.to_vector new_fn Column.from_vector new_name vec value_type=expected_value_type ## GROUP Standard.Base.Metadata diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso index 08cc1d265c32..688800759837 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso @@ -129,7 +129,7 @@ type Data_Formatter vector = case formats of v : Vector -> v singleton -> [singleton] - converted = vector.map on_problems=No_Wrap elem-> + converted = vector.map on_problems=No_Wrap.Value elem-> ## Ensure the element is a `Date_Time_Formatter` or is converted to it. We need to convert _each_ element - we cannot perform a 'bulk' conversion like `vector : Vector Date_Time_Formatter` because of erasure. checked = elem : Date_Time_Formatter @@ -216,17 +216,17 @@ type Data_Formatter ## PRIVATE make_date_parser self = self.wrap_base_parser <| Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <| - DateParser.new (self.date_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing) + DateParser.new (self.date_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing) ## PRIVATE make_date_time_parser self = self.wrap_base_parser <| Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <| - DateTimeParser.new (self.datetime_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing) + DateTimeParser.new (self.datetime_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing) ## PRIVATE make_time_of_day_parser self = self.wrap_base_parser <| Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <| - TimeOfDayParser.new (self.time_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing) + TimeOfDayParser.new (self.time_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing) ## PRIVATE make_identity_parser self = self.wrap_base_parser IdentityParser.new diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso index f5c86cd080ee..cd2cb464453c 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso @@ -67,7 +67,7 @@ prepare_aggregate_columns naming_helper group_by aggregates table error_on_missi assert (resolved_keys.contains Nothing . not) problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns columns = if old_style then group_by else keys+aggregates - valid_resolved_aggregate_columns = columns.map on_problems=No_Wrap (resolve_aggregate table problem_builder) . filter x-> x.is_nothing.not + valid_resolved_aggregate_columns = columns.map on_problems=No_Wrap.Value (resolve_aggregate table problem_builder) . filter x-> x.is_nothing.not # Grouping Key key_columns = resolved_keys.map .column @@ -80,7 +80,7 @@ prepare_aggregate_columns naming_helper group_by aggregates table error_on_missi The second pass resolves the default names, ensuring that they do not clash with the user-specified names (ensuring that user-specified names take precedence). - pass_1 = valid_resolved_aggregate_columns.map on_problems=No_Wrap c-> if c.as == "" then "" else + pass_1 = valid_resolved_aggregate_columns.map on_problems=No_Wrap.Value c-> if c.as == "" then "" else # Verify if the user-provided name is valid and if not, throw an error. naming_helper.ensure_name_is_valid c.as <| unique.make_unique c.as diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso index d9f05baef9cb..f7ee48006933 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso @@ -88,7 +88,7 @@ unpack_problem_summary problem_summary = ## TODO [RW, GT] In the next iterations we will want to remove `translate_problem` in favour of constructing Enso problem instances directly in Java code. To do so, we will need https://github.com/enso-org/enso/issues/7797 - parsed = problems_array . map on_problems=No_Wrap translate_problem + parsed = problems_array . map on_problems=No_Wrap.Value translate_problem if count == parsed.length then parsed else parsed + [Additional_Warnings.Error (count - parsed.length)] diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso index de49a7dc7051..6e5372fd6cf3 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso @@ -43,7 +43,7 @@ type Join_Condition_Resolver is_nothing column = case column of Nothing -> True _ -> False - conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap condition-> (condition:Join_Condition) + conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap.Value condition-> (condition:Join_Condition) handle_equals left_selector right_selector = left = resolve_left left_selector right = resolve_right right_selector @@ -52,7 +52,7 @@ type Join_Condition_Resolver if left.name == right.name then redundant_names.append right.name self.make_equals problem_builder left right - converted = conditions_vector.map on_problems=No_Wrap condition-> case condition of + converted = conditions_vector.map on_problems=No_Wrap.Value condition-> case condition of Join_Condition.Equals left_selector right_selector -> right_resovled = if right_selector == "" then left_selector else right_selector handle_equals left_selector right_resovled diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso index 1f09b59273ed..8ec79d4fee96 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso @@ -51,7 +51,7 @@ prepare_columns_for_lookup base_table lookup_table key_columns_selector add_new_ problems_to_add = Builder.new key_columns.if_not_error <| lookup_table_key_columns.if_not_error <| key_set = Hashset.from_vector key_columns - my_updated_columns = base_table.columns.map on_problems=No_Wrap base_column-> + my_updated_columns = base_table.columns.map on_problems=No_Wrap.Value base_column-> base_column_name = base_column.name is_key = key_set.contains base_column_name case is_key of diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso index 56d9111cefa3..f1fe3b385506 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso @@ -582,5 +582,5 @@ replace_columns_with_transformed_columns : Table -> Text | Integer | Regex | Vec replace_columns_with_transformed_columns table selectors transformer error_on_missing_columns=True on_problems:Problem_Behavior=..Report_Warning = internal_columns = table.columns_helper.select_columns selectors Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems columns = internal_columns.map table.columns_helper.make_column - new_columns = columns.map on_problems=No_Wrap transformer + new_columns = columns.map on_problems=No_Wrap.Value transformer replace_columns_with_columns table columns new_columns diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso index c365843e6a3b..76c49093e5c5 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso @@ -103,6 +103,6 @@ check_is_in_values operation_name values = Error.throw (Illegal_Argument.Error message) _ -> v case values of - _ : Vector -> values.map on_problems=No_Wrap check_value - _ : Array -> values.map on_problems=No_Wrap check_value + _ : Vector -> values.map on_problems=No_Wrap.Value check_value + _ : Array -> values.map on_problems=No_Wrap.Value check_value _ -> check_value values diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso index 92a030e128d3..8bcdbb60339e 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso @@ -273,7 +273,7 @@ check_binary_boolean_op arg1 arg2 ~action = - action: the action to run if the arguments are compatible. check_multi_argument_comparable_op column arg_or_args ~action = args = Vector.unify_vector_or_element arg_or_args - checked = args.map on_problems=No_Wrap arg-> + checked = args.map on_problems=No_Wrap.Value arg-> Value_Type.expect_comparable column arg <| True checked.if_not_error <| diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso index 9fd946da0195..e7c5bcd222ff 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso @@ -140,7 +140,7 @@ type Table new columns = invalid_input_shape = Error.throw (Illegal_Argument.Error "Each column must be represented by a pair whose first element is the column name and the second element is a vector of elements that will constitute that column, or an existing column.") - cols = columns.map on_problems=No_Wrap c-> + cols = columns.map on_problems=No_Wrap.Value c-> case c of v : Vector -> if v.length != 2 then invalid_input_shape else @@ -1512,7 +1512,7 @@ type Table False -> Dictionary.from_vector <| selected_columns.map c-> [c.name, True] - new_columns = self.columns.map on_problems=No_Wrap column-> if selected_column_names.contains_key column.name . not then column else + new_columns = self.columns.map on_problems=No_Wrap.Value column-> if selected_column_names.contains_key column.name . not then column else Value_Type.expect_text column <| storage = column.java_column.getStorage new_storage = Java_Problems.with_problem_aggregator on_problems java_problem_aggregator-> @@ -2732,10 +2732,10 @@ type Table merge self lookup_table:Table key_columns:(Vector (Integer | Text | Regex) | Text | Integer | Regex) add_new_columns:Boolean=False allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=..Report_Warning = lookup_columns = Lookup_Helpers.prepare_columns_for_lookup self lookup_table key_columns add_new_columns allow_unmatched_rows on_problems - java_descriptions = lookup_columns.map make_java_lookup_column_description on_problems=No_Wrap + java_descriptions = lookup_columns.map make_java_lookup_column_description on_problems=No_Wrap.Value keys = lookup_columns.filter .is_key - java_keys = keys.map on_problems=No_Wrap key_column-> + java_keys = keys.map on_problems=No_Wrap.Value key_column-> Java_Join_Equals.new key_column.base_column.java_column key_column.lookup_column.java_column handle_java_errors ~action = @@ -3205,7 +3205,7 @@ type Table normalize_group_by input = case input of Aggregate_Column.Group_By c _ -> c _ : Aggregate_Column -> Error.throw (Illegal_Argument.Error "Only Aggregate_Column.Group_By can be used for cross_tab group_by clause.") - _ : Vector -> input.map on_problems=No_Wrap normalize_group_by + _ : Vector -> input.map on_problems=No_Wrap.Value normalize_group_by _ -> input ## validate the name and group_by columns @@ -3217,7 +3217,7 @@ type Table grouping = columns_helper.select_columns_helper (normalize_group_by group_by) Case_Sensitivity.Default True problem_builder ## Validate the values - resolved_values = Vector.unify_vector_or_element values . map on_problems=No_Wrap (Aggregate_Column_Helper.resolve_aggregate self problem_builder) + resolved_values = Vector.unify_vector_or_element values . map on_problems=No_Wrap.Value (Aggregate_Column_Helper.resolve_aggregate self problem_builder) is_group_by c = case c of Aggregate_Column.Group_By _ _ -> True _ -> False diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java index 78a8a52f03c0..be2bc664e33e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java @@ -1,9 +1,20 @@ package org.enso.interpreter.node.expression.builtin.error; +import java.util.List; import org.enso.interpreter.dsl.BuiltinType; import org.enso.interpreter.node.expression.builtin.Builtin; +import org.enso.interpreter.node.expression.builtin.UniquelyConstructibleBuiltin; @BuiltinType(name = "Standard.Base.Data.Vector.No_Wrap") -public class NoWrap extends Builtin { - // Empty on purpose - does not have any constructors +public class NoWrap extends UniquelyConstructibleBuiltin { + + @Override + protected String getConstructorName() { + return "Value"; + } + + @Override + protected List getConstructorParamNames() { + return List.of(); + } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java index 5aadffd2f243..6698287f16da 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java @@ -120,7 +120,7 @@ public static class Debug { private final Builtin timeOfDay; private final Builtin timeZone; private final Builtin warning; - private final Builtin noWrap; + private final NoWrap noWrap; private final ProblemBehavior problemBehavior; private final AdditionalWarnings additionalWarnings; @@ -174,7 +174,7 @@ public Builtins(EnsoContext context) { timeOfDay = builtins.get(org.enso.interpreter.node.expression.builtin.date.TimeOfDay.class); timeZone = builtins.get(org.enso.interpreter.node.expression.builtin.date.TimeZone.class); warning = builtins.get(Warning.class); - noWrap = builtins.get(NoWrap.class); + noWrap = getBuiltinType(NoWrap.class); problemBehavior = getBuiltinType(ProblemBehavior.class); additionalWarnings = getBuiltinType(AdditionalWarnings.class); @@ -617,8 +617,8 @@ public ProblemBehavior problemBehavior() { } /** Returns the {@code No_Wrap} atom constructor. */ - public Type noWrap() { - return noWrap.getType(); + public NoWrap noWrap() { + return noWrap; } /** Returns the {@code Additional_Warnings} atom constructor. */ diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 7831a2d28867..28ce6bb60134 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -10,6 +10,7 @@ import com.oracle.truffle.api.profiles.BranchProfile; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; +import org.enso.interpreter.node.expression.builtin.error.NoWrap; import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.callable.function.Function; @@ -50,12 +51,11 @@ Object doItCached( State state, long length, Function func, - Object onProblemsAtom, - @Cached("onProblemsAtom") Object onProblemsAtomCached, + Atom onProblemsAtom, + @Cached("onProblemsAtom") Atom onProblemsAtomCached, @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, @Shared @Cached("build()") AppendWarningNode appendWarningNode, @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @Shared @CachedLibrary(limit = "3") TypesLibrary typesLib, @Shared @Cached BranchProfile errorEncounteredProfile, @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { return doIt( @@ -65,7 +65,6 @@ Object doItCached( func, onProblemsAtomCached, warnsLib, - typesLib, invokeFunctionNode, appendWarningNode, errorEncounteredProfile, @@ -78,11 +77,10 @@ Object doItUncached( State state, long length, Function func, - Object onProblemsAtom, + Atom onProblemsAtom, @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, @Shared @Cached("build()") AppendWarningNode appendWarningNode, @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @Shared @CachedLibrary(limit = "3") TypesLibrary typesLib, @Shared @Cached BranchProfile errorEncounteredProfile, @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { return doIt( @@ -92,7 +90,6 @@ Object doItUncached( func, onProblemsAtom, warnsLib, - typesLib, invokeFunctionNode, appendWarningNode, errorEncounteredProfile, @@ -104,15 +101,14 @@ private Object doIt( State state, long length, Function func, - Object onProblemsAtom, + Atom onProblemsAtom, WarningsLibrary warnsLib, - TypesLibrary typesLib, InvokeFunctionNode invokeFunctionNode, AppendWarningNode appendWarningNode, BranchProfile errorEncounteredProfile, HasContextEnabledNode hasContextEnabledNode) { var ctx = EnsoContext.get(this); - var onProblems = processOnProblemsArg(onProblemsAtom, typesLib); + var onProblems = processOnProblemsArg(onProblemsAtom); var len = Math.toIntExact(length); var nothing = ctx.getNothing(); var target = ArrayBuilder.newBuilder(len); @@ -158,24 +154,17 @@ private Object doIt( } } - private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib) { + private OnProblems processOnProblemsArg(Atom onProblems) { var ctx = EnsoContext.get(this); var problemBehaviorBuiltin = ctx.getBuiltins().problemBehavior(); var noWrapBuiltin = ctx.getBuiltins().noWrap(); - if (onProblems instanceof Atom onProblemsAtom) { - if (isIgnore(onProblemsAtom, problemBehaviorBuiltin)) { - return OnProblems.IGNORE; - } else if (isReportError(onProblemsAtom, problemBehaviorBuiltin)) { - return OnProblems.REPORT_ERROR; - } else if (isReportWarning(onProblemsAtom, problemBehaviorBuiltin)) { - return OnProblems.REPORT_WARNING; - } - } - if (!typesLib.hasType(onProblems)) { - throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); - } - var onProblemsType = typesLib.getType(onProblems); - if (onProblemsType == noWrapBuiltin) { + if (isIgnore(onProblems, problemBehaviorBuiltin)) { + return OnProblems.IGNORE; + } else if (isReportError(onProblems, problemBehaviorBuiltin)) { + return OnProblems.REPORT_ERROR; + } else if (isReportWarning(onProblems, problemBehaviorBuiltin)) { + return OnProblems.REPORT_WARNING; + } else if (isNoWrap(onProblems, noWrapBuiltin)) { return OnProblems.NO_WRAP; } throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); @@ -200,6 +189,10 @@ private static boolean isIgnore(Atom onProblems, ProblemBehavior problemBehavior return onProblems.getConstructor() == problemBehaviorBuiltin.getIgnore(); } + private static boolean isNoWrap(Atom onProblems, NoWrap noWrapBuiltin) { + return onProblems.getConstructor() == noWrapBuiltin.getUniqueConstructor(); + } + private enum OnProblems { IGNORE, REPORT_ERROR, diff --git a/test/Base_Tests/src/Data/Vector_Spec.enso b/test/Base_Tests/src/Data/Vector_Spec.enso index fca7f5bbf0b2..b2fd0e678be6 100644 --- a/test/Base_Tests/src/Data/Vector_Spec.enso +++ b/test/Base_Tests/src/Data/Vector_Spec.enso @@ -388,7 +388,7 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> group_builder.specify "should allow map on_problems=No_Wrap, returning a new vector" <| vec = alter [1, 2, 3, 4] - mapped = vec.map on_problems=No_Wrap x-> x * x + mapped = vec.map on_problems=No_Wrap.Value x-> x * x vec.to_text.should_equal "[1, 2, 3, 4]" mapped.to_text.should_equal "[1, 4, 9, 16]" @@ -800,11 +800,11 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> alter [] . zip [4, 5, 6] (+) . should_equal [] group_builder.specify "should zip elements with zip on_problems=No_Wrap" <| - alter [1, 2, 3] . zip on_problems=No_Wrap [] (+) . should_equal [] - alter [1, 2, 3] . zip on_problems=No_Wrap [4] (+) . should_equal [5] - alter [1, 2, 3] . zip on_problems=No_Wrap [4, 5, 6] (+) . should_equal [5, 7, 9] - alter [1, 2, 3] . zip on_problems=No_Wrap [4, 5, 6, 7] (+) . should_equal [5, 7, 9] - alter [] . zip on_problems=No_Wrap [4, 5, 6] (+) . should_equal [] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [] (+) . should_equal [] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [4] (+) . should_equal [5] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [4, 5, 6] (+) . should_equal [5, 7, 9] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [4, 5, 6, 7] (+) . should_equal [5, 7, 9] + alter [] . zip on_problems=No_Wrap.Value [4, 5, 6] (+) . should_equal [] group_builder.specify "should flat_map elements" <| alter [1, 2, 3] . flat_map (_ -> []) . should_equal [] @@ -814,11 +814,11 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> alter [0, 0, 0] . flat_map (i -> [i]) . should_equal [0, 0, 0] group_builder.specify "should flat_map elements with flat_map on_problems=No_Wrap" <| - alter [1, 2, 3] . flat_map on_problems=No_Wrap (_ -> []) . should_equal [] - alter [1, 2, 3] . flat_map on_problems=No_Wrap (_ -> [0, 1]) . should_equal [0, 1, 0, 1, 0, 1] - alter [1, 2, 3] . flat_map on_problems=No_Wrap (_ -> [0, [1]]) . should_equal [0, [1], 0, [1], 0, [1]] - alter [0, 1, 0] . flat_map on_problems=No_Wrap (i -> if i == 1 then [1, 1] else [i]) . should_equal [0, 1, 1, 0] - alter [0, 0, 0] . flat_map on_problems=No_Wrap (i -> [i]) . should_equal [0, 0, 0] + alter [1, 2, 3] . flat_map on_problems=No_Wrap.Value (_ -> []) . should_equal [] + alter [1, 2, 3] . flat_map on_problems=No_Wrap.Value (_ -> [0, 1]) . should_equal [0, 1, 0, 1, 0, 1] + alter [1, 2, 3] . flat_map on_problems=No_Wrap.Value (_ -> [0, [1]]) . should_equal [0, [1], 0, [1], 0, [1]] + alter [0, 1, 0] . flat_map on_problems=No_Wrap.Value (i -> if i == 1 then [1, 1] else [i]) . should_equal [0, 1, 1, 0] + alter [0, 0, 0] . flat_map on_problems=No_Wrap.Value (i -> [i]) . should_equal [0, 0, 0] group_builder.specify "should allow inserting elements" <| alter [2, 3] . insert . should_equal [2, 3, Nothing] @@ -909,11 +909,11 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> alter [10, 20, 30, 40] . map map_fun . should_fail_with (Map_Error.Error 2 (My_Error.Error 30)) unwrap_errors=False group_builder.specify "an error thrown inside map on_problems=No_Wrap should be caught as a My_Error" <| - alter [10, 20, 30, 40] . map on_problems=No_Wrap map_fun . should_fail_with My_Error + alter [10, 20, 30, 40] . map on_problems=No_Wrap.Value map_fun . should_fail_with My_Error group_builder.specify "an error thrown inside map_with_index on_problems=No_Wrap should be caught as a My_Error" <| map_with_index_fun _ a = if a == 30 then Error.throw (My_Error.Error a) else a+1 - alter [10, 20, 30, 40] . map_with_index on_problems=No_Wrap map_with_index_fun . should_fail_with My_Error + alter [10, 20, 30, 40] . map_with_index on_problems=No_Wrap.Value map_with_index_fun . should_fail_with My_Error group_builder.specify "an error thrown inside map and caught (without error parameter) should be caught as a Map_Error" <| alter [10, 20, 30, 40] . map map_fun . catch . should_equal (Map_Error.Error 2 (My_Error.Error 30)) @@ -971,16 +971,16 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> Warning.get_all result wrap_errors=True . map .value . should_equal expected_warnings group_builder.specify "map on_problems=No_Wrap does not do error wrapping" <| - alter [10, 20, 30, 40] . map on_problems=No_Wrap map_fun . catch . should_equal (My_Error.Error 30) + alter [10, 20, 30, 40] . map on_problems=No_Wrap.Value map_fun . catch . should_equal (My_Error.Error 30) group_builder.specify "zip on_problems=No_Wrap does not do error wrapping" <| zip_fun a _ = if a == 30 then Error.throw (My_Error.Error a) else a+1 arr = alter [10, 20, 30, 40] - arr . zip on_problems=No_Wrap arr zip_fun . catch . should_equal (My_Error.Error 30) + arr . zip on_problems=No_Wrap.Value arr zip_fun . catch . should_equal (My_Error.Error 30) group_builder.specify "flat_map on_problems=No_Wrap does not do error wrapping" <| vec = alter [1, 2, 0, 3] - vec.flat_map on_problems=No_Wrap (n-> Error.throw (My_Error.Error n)) . catch . should_equal (My_Error.Error 1) + vec.flat_map on_problems=No_Wrap.Value (n-> Error.throw (My_Error.Error n)) . catch . should_equal (My_Error.Error 1) group_builder.specify "can transpose a vector of vectors" <| mat = alter [alter [0, 1, 2], alter [3, 4, 5], alter [6, 7, 8]] From d2dcc04475176f813ccd991ecb8f7654fa8d3e44 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 4 Nov 2024 19:47:24 +0100 Subject: [PATCH 34/36] VectorFromFunctionNode caches onProblems atom ctor and uses loop profile --- .../node/expression/builtin/error/NoWrap.java | 1 - .../data/vector/VectorFromFunctionNode.java | 130 ++++++------------ 2 files changed, 45 insertions(+), 86 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java index be2bc664e33e..2b9d26a978cf 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java @@ -2,7 +2,6 @@ import java.util.List; import org.enso.interpreter.dsl.BuiltinType; -import org.enso.interpreter.node.expression.builtin.Builtin; import org.enso.interpreter.node.expression.builtin.UniquelyConstructibleBuiltin; @BuiltinType(name = "Standard.Base.Data.Vector.No_Wrap") diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 28ce6bb60134..f75e34ab69f0 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -2,22 +2,20 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; -import com.oracle.truffle.api.dsl.Cached.Shared; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.library.CachedLibrary; import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.profiles.BranchProfile; +import com.oracle.truffle.api.profiles.LoopConditionProfile; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; -import org.enso.interpreter.node.expression.builtin.error.NoWrap; -import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.callable.function.Function; import org.enso.interpreter.runtime.data.atom.Atom; +import org.enso.interpreter.runtime.data.atom.AtomConstructor; import org.enso.interpreter.runtime.error.DataflowError; import org.enso.interpreter.runtime.error.PanicException; -import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; import org.enso.interpreter.runtime.state.HasContextEnabledNode; import org.enso.interpreter.runtime.state.State; import org.enso.interpreter.runtime.warning.AppendWarningNode; @@ -45,75 +43,30 @@ public static VectorFromFunctionNode build() { abstract Object execute( VirtualFrame frame, State state, long length, Function func, Object onProblems); - @Specialization(guards = "onProblemsAtom == onProblemsAtomCached", limit = "3") + @Specialization( + guards = "getCtor(onProblemsAtom) == onProblemsAtomCtorCached", + limit = "onProblemsCtorsCount()") Object doItCached( VirtualFrame frame, State state, long length, Function func, Atom onProblemsAtom, - @Cached("onProblemsAtom") Atom onProblemsAtomCached, - @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, - @Shared @Cached("build()") AppendWarningNode appendWarningNode, - @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @Shared @Cached BranchProfile errorEncounteredProfile, - @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { - return doIt( - frame, - state, - length, - func, - onProblemsAtomCached, - warnsLib, - invokeFunctionNode, - appendWarningNode, - errorEncounteredProfile, - hasContextEnabledNode); - } - - @Specialization(replaces = "doItCached") - Object doItUncached( - VirtualFrame frame, - State state, - long length, - Function func, - Atom onProblemsAtom, - @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, - @Shared @Cached("build()") AppendWarningNode appendWarningNode, - @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @Shared @Cached BranchProfile errorEncounteredProfile, - @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { - return doIt( - frame, - state, - length, - func, - onProblemsAtom, - warnsLib, - invokeFunctionNode, - appendWarningNode, - errorEncounteredProfile, - hasContextEnabledNode); - } - - private Object doIt( - VirtualFrame frame, - State state, - long length, - Function func, - Atom onProblemsAtom, - WarningsLibrary warnsLib, - InvokeFunctionNode invokeFunctionNode, - AppendWarningNode appendWarningNode, - BranchProfile errorEncounteredProfile, - HasContextEnabledNode hasContextEnabledNode) { + @Cached("getCtor(onProblemsAtom)") AtomConstructor onProblemsAtomCtorCached, + @Cached("processOnProblemsArg(onProblemsAtomCtorCached)") OnProblems onProblems, + @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, + @Cached("build()") AppendWarningNode appendWarningNode, + @CachedLibrary(limit = "3") WarningsLibrary warnsLib, + @Cached BranchProfile errorEncounteredProfile, + @Cached HasContextEnabledNode hasContextEnabledNode, + @Cached LoopConditionProfile loopConditionProfile) { var ctx = EnsoContext.get(this); - var onProblems = processOnProblemsArg(onProblemsAtom); - var len = Math.toIntExact(length); + var len = (int) length; var nothing = ctx.getNothing(); var target = ArrayBuilder.newBuilder(len); var errorsEncountered = 0; - for (int i = 0; i < len; i++) { + loopConditionProfile.profileCounted(len); + for (int i = 0; loopConditionProfile.inject(i < len); i++) { var value = invokeFunctionNode.execute(func, frame, state, new Long[] {(long) i}); Object valueToAdd = value; if (value instanceof DataflowError err) { @@ -154,22 +107,44 @@ private Object doIt( } } - private OnProblems processOnProblemsArg(Atom onProblems) { + /** + * Unreachable: The {@code doItCached} specialization has the same limit of instantiations as + * there are possible onProblems arguments. So this specialization is only reached if {@code + * onProblems} argument is an unexpected type. + * + * @return Just throws Type_Error dataflow error. + */ + @Specialization(replaces = "doItCached") + Object unreachable( + VirtualFrame frame, State state, long length, Function func, Object onProblems) { + var problemBehaviorBuiltin = EnsoContext.get(this).getBuiltins().problemBehavior(); + throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); + } + + protected OnProblems processOnProblemsArg(AtomConstructor onProblems) { var ctx = EnsoContext.get(this); var problemBehaviorBuiltin = ctx.getBuiltins().problemBehavior(); var noWrapBuiltin = ctx.getBuiltins().noWrap(); - if (isIgnore(onProblems, problemBehaviorBuiltin)) { + if (onProblems == problemBehaviorBuiltin.getIgnore()) { return OnProblems.IGNORE; - } else if (isReportError(onProblems, problemBehaviorBuiltin)) { + } else if (onProblems == problemBehaviorBuiltin.getReportError()) { return OnProblems.REPORT_ERROR; - } else if (isReportWarning(onProblems, problemBehaviorBuiltin)) { + } else if (onProblems == problemBehaviorBuiltin.getReportWarning()) { return OnProblems.REPORT_WARNING; - } else if (isNoWrap(onProblems, noWrapBuiltin)) { + } else if (onProblems == noWrapBuiltin.getUniqueConstructor()) { return OnProblems.NO_WRAP; } throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); } + protected static AtomConstructor getCtor(Atom atom) { + return atom.getConstructor(); + } + + protected static int onProblemsCtorsCount() { + return OnProblems.values().length; + } + @TruffleBoundary private PanicException makeTypeError(Object expected, Object actual, String name) { var ctx = EnsoContext.get(this); @@ -177,23 +152,8 @@ private PanicException makeTypeError(Object expected, Object actual, String name return new PanicException(typeError, this); } - private static boolean isReportWarning(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { - return onProblems.getConstructor() == problemBehaviorBuiltin.getReportWarning(); - } - - private static boolean isReportError(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { - return onProblems.getConstructor() == problemBehaviorBuiltin.getReportError(); - } - - private static boolean isIgnore(Atom onProblems, ProblemBehavior problemBehaviorBuiltin) { - return onProblems.getConstructor() == problemBehaviorBuiltin.getIgnore(); - } - - private static boolean isNoWrap(Atom onProblems, NoWrap noWrapBuiltin) { - return onProblems.getConstructor() == noWrapBuiltin.getUniqueConstructor(); - } - - private enum OnProblems { + /** All the possible values for the {@code onProblems} argument. */ + protected enum OnProblems { IGNORE, REPORT_ERROR, REPORT_WARNING, From cd3e04b2647acbdaffcfd423769d73b87bfa2f9c Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 5 Nov 2024 11:44:46 +0100 Subject: [PATCH 35/36] Add value for No_Wrap to meta tests --- .../java/org/enso/interpreter/test/ValuesGenerator.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java index 90c8b7b836b5..4b23c3300299 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/ValuesGenerator.java @@ -865,6 +865,15 @@ public List problemBehaviors() { return collect; } + public List noWrap() { + var collect = new ArrayList(); + if (languages.contains(Language.ENSO)) { + var prelude = "import Standard.Base.Data.Vector.No_Wrap"; + collect.add(v(null, prelude, "No_Wrap.Value").type()); + } + return collect; + } + public List errors() { var collect = new ArrayList(); if (languages.contains(Language.ENSO)) { From 2cbc1e905752c7b211380c81cd3cad273b3e466e Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Tue, 5 Nov 2024 12:46:49 +0100 Subject: [PATCH 36/36] onProblems is No_Wrap.Value --- distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso | 2 +- .../lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso index 4e67a357738e..1381ff9fb7c4 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso @@ -173,7 +173,7 @@ type JS_Object mapper = ObjectMapper.new new_object = mapper.createObjectNode keys = Vector.build builder-> - pairs.map on_problems=No_Wrap pair-> + pairs.map on_problems=No_Wrap.Value pair-> case pair.first of text : Text -> ## Ensure that any dataflow errors that could be stored in `pair.second` are propagated. diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso index c8357c65bfce..e0b3241895bc 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP/Header.enso @@ -30,7 +30,7 @@ type Header `Header` values. unify_vector : Vector (Header | Pair Text Text | Vector) -> Vector Header unify_vector headers:Vector = - headers . map on_problems=No_Wrap h-> case h of + headers . map on_problems=No_Wrap.Value h-> case h of _ : Vector -> Header.new (h.at 0) (h.at 1) _ : Pair -> Header.new (h.at 0) (h.at 1) _ : Function -> h:Header