Skip to content

Commit

Permalink
Default enable new accumulator variable.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 708371506
  • Loading branch information
jnthntatum authored and copybara-github committed Dec 20, 2024
1 parent 8ce99ed commit b95bae4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 94 deletions.
10 changes: 5 additions & 5 deletions compiler/compiler_factory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST(CompilerFactoryTest, Works) {
NewCompilerBuilder(cel::internal::GetSharedTestingDescriptorPool()));

ASSERT_THAT(builder->AddLibrary(StandardCheckerLibrary()), IsOk());

builder->GetParserBuilder().GetOptions().enable_hidden_accumulator_var = true;
ASSERT_OK_AND_ASSIGN(auto compiler, std::move(*builder).Build());

ASSERT_OK_AND_ASSIGN(
Expand All @@ -71,18 +71,18 @@ TEST(CompilerFactoryTest, Works) {
"c"~string
]~list(string),
// Accumulator
__result__,
@result,
// Init
false~bool,
// LoopCondition
@not_strictly_false(
!_(
__result__~bool^__result__
@result~bool^@result
)~bool^logical_not
)~bool^not_strictly_false,
// LoopStep
_||_(
__result__~bool^__result__,
@result~bool^@result,
@in(
x~string^x,
[
Expand All @@ -93,7 +93,7 @@ TEST(CompilerFactoryTest, Works) {
)~bool^in_list
)~bool^logical_or,
// Result
__result__~bool^__result__)~bool,
@result~bool^@result)~bool,
_<_(
10~int,
_-_(
Expand Down
16 changes: 8 additions & 8 deletions extensions/comprehensions_v2_macros.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ absl::optional<Expr> ExpandAllMacro2(MacroExprFactory& factory, Expr& target,
auto result = factory.NewAccuIdent();
return factory.NewComprehension(
args[0].ident_expr().name(), args[1].ident_expr().name(),
std::move(target), kAccumulatorVariableName, std::move(init),
std::move(target), factory.AccuVarName(), std::move(init),
std::move(condition), std::move(step), std::move(result));
}

Expand Down Expand Up @@ -119,7 +119,7 @@ absl::optional<Expr> ExpandExistsMacro2(MacroExprFactory& factory, Expr& target,
auto result = factory.NewAccuIdent();
return factory.NewComprehension(
args[0].ident_expr().name(), args[1].ident_expr().name(),
std::move(target), kAccumulatorVariableName, std::move(init),
std::move(target), factory.AccuVarName(), std::move(init),
std::move(condition), std::move(step), std::move(result));
}

Expand Down Expand Up @@ -172,7 +172,7 @@ absl::optional<Expr> ExpandExistsOneMacro2(MacroExprFactory& factory,
factory.NewIntConst(1));
return factory.NewComprehension(
args[0].ident_expr().name(), args[1].ident_expr().name(),
std::move(target), kAccumulatorVariableName, std::move(init),
std::move(target), factory.AccuVarName(), std::move(init),
std::move(condition), std::move(step), std::move(result));
}

Expand Down Expand Up @@ -220,7 +220,7 @@ absl::optional<Expr> ExpandFilterMacro2(MacroExprFactory& factory, Expr& target,
step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[2]),
std::move(step), factory.NewAccuIdent());
return factory.NewComprehension(
name, name2, std::move(target), kAccumulatorVariableName, std::move(init),
name, name2, std::move(target), factory.AccuVarName(), std::move(init),
std::move(condition), std::move(step), factory.NewAccuIdent());
}

Expand Down Expand Up @@ -268,7 +268,7 @@ absl::optional<Expr> ExpandTransformList3Macro(MacroExprFactory& factory,
CelOperator::ADD, factory.NewAccuIdent(),
factory.NewList(factory.NewListElement(std::move(args[2]))));
return factory.NewComprehension(std::move(iter_var), std::move(iter_var2),
std::move(target), kAccumulatorVariableName,
std::move(target), factory.AccuVarName(),
factory.NewList(), factory.NewBoolConst(true),
std::move(step), factory.NewAccuIdent());
}
Expand Down Expand Up @@ -319,7 +319,7 @@ absl::optional<Expr> ExpandTransformList4Macro(MacroExprFactory& factory,
step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[2]),
std::move(step), factory.NewAccuIdent());
return factory.NewComprehension(std::move(iter_var), std::move(iter_var2),
std::move(target), kAccumulatorVariableName,
std::move(target), factory.AccuVarName(),
factory.NewList(), factory.NewBoolConst(true),
std::move(step), factory.NewAccuIdent());
}
Expand Down Expand Up @@ -367,7 +367,7 @@ absl::optional<Expr> ExpandTransformMap3Macro(MacroExprFactory& factory,
auto step = factory.NewCall("cel.@mapInsert", factory.NewAccuIdent(),
std::move(args[0]), std::move(args[2]));
return factory.NewComprehension(std::move(iter_var), std::move(iter_var2),
std::move(target), kAccumulatorVariableName,
std::move(target), factory.AccuVarName(),
factory.NewMap(), factory.NewBoolConst(true),
std::move(step), factory.NewAccuIdent());
}
Expand Down Expand Up @@ -417,7 +417,7 @@ absl::optional<Expr> ExpandTransformMap4Macro(MacroExprFactory& factory,
step = factory.NewCall(CelOperator::CONDITIONAL, std::move(args[2]),
std::move(step), factory.NewAccuIdent());
return factory.NewComprehension(std::move(iter_var), std::move(iter_var2),
std::move(target), kAccumulatorVariableName,
std::move(target), factory.AccuVarName(),
factory.NewMap(), factory.NewBoolConst(true),
std::move(step), factory.NewAccuIdent());
}
Expand Down
2 changes: 1 addition & 1 deletion parser/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct ParserOptions final {
bool disable_standard_macros = false;

// Enable hidden accumulator variable '@result' for builtin comprehensions.
bool enable_hidden_accumulator_var = false;
bool enable_hidden_accumulator_var = true;
};

} // namespace cel
Expand Down
Loading

0 comments on commit b95bae4

Please sign in to comment.