Skip to content

Commit baeddd0

Browse files
committed
DataflowError.withDefaultTrace has BranchProfile as parameter
1 parent 1fc4fe6 commit baeddd0

File tree

12 files changed

+68
-26
lines changed

12 files changed

+68
-26
lines changed

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/ThrowErrorNode.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.oracle.truffle.api.frame.VirtualFrame;
44
import com.oracle.truffle.api.nodes.Node;
5+
import com.oracle.truffle.api.profiles.BranchProfile;
56
import org.enso.interpreter.dsl.BuiltinMethod;
67
import org.enso.interpreter.runtime.error.DataflowError;
78
import org.enso.interpreter.runtime.state.State;
@@ -12,7 +13,9 @@
1213
description = "Returns a new value error with given payload.",
1314
inlineable = true)
1415
public class ThrowErrorNode extends Node {
16+
private final BranchProfile attachFullStackTraceProfile = BranchProfile.create();
17+
1518
public Object execute(VirtualFrame giveMeAStackFrame, State state, Object payload) {
16-
return DataflowError.withDefaultTrace(state, payload, this);
19+
return DataflowError.withDefaultTrace(state, payload, this, attachFullStackTraceProfile);
1720
}
1821
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/FloatNode.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.oracle.truffle.api.interop.TruffleObject;
55
import com.oracle.truffle.api.interop.UnsupportedMessageException;
66
import com.oracle.truffle.api.nodes.Node;
7+
import com.oracle.truffle.api.profiles.BranchProfile;
78
import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode;
89
import org.enso.interpreter.runtime.EnsoContext;
910
import org.enso.interpreter.runtime.error.DataflowError;
@@ -12,6 +13,7 @@
1213

1314
abstract class FloatNode extends Node {
1415
static final String INTEROP_LIMIT = "3";
16+
private final BranchProfile attachFullStackTraceProfile = BranchProfile.create();
1517

1618
final boolean isForeignNumber(InteropLibrary iop, TruffleObject obj) {
1719
if (obj instanceof EnsoBigInteger) {
@@ -48,6 +50,6 @@ final PanicException panicOtherwise(double self, Object that) {
4850
final DataflowError incomparableError(Object self, Object that) {
4951
var builtins = EnsoContext.get(this).getBuiltins();
5052
var incomparableErr = builtins.error().makeIncomparableValues(self, that);
51-
return DataflowError.withDefaultTrace(incomparableErr, this);
53+
return DataflowError.withDefaultTrace(incomparableErr, this, attachFullStackTraceProfile);
5254
}
5355
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/BitShiftNode.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import com.oracle.truffle.api.dsl.Cached;
44
import com.oracle.truffle.api.dsl.Cached.Exclusive;
5+
import com.oracle.truffle.api.dsl.Cached.Shared;
56
import com.oracle.truffle.api.dsl.Fallback;
67
import com.oracle.truffle.api.dsl.ImportStatic;
78
import com.oracle.truffle.api.dsl.NeverDefault;
89
import com.oracle.truffle.api.dsl.Specialization;
910
import com.oracle.truffle.api.interop.InteropLibrary;
1011
import com.oracle.truffle.api.interop.TruffleObject;
1112
import com.oracle.truffle.api.library.CachedLibrary;
13+
import com.oracle.truffle.api.profiles.BranchProfile;
1214
import com.oracle.truffle.api.profiles.CountingConditionProfile;
1315
import org.enso.interpreter.dsl.BuiltinMethod;
1416
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
@@ -40,14 +42,17 @@ long doLongShiftLeft(long self, long that) {
4042
}
4143

4244
@Specialization(guards = "that >= 0", replaces = "doLongShiftLeft")
43-
Object doLongShiftLeftExplicit(long self, long that) {
45+
Object doLongShiftLeftExplicit(
46+
long self, long that, @Shared @Cached BranchProfile attachFullStackTraceProfile) {
4447
if (canShiftLeftInLongProfile.profile(canShiftLeftInLong(self, that))) {
4548
return doLongShiftLeft(self, that);
4649
} else if (positiveFitsInInt.profile(BigIntegerOps.fitsInInt(that))) {
4750
return toEnsoNumberNode.execute(BigIntegerOps.bitShiftLeft(self, (int) that));
4851
} else {
4952
return DataflowError.withDefaultTrace(
50-
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(), this);
53+
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(),
54+
this,
55+
attachFullStackTraceProfile);
5156
}
5257
}
5358

@@ -70,13 +75,16 @@ long doLongShiftRightExplicit(long self, long that) {
7075
}
7176

7277
@Specialization
73-
Object doBigInteger(long self, EnsoBigInteger that) {
78+
Object doBigInteger(
79+
long self, EnsoBigInteger that, @Cached BranchProfile attachFullStackTraceProfile) {
7480
if (!BigIntegerOps.nonNegative(that.getValue())) {
7581
return self >= 0 ? 0L : -1L;
7682
} else {
7783
// Note [Well-Formed BigIntegers]
7884
return DataflowError.withDefaultTrace(
79-
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(), this);
85+
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(),
86+
this,
87+
attachFullStackTraceProfile);
8088
}
8189
}
8290

@@ -89,12 +97,15 @@ EnsoBigInteger doBigIntShiftLeft(EnsoBigInteger self, long that) {
8997
Object doBigIntShiftLeftExplicit(
9098
EnsoBigInteger self,
9199
long that,
92-
@Exclusive @Cached CountingConditionProfile fitsInIntProfileLeftShift) {
100+
@Exclusive @Cached CountingConditionProfile fitsInIntProfileLeftShift,
101+
@Cached BranchProfile attachFullStackTraceProfile) {
93102
if (fitsInIntProfileLeftShift.profile(BigIntegerOps.fitsInInt(that))) {
94103
return doBigIntShiftLeft(self, that);
95104
} else {
96105
return DataflowError.withDefaultTrace(
97-
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(), this);
106+
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(),
107+
this,
108+
attachFullStackTraceProfile);
98109
}
99110
}
100111

@@ -116,12 +127,17 @@ Object doBigIntShiftRightExplicit(
116127
}
117128

118129
@Specialization
119-
Object doBigIntThat(EnsoBigInteger self, EnsoBigInteger that) {
130+
Object doBigIntThat(
131+
EnsoBigInteger self,
132+
EnsoBigInteger that,
133+
@Shared @Cached BranchProfile attachFullStackTraceProfile) {
120134
if (!BigIntegerOps.nonNegative(that.getValue())) {
121135
return BigIntegerOps.nonNegative(self.getValue()) ? 0L : -1L;
122136
} else {
123137
return DataflowError.withDefaultTrace(
124-
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(), this);
138+
EnsoContext.get(this).getBuiltins().error().getShiftAmountTooLargeError(),
139+
this,
140+
attachFullStackTraceProfile);
125141
}
126142
}
127143

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/GreaterNode.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.oracle.truffle.api.interop.InteropLibrary;
77
import com.oracle.truffle.api.interop.TruffleObject;
88
import com.oracle.truffle.api.library.CachedLibrary;
9+
import com.oracle.truffle.api.profiles.BranchProfile;
910
import org.enso.interpreter.dsl.BuiltinMethod;
1011
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
1112
import org.enso.interpreter.runtime.EnsoContext;
@@ -61,9 +62,9 @@ Object doInterop(
6162
}
6263

6364
@Fallback
64-
Object doOther(Object self, Object that) {
65+
Object doOther(Object self, Object that, @Cached BranchProfile attachFullStackTraceProfile) {
6566
var builtins = EnsoContext.get(this).getBuiltins();
6667
var incomparableValsErr = builtins.error().makeIncomparableValues(self, that);
67-
return DataflowError.withDefaultTrace(incomparableValsErr, this);
68+
return DataflowError.withDefaultTrace(incomparableValsErr, this, attachFullStackTraceProfile);
6869
}
6970
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/GreaterOrEqualNode.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.oracle.truffle.api.interop.InteropLibrary;
77
import com.oracle.truffle.api.interop.TruffleObject;
88
import com.oracle.truffle.api.library.CachedLibrary;
9+
import com.oracle.truffle.api.profiles.BranchProfile;
910
import org.enso.interpreter.dsl.BuiltinMethod;
1011
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
1112
import org.enso.interpreter.runtime.EnsoContext;
@@ -61,9 +62,9 @@ Object doInterop(
6162
}
6263

6364
@Fallback
64-
Object doOther(Object self, Object that) {
65+
Object doOther(Object self, Object that, @Cached BranchProfile attachFullStackTraceProfile) {
6566
var builtins = EnsoContext.get(this).getBuiltins();
6667
var incomparableValsErr = builtins.error().makeIncomparableValues(self, that);
67-
return DataflowError.withDefaultTrace(incomparableValsErr, this);
68+
return DataflowError.withDefaultTrace(incomparableValsErr, this, attachFullStackTraceProfile);
6869
}
6970
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/LessNode.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.oracle.truffle.api.interop.InteropLibrary;
77
import com.oracle.truffle.api.interop.TruffleObject;
88
import com.oracle.truffle.api.library.CachedLibrary;
9+
import com.oracle.truffle.api.profiles.BranchProfile;
910
import org.enso.interpreter.dsl.BuiltinMethod;
1011
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
1112
import org.enso.interpreter.runtime.EnsoContext;
@@ -61,9 +62,9 @@ Object doInterop(
6162
}
6263

6364
@Fallback
64-
Object doOther(Object self, Object that) {
65+
Object doOther(Object self, Object that, @Cached BranchProfile attachFullStackTraceProfile) {
6566
var builtins = EnsoContext.get(this).getBuiltins();
6667
var incomparableValsErr = builtins.error().makeIncomparableValues(self, that);
67-
return DataflowError.withDefaultTrace(incomparableValsErr, this);
68+
return DataflowError.withDefaultTrace(incomparableValsErr, this, attachFullStackTraceProfile);
6869
}
6970
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/LessOrEqualNode.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.oracle.truffle.api.interop.InteropLibrary;
77
import com.oracle.truffle.api.interop.TruffleObject;
88
import com.oracle.truffle.api.library.CachedLibrary;
9+
import com.oracle.truffle.api.profiles.BranchProfile;
910
import org.enso.interpreter.dsl.BuiltinMethod;
1011
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
1112
import org.enso.interpreter.runtime.EnsoContext;
@@ -62,9 +63,9 @@ Object doInterop(
6263
}
6364

6465
@Fallback
65-
Object doOther(Object self, Object that) {
66+
Object doOther(Object self, Object that, @Cached BranchProfile attachFullStackTraceProfile) {
6667
var builtins = EnsoContext.get(this).getBuiltins();
6768
var incomparableValsErr = builtins.error().makeIncomparableValues(self, that);
68-
return DataflowError.withDefaultTrace(incomparableValsErr, this);
69+
return DataflowError.withDefaultTrace(incomparableValsErr, this, attachFullStackTraceProfile);
6970
}
7071
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/ModNode.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.oracle.truffle.api.interop.InteropLibrary;
88
import com.oracle.truffle.api.interop.TruffleObject;
99
import com.oracle.truffle.api.library.CachedLibrary;
10+
import com.oracle.truffle.api.profiles.BranchProfile;
1011
import java.math.BigInteger;
1112
import org.enso.interpreter.dsl.BuiltinMethod;
1213
import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps;
@@ -53,12 +54,14 @@ Object doBigInteger(long self, EnsoBigInteger that) {
5354
}
5455

5556
@Specialization
56-
Object doLong(EnsoBigInteger self, long that) {
57+
Object doLong(EnsoBigInteger self, long that, @Cached BranchProfile attachFullStackTraceProfile) {
5758
try {
5859
return toEnsoNumberNode.execute(BigIntegerOps.modulo(self.getValue(), that));
5960
} catch (ArithmeticException e) {
6061
return DataflowError.withDefaultTrace(
61-
EnsoContext.get(this).getBuiltins().error().getDivideByZeroError(), this);
62+
EnsoContext.get(this).getBuiltins().error().getDivideByZeroError(),
63+
this,
64+
attachFullStackTraceProfile);
6265
}
6366
}
6467

engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/integer/ParseIntegerNode.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public final class ParseIntegerNode extends IntegerNode {
2020
@Child ToJavaStringNode toJavaString = ToJavaStringNode.build();
2121
private final BranchProfile noEx1 = BranchProfile.create();
2222
private final BranchProfile noEx2 = BranchProfile.create();
23+
private final BranchProfile attachFullStackTraceProfile = BranchProfile.create();
2324

2425
Object execute(Text value, long radix) {
2526
var r = Math.toIntExact(radix);
@@ -36,7 +37,7 @@ Object execute(Text value, long radix) {
3637
noEx2.enter();
3738
var errors = EnsoContext.get(this).getBuiltins().error();
3839
var err = errors.makeNumberParseError(ex.getMessage());
39-
return DataflowError.withDefaultTrace(err, this);
40+
return DataflowError.withDefaultTrace(err, this, attachFullStackTraceProfile);
4041
}
4142
}
4243
}

engine/runtime/src/main/java/org/enso/interpreter/node/expression/constant/LazyObjectNode.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.oracle.truffle.api.frame.VirtualFrame;
44
import com.oracle.truffle.api.interop.TruffleObject;
55
import com.oracle.truffle.api.nodes.NodeInfo;
6+
import com.oracle.truffle.api.profiles.BranchProfile;
67
import java.util.function.Supplier;
78
import org.enso.interpreter.node.ExpressionNode;
89
import org.enso.interpreter.runtime.data.text.Text;
@@ -16,6 +17,7 @@ public final class LazyObjectNode extends ExpressionNode {
1617

1718
private final String error;
1819
private final CachingSupplier<? extends Object> supply;
20+
private final BranchProfile attachFullStackTraceProfile = BranchProfile.create();
1921

2022
private LazyObjectNode(String error, Supplier<? extends Object> supply) {
2123
this.error = error;
@@ -39,6 +41,6 @@ public Object executeGeneric(VirtualFrame frame) {
3941
if (result instanceof TruffleObject) {
4042
return result;
4143
}
42-
return DataflowError.withDefaultTrace(Text.create(error), this);
44+
return DataflowError.withDefaultTrace(Text.create(error), this, attachFullStackTraceProfile);
4345
}
4446
}

engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/HashMapRemoveNode.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.oracle.truffle.api.interop.UnsupportedMessageException;
1414
import com.oracle.truffle.api.library.CachedLibrary;
1515
import com.oracle.truffle.api.nodes.Node;
16+
import com.oracle.truffle.api.profiles.BranchProfile;
1617
import org.enso.interpreter.dsl.BuiltinMethod;
1718
import org.enso.interpreter.node.expression.builtin.meta.EqualsNode;
1819
import org.enso.interpreter.node.expression.builtin.meta.HashCodeNode;
@@ -39,12 +40,13 @@ EnsoHashMap removeFromEnsoMap(
3940
EnsoHashMap ensoMap,
4041
Object key,
4142
@Shared("hash") @Cached HashCodeNode hashCodeNode,
42-
@Shared("equals") @Cached EqualsNode equalsNode) {
43+
@Shared("equals") @Cached EqualsNode equalsNode,
44+
@Cached BranchProfile attachFullStackTraceProfile) {
4345
var mapBuilder = ensoMap.getMapBuilder(frame, false, hashCodeNode, equalsNode);
4446
if (mapBuilder.remove(frame, key, hashCodeNode, equalsNode)) {
4547
return mapBuilder.build();
4648
} else {
47-
throw DataflowError.withDefaultTrace("No such key", null);
49+
throw DataflowError.withDefaultTrace("No such key", null, attachFullStackTraceProfile);
4850
}
4951
}
5052

engine/runtime/src/main/java/org/enso/interpreter/runtime/error/DataflowError.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.oracle.truffle.api.library.ExportLibrary;
1616
import com.oracle.truffle.api.library.ExportMessage;
1717
import com.oracle.truffle.api.nodes.Node;
18+
import com.oracle.truffle.api.profiles.BranchProfile;
1819
import java.util.Objects;
1920
import org.enso.interpreter.node.callable.IndirectInvokeMethodNode;
2021
import org.enso.interpreter.node.expression.builtin.text.util.TypeToDisplayTextNode;
@@ -49,16 +50,19 @@ public final class DataflowError extends AbstractTruffleException implements Ens
4950
*
5051
* @param payload the user-provided value carried by the error
5152
* @param location the node in which the error was created
53+
* @param attachFullStackTraceProfile
5254
* @return a new dataflow error
5355
*/
54-
public static DataflowError withDefaultTrace(State state, Object payload, Node location) {
56+
public static DataflowError withDefaultTrace(
57+
State state, Object payload, Node location, BranchProfile attachFullStackTraceProfile) {
5558
assert payload != null;
5659
boolean attachFullStackTrace =
5760
state == null
5861
|| EnsoContext.get(location)
5962
.getExecutionEnvironment()
6063
.hasContextEnabled("Dataflow_Stack_Trace");
6164
if (attachFullStackTrace) {
65+
attachFullStackTraceProfile.enter();
6266
var result = new DataflowError(payload, UNLIMITED_STACK_TRACE, location);
6367
TruffleStackTrace.fillIn(result);
6468
return result;
@@ -68,8 +72,13 @@ public static DataflowError withDefaultTrace(State state, Object payload, Node l
6872
}
6973
}
7074

75+
public static DataflowError withDefaultTrace(
76+
Object payload, Node location, BranchProfile attachFullStackTraceProfile) {
77+
return withDefaultTrace(null, payload, location, attachFullStackTraceProfile);
78+
}
79+
7180
public static DataflowError withDefaultTrace(Object payload, Node location) {
72-
return withDefaultTrace(null, payload, location);
81+
return withDefaultTrace(null, payload, location, BranchProfile.getUncached());
7382
}
7483

7584
/**

0 commit comments

Comments
 (0)