Skip to content

Commit

Permalink
Draft: default enable updated accumulator variable.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707607511
  • Loading branch information
jnthntatum authored and copybara-github committed Dec 18, 2024
1 parent 6535745 commit f3d6f7d
Show file tree
Hide file tree
Showing 16 changed files with 535 additions and 174 deletions.
28 changes: 14 additions & 14 deletions checker/src/test/resources/mapExpr.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ __comprehension__(
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
__result__,
@result,
// Init
[]~list(double),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(double)^__result__,
@result~list(double)^@result,
[
double(
x~int^x
)~double^int64_to_double
]~list(double)
)~list(double)^add_list,
// Result
__result__~list(double)^__result__)~list(double)
@result~list(double)^@result)~list(double)

Source: [].map(x, [].map(y, x in y && y in x))
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
ERROR: test_location:1:33: found no matching overload for '@in' applied to '(list(%elem0), %elem0)' (candidates: (%A7, list(%A7)),(%A8, map(%A8, %B9)))
| [].map(x, [].map(y, x in y && y in x))
| ................................^
| [].map(x, [].map(y, x in y && y in x))
| ................................^

Source: [{}.map(c,c,c)]+[{}.map(c,c,c)]
declare x {
Expand All @@ -48,7 +48,7 @@ _+_(
// Target
{}~map(bool, dyn),
// Accumulator
__result__,
@result,
// Init
[]~list(bool),
// LoopCondition
Expand All @@ -57,15 +57,15 @@ _+_(
_?_:_(
c~bool^c,
_+_(
__result__~list(bool)^__result__,
@result~list(bool)^@result,
[
c~bool^c
]~list(bool)
)~list(bool)^add_list,
__result__~list(bool)^__result__
@result~list(bool)^@result
)~list(bool)^conditional,
// Result
__result__~list(bool)^__result__)~list(bool)
@result~list(bool)^@result)~list(bool)
]~list(list(bool)),
[
__comprehension__(
Expand All @@ -74,7 +74,7 @@ _+_(
// Target
{}~map(bool, dyn),
// Accumulator
__result__,
@result,
// Init
[]~list(bool),
// LoopCondition
Expand All @@ -83,14 +83,14 @@ _+_(
_?_:_(
c~bool^c,
_+_(
__result__~list(bool)^__result__,
@result~list(bool)^@result,
[
c~bool^c
]~list(bool)
)~list(bool)^add_list,
__result__~list(bool)^__result__
@result~list(bool)^@result
)~list(bool)^conditional,
// Result
__result__~list(bool)^__result__)~list(bool)
@result~list(bool)^@result)~list(bool)
]~list(list(bool))
)~list(list(bool))^add_list
)~list(list(bool))^add_list
24 changes: 12 additions & 12 deletions checker/src/test/resources/mapFilterExpr.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __comprehension__(
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
__result__,
@result,
// Init
[]~list(double),
// LoopCondition
Expand All @@ -21,17 +21,17 @@ __comprehension__(
0~int
)~bool^greater_int64,
_+_(
__result__~list(double)^__result__,
@result~list(double)^@result,
[
double(
x~int^x
)~double^int64_to_double
]~list(double)
)~list(double)^add_list,
__result__~list(double)^__result__
@result~list(double)^@result
)~list(double)^conditional,
// Result
__result__~list(double)^__result__)~list(double)
@result~list(double)^@result)~list(double)

Source: lists.filter(x, x > 1.5)
declare x {
Expand All @@ -47,7 +47,7 @@ __comprehension__(
// Target
lists~dyn^lists,
// Accumulator
__result__,
@result,
// Init
[]~list(dyn),
// LoopCondition
Expand All @@ -59,15 +59,15 @@ __comprehension__(
1.5~double
)~bool^greater_double|greater_int64_double|greater_uint64_double,
_+_(
__result__~list(dyn)^__result__,
@result~list(dyn)^@result,
[
x~dyn^x
]~list(dyn)
)~list(dyn)^add_list,
__result__~list(dyn)^__result__
@result~list(dyn)^@result
)~list(dyn)^conditional,
// Result
__result__~list(dyn)^__result__)~list(dyn)
@result~list(dyn)^@result)~list(dyn)

