Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions common/src/main/java/dev/cel/common/CelOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public enum ProtoUnsetFieldOptions {

public abstract boolean retainUnbalancedLogicalExpressions();

public abstract boolean enableHiddenAccumulatorVar();

public abstract boolean enableQuotedIdentifierSyntax();

public abstract boolean enablePrattParser();
Expand Down Expand Up @@ -144,7 +142,6 @@ public static Builder newBuilder() {
.populateMacroCalls(false)
.retainRepeatedUnaryOperators(false)
.retainUnbalancedLogicalExpressions(false)
.enableHiddenAccumulatorVar(true)
.enableQuotedIdentifierSyntax(true)
.enablePrattParser(false)
// Type-Checker options
Expand Down Expand Up @@ -262,16 +259,6 @@ public abstract static class Builder {
*/
public abstract Builder retainUnbalancedLogicalExpressions(boolean value);

/**
* Enable the use of a hidden accumulator variable name.
*
* <p>This is a temporary option to transition to using an internal identifier for the
* accumulator variable used by builtin comprehension macros. When enabled, parses result in a
* semantically equivalent AST, but with a different accumulator variable that can't be directly
* referenced in the source expression.
*/
public abstract Builder enableHiddenAccumulatorVar(boolean value);

/**
* Enable quoted identifier syntax.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelContainer;
import dev.cel.common.CelFunctionDecl;
import dev.cel.common.CelOptions;
import dev.cel.common.CelOverloadDecl;
import dev.cel.common.types.SimpleType;
import dev.cel.common.types.StructTypeReference;
Expand Down Expand Up @@ -274,7 +273,6 @@ public void map() throws Exception {
public void comprehension() throws Exception {
CelCompiler celCompiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(CelOptions.current().enableHiddenAccumulatorVar(true).build())
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("[1, 2, 3].exists(x, x > 0)").getAst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.collect.ImmutableList;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelContainer;
import dev.cel.common.CelOptions;
import dev.cel.common.Operator;
import dev.cel.common.ast.CelExpr.CelCall;
import dev.cel.common.ast.CelExpr.CelComprehension;
Expand Down Expand Up @@ -327,7 +326,6 @@ public void visitList() throws Exception {
public void visitComprehension() throws Exception {
CelCompiler celCompiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(CelOptions.current().enableHiddenAccumulatorVar(true).build())
.setStandardMacros(CelStandardMacro.ALL)
.build();
CelAbstractSyntaxTree ast = celCompiler.compile("[1, 1].all(x, x == 1)").getAst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ public void emptyMapConstruction_allNodesReturned() throws Exception {
public void comprehension_preOrder_allNodesReturned() throws Exception {
CelCompiler compiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(CelOptions.current().enableHiddenAccumulatorVar(true).build())
.setStandardMacros(CelStandardMacro.EXISTS)
.build();
CelAbstractSyntaxTree ast = compiler.compile("[true].exists(i, i)").getAst();
Expand Down Expand Up @@ -873,7 +872,6 @@ public void comprehension_preOrder_allNodesReturned() throws Exception {
public void comprehension_postOrder_allNodesReturned() throws Exception {
CelCompiler compiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(CelOptions.current().enableHiddenAccumulatorVar(true).build())
.setStandardMacros(CelStandardMacro.EXISTS)
.build();
CelAbstractSyntaxTree ast = compiler.compile("[true].exists(i, i)").getAst();
Expand Down Expand Up @@ -1011,7 +1009,6 @@ public void comprehension_postOrder_maxIdsSet() throws Exception {
public void comprehension_allNodes_parentsPopulated() throws Exception {
CelCompiler compiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(CelOptions.current().enableHiddenAccumulatorVar(true).build())
.setStandardMacros(CelStandardMacro.EXISTS)
.build();
CelAbstractSyntaxTree ast = compiler.compile("[true].exists(i, i)").getAst();
Expand Down Expand Up @@ -1070,7 +1067,6 @@ public void comprehension_allNodes_parentsPopulated() throws Exception {
public void comprehension_filterComprehension_allNodesReturned() throws Exception {
CelCompiler compiler =
CelCompilerFactory.standardCelCompilerBuilder()
.setOptions(CelOptions.current().enableHiddenAccumulatorVar(true).build())
.setStandardMacros(CelStandardMacro.EXISTS)
.build();
CelAbstractSyntaxTree ast = compiler.compile("[true].exists(i, i)").getAst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ private static CelExpr validatedIterationVariable(
CelExpr arg = checkNotNull(argument);
if (!isSimpleIdentifier(arg)) {
return reportArgumentError(exprFactory, arg);
} else if (arg.exprKind().ident().name().equals("__result__")) {
} else if (arg.exprKind().ident().name().equals(exprFactory.getAccumulatorVarName())
|| arg.exprKind().ident().name().equals("__result__")) {
return reportAccumulatorOverwriteError(exprFactory, arg);
} else {
return arg;
Expand Down
2 changes: 1 addition & 1 deletion optimizer/src/main/java/dev/cel/optimizer/AstMutator.java
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ private CelMutableExpr mangleIdentsInComprehensionExpr(

comprehension.setIterVar(mangledComprehensionName.iterVarName());

// Most standard macros set accu_var as __result__, but not all (ex: cel.bind).
// Most standard macros set accu_var as @result, but not all (ex: cel.bind).
if (comprehension.accuVar().equals(originalAccuVar)) {
comprehension.setAccuVar(mangledComprehensionName.resultName());
}
Expand Down
8 changes: 2 additions & 6 deletions parser/src/main/java/dev/cel/parser/AntlrParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ final class AntlrParser extends CELBaseVisitor<CelExpr> {
"var",
"void",
"while");
private static final String ACCUMULATOR_NAME = "__result__";
private static final String HIDDEN_ACCUMULATOR_NAME = "@result";
private static final String ACCUMULATOR_NAME = "@result";

static CelValidationResult parse(
CelSource source, CelOptions options, Collection<CelMacro> macros) {
Expand All @@ -151,10 +150,7 @@ static CelValidationResult parse(
sourceInfo.setDescription(source.getDescription());
ExprFactory exprFactory =
new ExprFactory(
antlrParser,
sourceInfo,
options.enableHiddenAccumulatorVar() ? HIDDEN_ACCUMULATOR_NAME : ACCUMULATOR_NAME,
options.maxParseExpressionNodeCount());
antlrParser, sourceInfo, ACCUMULATOR_NAME, options.maxParseExpressionNodeCount());
AntlrParser parserImpl = new AntlrParser(options, macros, sourceInfo, exprFactory);
ErrorListener errorListener = new ErrorListener(exprFactory);
antlrLexer.removeErrorListeners();
Expand Down
3 changes: 2 additions & 1 deletion parser/src/main/java/dev/cel/parser/CelStandardMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ private static CelExpr validatedIterationVariable(
CelExpr arg = checkNotNull(argument);
if (!isSimpleIdentifier(arg)) {
return reportArgumentError(exprFactory, arg);
} else if (arg.exprKind().ident().name().equals("__result__")) {
} else if (arg.exprKind().ident().name().equals(exprFactory.getAccumulatorVarName())
|| arg.exprKind().ident().name().equals("__result__")) {
return reportAccumulatorOverwriteError(exprFactory, arg);
} else {
return arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public CelExpr reportError(CelIssue issue) {

@Override
public String getAccumulatorVarName() {
return "__result__";
return "@result";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public final class CelParserParameterizedTest extends BaselineTestCase {
.populateMacroCalls(true)
.enableOptionalSyntax(true)
.enableQuotedIdentifierSyntax(true)
.enableHiddenAccumulatorVar(true)
.build();

private static final CelOptions OPTIONS_MAX_RECURSION_DEPTH_32 =
Expand All @@ -74,9 +73,6 @@ public final class CelParserParameterizedTest extends BaselineTestCase {
private static final CelOptions OPTIONS_MAX_ERROR_RECOVERY_LIMIT_2 =
OPTIONS.toBuilder().maxParseErrorRecoveryLimit(2).build();

private static final CelOptions OPTIONS_OLD_ACCU_VAR =
OPTIONS.toBuilder().enableHiddenAccumulatorVar(false).build();

private static final ImmutableMap<String, CelMacro> MACROS =
ImmutableMap.<String, CelMacro>builder()
.putAll(
Expand Down Expand Up @@ -681,17 +677,6 @@ public void parser_errors() {
runTest(OPTIONS_MAX_ERROR_RECOVERY_LIMIT_2, "[1 2 3 a b c]");
}

@Test
public void parser_legacyAccuVar() {
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "x * 2");
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "has(m.f)");
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "m.exists_one(v, f)");
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "m.all(v, f)");
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "m.map(v, f)");
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "m.map(v, p, f)");
runAntlrTest(OPTIONS_OLD_ACCU_VAR, "m.filter(v, p)");
}

private void runAntlrTest(CelOptions options, String expression) {
testOutput().println("I: " + sanitizeForBaseline(expression));
testOutput().println("=====>");
Expand Down
Loading
Loading