From 95cb753ebfbceb67240e67b9fe53e81619831962 Mon Sep 17 00:00:00 2001 From: Sokwhan Huh Date: Mon, 22 Apr 2024 09:59:45 -0700 Subject: [PATCH] Fully perform CSE on presence tests where possible PiperOrigin-RevId: 627071810 --- .../optimizers/SubexpressionOptimizer.java | 2 - ...old_before_subexpression_unparsed.baseline | 14 +- ...ion_ast_block_common_subexpr_only.baseline | 32 +-- ...ssion_ast_block_recursion_depth_1.baseline | 271 +++++++++++------- ...ssion_ast_block_recursion_depth_2.baseline | 120 ++++---- ...ssion_ast_block_recursion_depth_3.baseline | 52 ++-- ...ssion_ast_block_recursion_depth_4.baseline | 32 +-- ...ssion_ast_block_recursion_depth_5.baseline | 32 +-- ...ssion_ast_block_recursion_depth_6.baseline | 32 +-- ...ssion_ast_block_recursion_depth_7.baseline | 32 +-- ...ssion_ast_block_recursion_depth_8.baseline | 32 +-- ...ssion_ast_block_recursion_depth_9.baseline | 32 +-- .../subexpression_ast_cascaded_binds.baseline | 36 ++- .../resources/subexpression_unparsed.baseline | 38 +-- 14 files changed, 392 insertions(+), 365 deletions(-) diff --git a/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java b/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java index 25d15cc4c..a71e83912 100644 --- a/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java +++ b/optimizer/src/main/java/dev/cel/optimizer/optimizers/SubexpressionOptimizer.java @@ -555,8 +555,6 @@ private boolean canEliminate(CelNavigableMutableExpr navigableExpr) { && !navigableExpr.getKind().equals(Kind.IDENT) && !(navigableExpr.getKind().equals(Kind.IDENT) && navigableExpr.expr().ident().name().startsWith(BIND_IDENTIFIER_PREFIX)) - && !(navigableExpr.getKind().equals(Kind.SELECT) - && navigableExpr.expr().select().testOnly()) && containsEliminableFunctionOnly(navigableExpr) && isWithinInlineableComprehension(navigableExpr); } diff --git a/optimizer/src/test/resources/constfold_before_subexpression_unparsed.baseline b/optimizer/src/test/resources/constfold_before_subexpression_unparsed.baseline index 8aeacf84e..ab1e6e12b 100644 --- a/optimizer/src/test/resources/constfold_before_subexpression_unparsed.baseline +++ b/optimizer/src/test/resources/constfold_before_subexpression_unparsed.baseline @@ -452,7 +452,7 @@ Source: (has(msg.oneof_type.payload) ? msg.oneof_type.payload.single_int64 : 0) Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type, has(@r0.payload) ? @r0.payload.single_int64 : 0) == 10 [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type], (has(@index0.payload) ? @index0.payload.single_int64 : 0) == 10) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64], (has(@index0.payload) ? @index2 : 0) == 10) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, has(@index0.payload), @index0.payload, @index2.single_int64, @index1 ? @index3 : 0], @index4 == 10) [BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type, @index0.payload.single_int64, has(@index0.payload) ? @index1 : 0], @index2 == 10) [BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type, has(@index0.payload) ? @index0.payload.single_int64 : 0], @index1 == 10) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type], (has(@index0.payload) ? @index0.payload.single_int64 : 0) == 10) @@ -468,8 +468,8 @@ Source: (has(msg.oneof_type.payload) ? msg.oneof_type.payload.single_int64 : msg Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type, cel.bind(@r1, @r0.payload.single_int64, has(@r0.payload) ? @r1 : (@r1 * 0))) == 10 [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type, @index0.payload.single_int64], (has(@index0.payload) ? @index1 : (@index1 * 0)) == 10) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, @index2 * 0], (has(@index0.payload) ? @index2 : @index3) == 10) -[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.single_int64, msg.oneof_type, has(@index2.payload) ? @index1 : (@index1 * 0)], @index3 == 10) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, has(@index0.payload), @index2 * 0, @index3 ? @index2 : @index4], @index5 == 10) +[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.single_int64, has(msg.oneof_type.payload), @index2 ? @index1 : (@index1 * 0)], @index3 == 10) [BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.single_int64, has(msg.oneof_type.payload) ? @index0 : (@index0 * 0)], @index1 == 10) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload) ? @index0 : (@index0 * 0)) == 10) [BLOCK_RECURSION_DEPTH_5]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload) ? @index0 : (@index0 * 0)) == 10) @@ -484,9 +484,9 @@ Source: (has(msg.oneof_type.payload.single_int64) ? msg.oneof_type.payload.singl Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type.payload, cel.bind(@r1, @r0.single_int64, has(@r0.single_int64) ? @r1 : (@r1 * 0))) == 10 [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type.payload, @index0.single_int64], (has(@index0.single_int64) ? @index1 : (@index1 * 0)) == 10) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, @index2 * 0], (has(@index1.single_int64) ? @index2 : @index3) == 10) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, has(@index1.single_int64), @index2 * 0, @index3 ? @index2 : @index4], @index5 == 10) [BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.single_int64, has(@index0.single_int64) ? @index1 : (@index1 * 0)], @index2 == 10) -[BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.single_int64, msg.oneof_type.payload], (has(@index1.single_int64) ? @index0 : (@index0 * 0)) == 10) +[BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.single_int64, has(msg.oneof_type.payload.single_int64)], (@index1 ? @index0 : (@index0 * 0)) == 10) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type.payload.single_int64, has(msg.oneof_type.payload.single_int64) ? @index0 : (@index0 * 0)], @index1 == 10) [BLOCK_RECURSION_DEPTH_5]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload.single_int64) ? @index0 : (@index0 * 0)) == 10) [BLOCK_RECURSION_DEPTH_6]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload.single_int64) ? @index0 : (@index0 * 0)) == 10) @@ -500,8 +500,8 @@ Source: (has(msg.oneof_type) && has(msg.oneof_type.payload) && has(msg.oneof_typ Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type, cel.bind(@r1, @r0.payload, (has(msg.oneof_type) && has(@r0.payload) && has(@r1.single_int64)) ? cel.bind(@r2, @r1.map_string_string, (has(@r1.map_string_string) && has(@r2.key)) ? (@r2.key == "A") : false) : false)) [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type, @index0.payload, @index1.map_string_string], (has(msg.oneof_type) && has(@index0.payload) && has(@index1.single_int64)) ? ((has(@index1.map_string_string) && has(@index2.key)) ? (@index2.key == "A") : false) : false) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.map_string_string, @index2.key, @index3 == "A"], (has(msg.oneof_type) && has(@index0.payload) && has(@index1.single_int64)) ? ((has(@index1.map_string_string) && has(@index2.key)) ? @index4 : false) : false) -[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.map_string_string, has(@index0.map_string_string) && has(@index1.key), @index1.key == "A", msg.oneof_type, has(msg.oneof_type) && has(@index4.payload), @index5 && has(@index0.single_int64)], @index6 ? (@index2 ? @index3 : false) : false) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.map_string_string, has(msg.oneof_type), has(@index0.payload), @index3 && @index4, has(@index1.single_int64), @index5 && @index6, has(@index1.map_string_string), has(@index2.key), @index8 && @index9, @index2.key, @index11 == "A", @index10 ? @index12 : false], @index7 ? @index13 : false) +[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.map_string_string, has(msg.oneof_type.payload), has(msg.oneof_type) && @index2, @index3 && has(@index0.single_int64), has(@index0.map_string_string) && has(@index1.key), @index1.key == "A"], @index4 ? (@index5 ? @index6 : false) : false) [BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.map_string_string, msg.oneof_type.payload, has(msg.oneof_type) && has(msg.oneof_type.payload), (has(@index1.map_string_string) && has(@index0.key)) ? (@index0.key == "A") : false], (@index2 && has(@index1.single_int64)) ? @index3 : false) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type.payload.map_string_string, msg.oneof_type.payload, has(msg.oneof_type) && has(msg.oneof_type.payload) && has(@index1.single_int64)], @index2 ? ((has(@index1.map_string_string) && has(@index0.key)) ? (@index0.key == "A") : false) : false) [BLOCK_RECURSION_DEPTH_5]: cel.@block([msg.oneof_type.payload.map_string_string, msg.oneof_type.payload], (has(msg.oneof_type) && has(msg.oneof_type.payload) && has(@index1.single_int64)) ? ((has(@index1.map_string_string) && has(@index0.key)) ? (@index0.key == "A") : false) : false) diff --git a/optimizer/src/test/resources/subexpression_ast_block_common_subexpr_only.baseline b/optimizer/src/test/resources/subexpression_ast_block_common_subexpr_only.baseline index d3026dd15..552ed004c 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_common_subexpr_only.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_common_subexpr_only.baseline @@ -2236,30 +2236,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_1.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_1.baseline index 4a37c61ff..cc88bd2e0 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_1.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_1.baseline @@ -2820,28 +2820,31 @@ CALL [1] { } } } - CALL [7] { + SELECT [7] { + IDENT [8] { + name: @index0 + }.a~presence_test + } + CALL [9] { function: _[_] args: { - IDENT [8] { + IDENT [10] { name: @index0 } - CONSTANT [9] { value: "a" } + CONSTANT [11] { value: "a" } } } } } - CALL [10] { + CALL [12] { function: _&&_ args: { - SELECT [11] { - IDENT [12] { - name: @index0 - }.a~presence_test - } IDENT [13] { name: @index1 } + IDENT [14] { + name: @index2 + } } } } @@ -2864,20 +2867,21 @@ CALL [1] { } } } + SELECT [7] { + IDENT [8] { + name: @index0 + }.a~presence_test + } } } - CALL [7] { + CALL [9] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index1 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [11] { + name: @index1 } } } @@ -2899,33 +2903,39 @@ CALL [1] { SELECT [5] { IDENT [6] { name: @index0 - }.payload + }.payload~presence_test } SELECT [7] { IDENT [8] { - name: @index1 + name: @index0 + }.payload + } + SELECT [9] { + IDENT [10] { + name: @index2 }.single_int64 } - } - } - CALL [9] { - function: _==_ - args: { - CALL [10] { + CALL [11] { function: _?_:_ args: { - SELECT [11] { - IDENT [12] { - name: @index0 - }.payload~presence_test + IDENT [12] { + name: @index1 } IDENT [13] { - name: @index2 + name: @index3 } CONSTANT [14] { value: 0 } } } - CONSTANT [15] { value: 10 } + } + } + CALL [15] { + function: _==_ + args: { + IDENT [16] { + name: @index4 + } + CONSTANT [17] { value: 10 } } } } @@ -2953,37 +2963,43 @@ CALL [1] { name: @index1 }.single_int64 } - CALL [9] { + SELECT [9] { + IDENT [10] { + name: @index0 + }.payload~presence_test + } + CALL [11] { function: _*_ args: { - IDENT [10] { + IDENT [12] { name: @index2 } - CONSTANT [11] { value: 0 } + CONSTANT [13] { value: 0 } } } - } - } - CALL [12] { - function: _==_ - args: { - CALL [13] { + CALL [14] { function: _?_:_ args: { - SELECT [14] { - IDENT [15] { - name: @index0 - }.payload~presence_test + IDENT [15] { + name: @index3 } IDENT [16] { name: @index2 } IDENT [17] { - name: @index3 + name: @index4 } } } - CONSTANT [18] { value: 10 } + } + } + CALL [18] { + function: _==_ + args: { + IDENT [19] { + name: @index5 + } + CONSTANT [20] { value: 10 } } } } @@ -3011,37 +3027,43 @@ CALL [1] { name: @index1 }.single_int64 } - CALL [9] { + SELECT [9] { + IDENT [10] { + name: @index1 + }.single_int64~presence_test + } + CALL [11] { function: _*_ args: { - IDENT [10] { + IDENT [12] { name: @index2 } - CONSTANT [11] { value: 0 } + CONSTANT [13] { value: 0 } } } - } - } - CALL [12] { - function: _==_ - args: { - CALL [13] { + CALL [14] { function: _?_:_ args: { - SELECT [14] { - IDENT [15] { - name: @index1 - }.single_int64~presence_test + IDENT [15] { + name: @index3 } IDENT [16] { name: @index2 } IDENT [17] { - name: @index3 + name: @index4 } } } - CONSTANT [18] { value: 10 } + } + } + CALL [18] { + function: _==_ + args: { + IDENT [19] { + name: @index5 + } + CONSTANT [20] { value: 10 } } } } @@ -3071,73 +3093,100 @@ CALL [1] { } SELECT [9] { IDENT [10] { - name: @index2 - }.key + name: msg + }.oneof_type~presence_test } - CALL [11] { - function: _==_ + SELECT [11] { + IDENT [12] { + name: @index0 + }.payload~presence_test + } + CALL [13] { + function: _&&_ args: { - IDENT [12] { + IDENT [14] { name: @index3 } - CONSTANT [13] { value: "A" } + IDENT [15] { + name: @index4 + } } } - } - } - CALL [14] { - function: _?_:_ - args: { - CALL [15] { + SELECT [16] { + IDENT [17] { + name: @index1 + }.single_int64~presence_test + } + CALL [18] { function: _&&_ args: { - CALL [16] { - function: _&&_ - args: { - SELECT [17] { - IDENT [18] { - name: msg - }.oneof_type~presence_test - } - SELECT [19] { - IDENT [20] { - name: @index0 - }.payload~presence_test - } - } + IDENT [19] { + name: @index5 } - SELECT [21] { - IDENT [22] { - name: @index1 - }.single_int64~presence_test + IDENT [20] { + name: @index6 } } } - CALL [23] { + SELECT [21] { + IDENT [22] { + name: @index1 + }.map_string_string~presence_test + } + SELECT [23] { + IDENT [24] { + name: @index2 + }.key~presence_test + } + CALL [25] { + function: _&&_ + args: { + IDENT [26] { + name: @index8 + } + IDENT [27] { + name: @index9 + } + } + } + SELECT [28] { + IDENT [29] { + name: @index2 + }.key + } + CALL [30] { + function: _==_ + args: { + IDENT [31] { + name: @index11 + } + CONSTANT [32] { value: "A" } + } + } + CALL [33] { function: _?_:_ args: { - CALL [24] { - function: _&&_ - args: { - SELECT [25] { - IDENT [26] { - name: @index1 - }.map_string_string~presence_test - } - SELECT [27] { - IDENT [28] { - name: @index2 - }.key~presence_test - } - } + IDENT [34] { + name: @index10 } - IDENT [29] { - name: @index4 + IDENT [35] { + name: @index12 } - CONSTANT [30] { value: false } + CONSTANT [36] { value: false } } } - CONSTANT [31] { value: false } + } + } + CALL [37] { + function: _?_:_ + args: { + IDENT [38] { + name: @index7 + } + IDENT [39] { + name: @index13 + } + CONSTANT [40] { value: false } } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_2.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_2.baseline index 47c8e9e13..aca5d438e 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_2.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_2.baseline @@ -2637,30 +2637,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } @@ -2734,17 +2732,17 @@ CALL [1] { }.single_int64 } SELECT [8] { - IDENT [9] { - name: msg - }.oneof_type + SELECT [9] { + IDENT [10] { + name: msg + }.oneof_type + }.payload~presence_test } - CALL [10] { + CALL [11] { function: _?_:_ args: { - SELECT [11] { - IDENT [12] { - name: @index2 - }.payload~presence_test + IDENT [12] { + name: @index2 } IDENT [13] { name: @index1 @@ -2848,63 +2846,63 @@ CALL [1] { name: @index0 }.map_string_string } - CALL [8] { + SELECT [8] { + SELECT [9] { + IDENT [10] { + name: msg + }.oneof_type + }.payload~presence_test + } + CALL [11] { function: _&&_ args: { - SELECT [9] { - IDENT [10] { - name: @index0 - }.map_string_string~presence_test + SELECT [12] { + IDENT [13] { + name: msg + }.oneof_type~presence_test } - SELECT [11] { - IDENT [12] { - name: @index1 - }.key~presence_test + IDENT [14] { + name: @index2 } } } - CALL [13] { - function: _==_ + CALL [15] { + function: _&&_ args: { - SELECT [14] { - IDENT [15] { - name: @index1 - }.key + IDENT [16] { + name: @index3 + } + SELECT [17] { + IDENT [18] { + name: @index0 + }.single_int64~presence_test } - CONSTANT [16] { value: "A" } } } - SELECT [17] { - IDENT [18] { - name: msg - }.oneof_type - } CALL [19] { function: _&&_ args: { SELECT [20] { IDENT [21] { - name: msg - }.oneof_type~presence_test + name: @index0 + }.map_string_string~presence_test } SELECT [22] { IDENT [23] { - name: @index4 - }.payload~presence_test + name: @index1 + }.key~presence_test } } } CALL [24] { - function: _&&_ + function: _==_ args: { - IDENT [25] { - name: @index5 - } - SELECT [26] { - IDENT [27] { - name: @index0 - }.single_int64~presence_test + SELECT [25] { + IDENT [26] { + name: @index1 + }.key } + CONSTANT [27] { value: "A" } } } } @@ -2913,16 +2911,16 @@ CALL [1] { function: _?_:_ args: { IDENT [29] { - name: @index6 + name: @index4 } CALL [30] { function: _?_:_ args: { IDENT [31] { - name: @index2 + name: @index5 } IDENT [32] { - name: @index3 + name: @index6 } CONSTANT [33] { value: false } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_3.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_3.baseline index ae572aed0..babd462ba 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_3.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_3.baseline @@ -2392,30 +2392,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } @@ -2538,23 +2536,23 @@ CALL [1] { } SELECT [7] { SELECT [8] { - IDENT [9] { - name: msg - }.oneof_type - }.payload + SELECT [9] { + IDENT [10] { + name: msg + }.oneof_type + }.payload + }.single_int64~presence_test } } } - CALL [10] { + CALL [11] { function: _==_ args: { - CALL [11] { + CALL [12] { function: _?_:_ args: { - SELECT [12] { - IDENT [13] { - name: @index1 - }.single_int64~presence_test + IDENT [13] { + name: @index1 } IDENT [14] { name: @index0 diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_4.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_4.baseline index d7df4463a..34e6aaca1 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_4.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_4.baseline @@ -2329,30 +2329,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_5.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_5.baseline index ce5eafd5f..36fe2713b 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_5.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_5.baseline @@ -2299,30 +2299,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_6.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_6.baseline index 614a372a6..affa76d8c 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_6.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_6.baseline @@ -2293,30 +2293,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_7.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_7.baseline index 773c56aa2..d962803ee 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_7.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_7.baseline @@ -2290,30 +2290,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_8.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_8.baseline index 1d8371442..feab00f27 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_8.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_8.baseline @@ -2272,30 +2272,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_9.baseline b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_9.baseline index cd73ba02a..03f9e8cad 100644 --- a/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_9.baseline +++ b/optimizer/src/test/resources/subexpression_ast_block_recursion_depth_9.baseline @@ -2260,30 +2260,28 @@ CALL [1] { args: { CREATE_LIST [2] { elements: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } } - CALL [7] { + CALL [8] { function: _&&_ args: { - SELECT [8] { - IDENT [9] { - name: @index0 - }.a~presence_test + IDENT [9] { + name: @index0 } - SELECT [10] { - IDENT [11] { - name: @index0 - }.a~presence_test + IDENT [10] { + name: @index0 } } } diff --git a/optimizer/src/test/resources/subexpression_ast_cascaded_binds.baseline b/optimizer/src/test/resources/subexpression_ast_cascaded_binds.baseline index 78f8c433b..aea45bde5 100644 --- a/optimizer/src/test/resources/subexpression_ast_cascaded_binds.baseline +++ b/optimizer/src/test/resources/subexpression_ast_cascaded_binds.baseline @@ -2962,38 +2962,36 @@ COMPREHENSION [1] { } accu_var: @r0 accu_init: { - CREATE_MAP [3] { - MAP_ENTRY [4] { - key: { - CONSTANT [5] { value: "a" } - } - value: { - CONSTANT [6] { value: true } + SELECT [3] { + CREATE_MAP [4] { + MAP_ENTRY [5] { + key: { + CONSTANT [6] { value: "a" } + } + value: { + CONSTANT [7] { value: true } + } } - } + }.a~presence_test } } loop_condition: { - CONSTANT [7] { value: false } + CONSTANT [8] { value: false } } loop_step: { - IDENT [8] { + IDENT [9] { name: @r0 } } result: { - CALL [9] { + CALL [10] { function: _&&_ args: { - SELECT [10] { - IDENT [11] { - name: @r0 - }.a~presence_test + IDENT [11] { + name: @r0 } - SELECT [12] { - IDENT [13] { - name: @r0 - }.a~presence_test + IDENT [12] { + name: @r0 } } } diff --git a/optimizer/src/test/resources/subexpression_unparsed.baseline b/optimizer/src/test/resources/subexpression_unparsed.baseline index b38a971aa..1c4c11f7b 100644 --- a/optimizer/src/test/resources/subexpression_unparsed.baseline +++ b/optimizer/src/test/resources/subexpression_unparsed.baseline @@ -420,7 +420,7 @@ Source: has({'a': true}.a) && {'a':true}['a'] Result: true [CASCADED_BINDS]: cel.bind(@r0, {"a": true}, has(@r0.a) && @r0["a"]) [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([{"a": true}], has(@index0.a) && @index0["a"]) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([{"a": true}, @index0["a"]], has(@index0.a) && @index1) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([{"a": true}, has(@index0.a), @index0["a"]], @index1 && @index2) [BLOCK_RECURSION_DEPTH_2]: cel.@block([{"a": true}], has(@index0.a) && @index0["a"]) [BLOCK_RECURSION_DEPTH_3]: cel.@block([{"a": true}], has(@index0.a) && @index0["a"]) [BLOCK_RECURSION_DEPTH_4]: cel.@block([{"a": true}], has(@index0.a) && @index0["a"]) @@ -434,17 +434,17 @@ Test case: PRESENCE_TEST_2 Source: has({'a': true}.a) && has({'a': true}.a) =====> Result: true -[CASCADED_BINDS]: cel.bind(@r0, {"a": true}, has(@r0.a) && has(@r0.a)) -[BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_2]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_3]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_4]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_5]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_6]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_7]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_8]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) -[BLOCK_RECURSION_DEPTH_9]: cel.@block([{"a": true}], has(@index0.a) && has(@index0.a)) +[CASCADED_BINDS]: cel.bind(@r0, has({"a": true}.a), @r0 && @r0) +[BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([{"a": true}, has(@index0.a)], @index1 && @index1) +[BLOCK_RECURSION_DEPTH_2]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_3]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_4]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_5]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_6]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_7]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_8]: cel.@block([has({"a": true}.a)], @index0 && @index0) +[BLOCK_RECURSION_DEPTH_9]: cel.@block([has({"a": true}.a)], @index0 && @index0) Test case: PRESENCE_TEST_WITH_TERNARY Source: (has(msg.oneof_type.payload) ? msg.oneof_type.payload.single_int64 : 0) == 10 @@ -452,7 +452,7 @@ Source: (has(msg.oneof_type.payload) ? msg.oneof_type.payload.single_int64 : 0) Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type, has(@r0.payload) ? @r0.payload.single_int64 : 0) == 10 [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type], (has(@index0.payload) ? @index0.payload.single_int64 : 0) == 10) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64], (has(@index0.payload) ? @index2 : 0) == 10) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, has(@index0.payload), @index0.payload, @index2.single_int64, @index1 ? @index3 : 0], @index4 == 10) [BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type, @index0.payload.single_int64, has(@index0.payload) ? @index1 : 0], @index2 == 10) [BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type, has(@index0.payload) ? @index0.payload.single_int64 : 0], @index1 == 10) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type], (has(@index0.payload) ? @index0.payload.single_int64 : 0) == 10) @@ -468,8 +468,8 @@ Source: (has(msg.oneof_type.payload) ? msg.oneof_type.payload.single_int64 : msg Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type, cel.bind(@r1, @r0.payload.single_int64, has(@r0.payload) ? @r1 : (@r1 * 0))) == 10 [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type, @index0.payload.single_int64], (has(@index0.payload) ? @index1 : (@index1 * 0)) == 10) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, @index2 * 0], (has(@index0.payload) ? @index2 : @index3) == 10) -[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.single_int64, msg.oneof_type, has(@index2.payload) ? @index1 : (@index1 * 0)], @index3 == 10) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, has(@index0.payload), @index2 * 0, @index3 ? @index2 : @index4], @index5 == 10) +[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.single_int64, has(msg.oneof_type.payload), @index2 ? @index1 : (@index1 * 0)], @index3 == 10) [BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.single_int64, has(msg.oneof_type.payload) ? @index0 : (@index0 * 0)], @index1 == 10) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload) ? @index0 : (@index0 * 0)) == 10) [BLOCK_RECURSION_DEPTH_5]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload) ? @index0 : (@index0 * 0)) == 10) @@ -484,9 +484,9 @@ Source: (has(msg.oneof_type.payload.single_int64) ? msg.oneof_type.payload.singl Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type.payload, cel.bind(@r1, @r0.single_int64, has(@r0.single_int64) ? @r1 : (@r1 * 0))) == 10 [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type.payload, @index0.single_int64], (has(@index0.single_int64) ? @index1 : (@index1 * 0)) == 10) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, @index2 * 0], (has(@index1.single_int64) ? @index2 : @index3) == 10) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.single_int64, has(@index1.single_int64), @index2 * 0, @index3 ? @index2 : @index4], @index5 == 10) [BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.single_int64, has(@index0.single_int64) ? @index1 : (@index1 * 0)], @index2 == 10) -[BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.single_int64, msg.oneof_type.payload], (has(@index1.single_int64) ? @index0 : (@index0 * 0)) == 10) +[BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.single_int64, has(msg.oneof_type.payload.single_int64)], (@index1 ? @index0 : (@index0 * 0)) == 10) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type.payload.single_int64, has(msg.oneof_type.payload.single_int64) ? @index0 : (@index0 * 0)], @index1 == 10) [BLOCK_RECURSION_DEPTH_5]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload.single_int64) ? @index0 : (@index0 * 0)) == 10) [BLOCK_RECURSION_DEPTH_6]: cel.@block([msg.oneof_type.payload.single_int64], (has(msg.oneof_type.payload.single_int64) ? @index0 : (@index0 * 0)) == 10) @@ -500,8 +500,8 @@ Source: (has(msg.oneof_type) && has(msg.oneof_type.payload) && has(msg.oneof_typ Result: true [CASCADED_BINDS]: cel.bind(@r0, msg.oneof_type, cel.bind(@r1, @r0.payload, (has(msg.oneof_type) && has(@r0.payload) && has(@r1.single_int64)) ? cel.bind(@r2, @r1.map_string_string, (has(@r1.map_string_string) && has(@r2.key)) ? (@r2.key == "A") : false) : false)) [BLOCK_COMMON_SUBEXPR_ONLY]: cel.@block([msg.oneof_type, @index0.payload, @index1.map_string_string], (has(msg.oneof_type) && has(@index0.payload) && has(@index1.single_int64)) ? ((has(@index1.map_string_string) && has(@index2.key)) ? (@index2.key == "A") : false) : false) -[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.map_string_string, @index2.key, @index3 == "A"], (has(msg.oneof_type) && has(@index0.payload) && has(@index1.single_int64)) ? ((has(@index1.map_string_string) && has(@index2.key)) ? @index4 : false) : false) -[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.map_string_string, has(@index0.map_string_string) && has(@index1.key), @index1.key == "A", msg.oneof_type, has(msg.oneof_type) && has(@index4.payload), @index5 && has(@index0.single_int64)], @index6 ? (@index2 ? @index3 : false) : false) +[BLOCK_RECURSION_DEPTH_1]: cel.@block([msg.oneof_type, @index0.payload, @index1.map_string_string, has(msg.oneof_type), has(@index0.payload), @index3 && @index4, has(@index1.single_int64), @index5 && @index6, has(@index1.map_string_string), has(@index2.key), @index8 && @index9, @index2.key, @index11 == "A", @index10 ? @index12 : false], @index7 ? @index13 : false) +[BLOCK_RECURSION_DEPTH_2]: cel.@block([msg.oneof_type.payload, @index0.map_string_string, has(msg.oneof_type.payload), has(msg.oneof_type) && @index2, @index3 && has(@index0.single_int64), has(@index0.map_string_string) && has(@index1.key), @index1.key == "A"], @index4 ? (@index5 ? @index6 : false) : false) [BLOCK_RECURSION_DEPTH_3]: cel.@block([msg.oneof_type.payload.map_string_string, msg.oneof_type.payload, has(msg.oneof_type) && has(msg.oneof_type.payload), (has(@index1.map_string_string) && has(@index0.key)) ? (@index0.key == "A") : false], (@index2 && has(@index1.single_int64)) ? @index3 : false) [BLOCK_RECURSION_DEPTH_4]: cel.@block([msg.oneof_type.payload.map_string_string, msg.oneof_type.payload, has(msg.oneof_type) && has(msg.oneof_type.payload) && has(@index1.single_int64)], @index2 ? ((has(@index1.map_string_string) && has(@index0.key)) ? (@index0.key == "A") : false) : false) [BLOCK_RECURSION_DEPTH_5]: cel.@block([msg.oneof_type.payload.map_string_string, msg.oneof_type.payload], (has(msg.oneof_type) && has(msg.oneof_type.payload) && has(@index1.single_int64)) ? ((has(@index1.map_string_string) && has(@index0.key)) ? (@index0.key == "A") : false) : false)