Source: args.user["myextension"].customAttributes.filter(x, x.name == "hobbies")
declare x {
Expand All @@ -89,7 +89,7 @@ __comprehension__(
"myextension"~string
)~dyn^index_map.customAttributes~dyn,
// Accumulator
__result__,
@result,
// Init
[]~list(dyn),
// LoopCondition
Expand All @@ -101,12 +101,12 @@ __comprehension__(
"hobbies"~string
)~bool^equals,
_+_(
__result__~list(dyn)^__result__,
@result~list(dyn)^@result,
[
x~dyn^x
]~list(dyn)
)~list(dyn)^add_list,
__result__~list(dyn)^__result__
@result~list(dyn)^@result
)~list(dyn)^conditional,
// Result
__result__~list(dyn)^__result__)~list(dyn)
@result~list(dyn)^@result)~list(dyn)
14 changes: 7 additions & 7 deletions checker/src/test/resources/namespacedFunctions.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ __comprehension__(
)~int^ns_func_overload
]~list(int),
// Accumulator
__result__,
@result,
// Init
[]~list(int),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(int)^__result__,
@result~list(int)^@result,
[
_*_(
x~int^x,
Expand All @@ -100,7 +100,7 @@ __comprehension__(
]~list(int)
)~list(int)^add_list,
// Result
__result__~list(int)^__result__)~list(int)
@result~list(int)^@result)~list(int)

Source: [1, 2].map(x, x * ns.func('test'))
declare ns.func {
Expand All @@ -119,14 +119,14 @@ __comprehension__(
2~int
]~list(int),
// Accumulator
__result__,
@result,
// Init
[]~list(int),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(int)^__result__,
@result~list(int)^@result,
[
_*_(
x~int^x,
Expand All @@ -137,7 +137,7 @@ __comprehension__(
]~list(int)
)~list(int)^add_list,
// Result
__result__~list(int)^__result__)~list(int)
@result~list(int)^@result)~list(int)

Source: func('hello')
declare ns.func {
Expand Down Expand Up @@ -165,4 +165,4 @@ ns.func(
ns.func(
"test"~string
)~int^ns_func_overload
)~int^ns_member_overload
)~int^ns_member_overload
26 changes: 13 additions & 13 deletions checker/src/test/resources/quantifiers.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@ _&&_(
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
__result__,
@result,
// Init
true~bool,
// LoopCondition
@not_strictly_false(
__result__~bool^__result__
@result~bool^@result
)~bool^not_strictly_false,
// LoopStep
_&&_(
__result__~bool^__result__,
@result~bool^@result,
_>_(
e~int^e,
0~int
)~bool^greater_int64
)~bool^logical_and,
// Result
__result__~bool^__result__)~bool,
@result~bool^@result)~bool,
__comprehension__(
// Variable
e,
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// 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,
_<_(
e~int^e,
0~int
)~bool^less_int64
)~bool^logical_or,
// Result
__result__~bool^__result__)~bool
@result~bool^@result)~bool
)~bool^logical_and,
__comprehension__(
// Variable
e,
// Target
x~cel.expr.conformance.proto3.TestAllTypes^x.repeated_int64~list(int),
// Accumulator
__result__,
@result,
// Init
0~int,
// LoopCondition
Expand All @@ -72,14 +72,14 @@ _&&_(
0~int
)~bool^equals,
_+_(
__result__~int^__result__,
@result~int^@result,
1~int
)~int^add_int64,
__result__~int^__result__
@result~int^@result
)~int^conditional,
// Result
_==_(
__result__~int^__result__,
@result~int^@result,
1~int
)~bool^equals)~bool
)~bool^logical_and
)~bool^logical_and
6 changes: 3 additions & 3 deletions checker/src/test/resources/types.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ __comprehension__(
// Target
{}~map(dyn, dyn),
// Accumulator
__result__,
@result,
// Init
[]~list(list(dyn)),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(list(dyn))^__result__,
@result~list(list(dyn))^@result,
[
[
c~dyn^c,
Expand All @@ -45,4 +45,4 @@ __comprehension__(
]~list(list(dyn))
)~list(list(dyn))^add_list,
// Result
__result__~list(list(dyn))^__result__)~list(list(dyn))
@result~list(list(dyn))^@result)~list(list(dyn))
13 changes: 13 additions & 0 deletions common/src/main/java/dev/cel/common/CelOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public enum ProtoUnsetFieldOptions {

public abstract boolean retainUnbalancedLogicalExpressions();

public abstract boolean enableHiddenAccumulatorVar();

// Type-Checker related options

public abstract boolean enableCompileTimeOverloadResolution();
Expand Down Expand Up @@ -188,6 +190,7 @@ public static Builder newBuilder() {
.populateMacroCalls(false)
.retainRepeatedUnaryOperators(false)
.retainUnbalancedLogicalExpressions(false)
.enableHiddenAccumulatorVar(true)
// Type-Checker options
.enableCompileTimeOverloadResolution(false)
.enableHomogeneousLiterals(false)
Expand Down Expand Up @@ -319,6 +322,16 @@ 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);

// Type-Checker related options

/**
Expand Down
Loading

0 comments on commit f3d6f7d

Please sign in to comment.