Skip to content

Commit c368450

Browse files
l46kokcopybara-github
authored andcommitted
Remove dead code in interpreter util
PiperOrigin-RevId: 785326726
1 parent 57f8218 commit c368450

2 files changed

Lines changed: 5 additions & 39 deletions

File tree

runtime/src/main/java/dev/cel/runtime/DefaultInterpreter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,8 @@ private IntermediateResult mergeBooleanUnknowns(IntermediateResult lhs, Intermed
585585
return rhs;
586586
}
587587

588-
// Otherwise fallback to normal impl
589-
return IntermediateResult.create(
590-
InterpreterUtil.shortcircuitUnknownOrThrowable(lhsVal, rhsVal));
588+
// Otherwise, enforce strictness on both args
589+
return IntermediateResult.create(InterpreterUtil.enforceStrictness(lhsVal, rhsVal));
591590
}
592591

593592
private enum ShortCircuitableOperators {

runtime/src/main/java/dev/cel/runtime/InterpreterUtil.java

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import com.google.errorprone.annotations.CheckReturnValue;
1818
import dev.cel.common.annotations.Internal;
19-
import java.util.LinkedHashSet;
20-
import java.util.Set;
2119
import org.jspecify.annotations.Nullable;
2220

2321
/**
@@ -74,42 +72,11 @@ static AccumulatedUnknowns adaptToAccumulatedUnknowns(CelUnknownSet unknowns) {
7472
return AccumulatedUnknowns.create(unknowns.unknownExprIds(), unknowns.attributes());
7573
}
7674

77-
static AccumulatedUnknowns combineUnknownExprValue(Object... objs) {
78-
Set<Long> ids = new LinkedHashSet<>();
79-
for (Object object : objs) {
80-
if (isAccumulatedUnknowns(object)) {
81-
ids.addAll(((AccumulatedUnknowns) object).exprIds());
82-
}
83-
}
84-
85-
return AccumulatedUnknowns.create(ids);
86-
}
87-
8875
/**
89-
* Short circuit unknown or error arguments to logical operators.
90-
*
91-
* <p>Given two arguments, one of which must be throwable (error) or unknown, returns the result
92-
* from the && or || operators for these arguments, assuming that the result cannot be determined
93-
* from any boolean arguments alone. This allows us to consolidate the error/unknown handling for
94-
* both of these operators.
76+
* Enforces strictness on both lhs/rhs arguments from logical operators (i.e: intentionally throws
77+
* an appropriate exception when {@link Throwable} is encountered as part of evaluated result.
9578
*/
96-
public static Object shortcircuitUnknownOrThrowable(Object left, Object right)
97-
throws CelEvaluationException {
98-
// unknown <op> unknown ==> unknown combined
99-
if (InterpreterUtil.isAccumulatedUnknowns(left)
100-
&& InterpreterUtil.isAccumulatedUnknowns(right)) {
101-
return InterpreterUtil.combineUnknownExprValue(left, right);
102-
}
103-
// unknown <op> <error> ==> unknown
104-
// unknown <op> t|f ==> unknown
105-
if (InterpreterUtil.isAccumulatedUnknowns(left)) {
106-
return left;
107-
}
108-
// <error> <op> unknown ==> unknown
109-
// t|f <op> unknown ==> unknown
110-
if (InterpreterUtil.isAccumulatedUnknowns(right)) {
111-
return right;
112-
}
79+
public static Object enforceStrictness(Object left, Object right) throws CelEvaluationException {
11380
// Throw left or right side exception for now, should combine them into ErrorSet.
11481
// <error> <op> <error> ==> <error>
11582
if (left instanceof Throwable) {

0 commit comments

Comments
 (0)