From 2ca3e0a0fa099ab48de01e126611fe26f61fbc78 Mon Sep 17 00:00:00 2001 From: Gregory Travis Date: Wed, 3 Apr 2024 16:37:33 -0400 Subject: [PATCH] wip --- .../builtin/error/ThrowErrorNode.java | 8 +++++++- .../builtin/number/integer/BitShiftNode.java | 2 ++ .../runtime/error/DataflowError.java | 10 +++------- .../runtime/state/ExecutionEnvironment.java | 4 ++-- .../src/Runtime/Stack_Traces_Spec.enso | 18 +++++++++++++++++- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowErrorNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowErrorNode.java index 32c0d189e0..40372be553 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowErrorNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowErrorNode.java @@ -3,6 +3,7 @@ package org.enso.interpreter.node.expression.builtin.error; import com.oracle.truffle.api.frame.VirtualFrame; import com.oracle.truffle.api.nodes.Node; import org.enso.interpreter.dsl.BuiltinMethod; +import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.error.DataflowError; import org.enso.interpreter.runtime.state.State; @@ -13,6 +14,11 @@ import org.enso.interpreter.runtime.state.State; inlineable = true) public class ThrowErrorNode extends Node { public Object execute(VirtualFrame giveMeAStackFrame, State state, Object payload) { - return DataflowError.withoutTrace(state, payload, this); + boolean lala = state.currentEnvironment().hasContextEnabled("Dataflow_Stack_Trace"); + EnsoContext context = EnsoContext.get(this); + String skeys[] = state.currentEnvironment().keys; + String ckeys[] = context.getExecutionEnvironment().keys; + boolean attachFullStackTrace = context.getExecutionEnvironment().hasContextEnabled("Dataflow_Stack_Trace"); + return DataflowError.withoutTrace(payload, this); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/BitShiftNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/BitShiftNode.java index 4aef650fbb..f8f6d25773 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/BitShiftNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/BitShiftNode.java @@ -46,6 +46,7 @@ public abstract class BitShiftNode extends IntegerNode { } else if (positiveFitsInInt.profile(BigIntegerOps.fitsInInt(that))) { return toEnsoNumberNode.execute(BigIntegerOps.bitShiftLeft(self, (int) that)); } else { + System.out.println("AAA doLongShiftLeftExplicit"); return DataflowError.withoutTrace( EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(), this); } @@ -75,6 +76,7 @@ public abstract class BitShiftNode extends IntegerNode { return self >= 0 ? 0L : -1L; } else { // Note [Well-Formed BigIntegers] + System.out.println("AAA doBigInteger"); return DataflowError.withoutTrace( EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(), this); } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java index 33814e2f65..ada31e029e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java @@ -16,7 +16,6 @@ import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.data.vector.ArrayLikeHelpers; import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; -import org.enso.interpreter.runtime.state.State; /** * A runtime object representing an arbitrary, user-created dataflow error. @@ -42,9 +41,10 @@ public final class DataflowError extends AbstractTruffleException { * @param location the node in which the error was created * @return a new dataflow error */ - public static DataflowError withoutTrace(State state, Object payload, Node location) { + public static DataflowError withoutTrace(Object payload, Node location) { assert payload != null; - boolean attachFullStackTrace = state == null ? true : state.currentEnvironment().hasContextEnabled("Dataflow_Stack_Trace"); + EnsoContext context = EnsoContext.get(location); + boolean attachFullStackTrace = context.getExecutionEnvironment().hasContextEnabled("Dataflow_Stack_Trace"); if (attachFullStackTrace) { var result = new DataflowError(payload, UNLIMITED_STACK_TRACE, location); TruffleStackTrace.fillIn(result); @@ -55,10 +55,6 @@ public final class DataflowError extends AbstractTruffleException { } } - public static DataflowError withoutTrace(Object payload, Node location) { - return withoutTrace(null, payload, location); - } - /** * Construct a new dataflow error with the provided stack trace. * diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/ExecutionEnvironment.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/ExecutionEnvironment.java index ab67f39bad..eced3895c8 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/ExecutionEnvironment.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/state/ExecutionEnvironment.java @@ -11,8 +11,8 @@ public class ExecutionEnvironment { // Ideally we would "just" use a map here. But that leads // to native image build problems. This in turn leads to // TruffleBoundary annotations which in turn leads to slow path. - private final String[] keys; - private final Boolean[] permissions; + public final String[] keys; + public final Boolean[] permissions; public static final String LIVE_ENVIRONMENT_NAME = "live"; diff --git a/test/Base_Tests/src/Runtime/Stack_Traces_Spec.enso b/test/Base_Tests/src/Runtime/Stack_Traces_Spec.enso index 2e70640f62..0252b6c811 100644 --- a/test/Base_Tests/src/Runtime/Stack_Traces_Spec.enso +++ b/test/Base_Tests/src/Runtime/Stack_Traces_Spec.enso @@ -21,7 +21,7 @@ deep_b = deep_c deep_a = deep_b add_specs suite_builder = suite_builder.group "Stack traces" group_builder-> - group_builder.specify "should capture traces correctly" <| + group_builder.specify "should capture traces correctly" pending="a" <| modname = Meta.get_simple_type_name Stack_Traces_Spec stack = My_Type.foo names = [modname + ".bar", modname + ".baz", "Number.foo", modname + ".foo", "My_Type.foo"] @@ -42,6 +42,22 @@ add_specs suite_builder = suite_builder.group "Stack traces" group_builder-> (deep_stack_trace.length > 5) . should_be_true deep_stack_trace.take 5 . map .name . should_equal names + group_builder.specify "should respect Runtime.Context.Dataflow_Stack_Trace (for error thrown from Enso)" pending="a" <| + thrower = + big_integer = 922337203685477580700000 + 12 << big_integer + shallow_stack_trace = thrower.stack_trace + shallow_stack_trace.each (x-> IO.println "ST "+x.to_text) + IO.println "====" + #shallow_stack_trace.length . should_equal 1 + #shallow_stack_trace.at 0 . name . should_equal (names.at 0) + + Context.Dataflow_Stack_Trace.with_enabled <| + deep_stack_trace = deep_a.stack_trace + deep_stack_trace .each (x-> IO.println "ST "+x.to_text) + #(deep_stack_trace.length > 5) . should_be_true + #deep_stack_trace.take 5 . map .name . should_equal names + main = suite = Test.build suite_builder-> add_specs suite_builder