Skip to content

Commit c1a05d6

Browse files
jckingcopybara-github
authored andcommitted
Add a test case showing adjacent comprehensions
PiperOrigin-RevId: 663765762
1 parent 80baca4 commit c1a05d6

14 files changed

Lines changed: 2215 additions & 0 deletions

optimizer/src/test/java/dev/cel/optimizer/optimizers/SubexpressionOptimizerBaselineTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ private enum CseTestCase {
461461
+ " 1)"),
462462
NESTED_MACROS("[1,2,3].map(i, [1, 2, 3].map(i, i + 1)) == [[2, 3, 4], [2, 3, 4], [2, 3, 4]]"),
463463
NESTED_MACROS_2("[1, 2].map(y, [1, 2, 3].filter(x, x == y)) == [[1], [2]]"),
464+
ADJACENT_NESTED_MACROS(
465+
"[1,2,3].map(i, [1, 2, 3].map(i, i + 1)) == [1,2,3].map(j, [1, 2, 3].map(j, j + 1))"),
464466
INCLUSION_LIST("1 in [1,2,3] && 2 in [1,2,3] && 3 in [3, [1,2,3]] && 1 in [1,2,3]"),
465467
INCLUSION_MAP("2 in {'a': 1, 2: {true: false}, 3: {true: false}}"),
466468
MACRO_ITER_VAR_NOT_REFERENCED(

optimizer/src/test/resources/constfold_before_subexpression_unparsed.baseline

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,22 @@ Result: true
350350
[BLOCK_RECURSION_DEPTH_8]: true
351351
[BLOCK_RECURSION_DEPTH_9]: true
352352

353+
Test case: ADJACENT_NESTED_MACROS
354+
Source: [1,2,3].map(i, [1, 2, 3].map(i, i + 1)) == [1,2,3].map(j, [1, 2, 3].map(j, j + 1))
355+
=====>
356+
Result: true
357+
[CASCADED_BINDS]: true
358+
[BLOCK_COMMON_SUBEXPR_ONLY]: true
359+
[BLOCK_RECURSION_DEPTH_1]: true
360+
[BLOCK_RECURSION_DEPTH_2]: true
361+
[BLOCK_RECURSION_DEPTH_3]: true
362+
[BLOCK_RECURSION_DEPTH_4]: true
363+
[BLOCK_RECURSION_DEPTH_5]: true
364+
[BLOCK_RECURSION_DEPTH_6]: true
365+
[BLOCK_RECURSION_DEPTH_7]: true
366+
[BLOCK_RECURSION_DEPTH_8]: true
367+
[BLOCK_RECURSION_DEPTH_9]: true
368+
353369
Test case: INCLUSION_LIST
354370
Source: 1 in [1,2,3] && 2 in [1,2,3] && 3 in [3, [1,2,3]] && 1 in [1,2,3]
355371
=====>

optimizer/src/test/resources/subexpression_ast_block_common_subexpr_only.baseline

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,196 @@ CALL [31] {
21512151
}
21522152
}
21532153
}
2154+
Test case: ADJACENT_NESTED_MACROS
2155+
Source: [1,2,3].map(i, [1, 2, 3].map(i, i + 1)) == [1,2,3].map(j, [1, 2, 3].map(j, j + 1))
2156+
=====>
2157+
CALL [1] {
2158+
function: cel.@block
2159+
args: {
2160+
LIST [2] {
2161+
elements: {
2162+
LIST [3] {
2163+
elements: {
2164+
CONSTANT [4] { value: 1 }
2165+
CONSTANT [5] { value: 2 }
2166+
CONSTANT [6] { value: 3 }
2167+
}
2168+
}
2169+
}
2170+
}
2171+
CALL [7] {
2172+
function: _==_
2173+
args: {
2174+
COMPREHENSION [8] {
2175+
iter_var: @c:1
2176+
iter_range: {
2177+
IDENT [9] {
2178+
name: @index0
2179+
}
2180+
}
2181+
accu_var: @x:1
2182+
accu_init: {
2183+
LIST [10] {
2184+
elements: {
2185+
}
2186+
}
2187+
}
2188+
loop_condition: {
2189+
CONSTANT [11] { value: true }
2190+
}
2191+
loop_step: {
2192+
CALL [12] {
2193+
function: _+_
2194+
args: {
2195+
IDENT [13] {
2196+
name: @x:1
2197+
}
2198+
LIST [14] {
2199+
elements: {
2200+
COMPREHENSION [15] {
2201+
iter_var: @c:0
2202+
iter_range: {
2203+
IDENT [16] {
2204+
name: @index0
2205+
}
2206+
}
2207+
accu_var: @x:0
2208+
accu_init: {
2209+
LIST [17] {
2210+
elements: {
2211+
}
2212+
}
2213+
}
2214+
loop_condition: {
2215+
CONSTANT [18] { value: true }
2216+
}
2217+
loop_step: {
2218+
CALL [19] {
2219+
function: _+_
2220+
args: {
2221+
IDENT [20] {
2222+
name: @x:0
2223+
}
2224+
LIST [21] {
2225+
elements: {
2226+
CALL [22] {
2227+
function: _+_
2228+
args: {
2229+
IDENT [23] {
2230+
name: @c:0
2231+
}
2232+
CONSTANT [24] { value: 1 }
2233+
}
2234+
}
2235+
}
2236+
}
2237+
}
2238+
}
2239+
}
2240+
result: {
2241+
IDENT [25] {
2242+
name: @x:0
2243+
}
2244+
}
2245+
}
2246+
}
2247+
}
2248+
}
2249+
}
2250+
}
2251+
result: {
2252+
IDENT [26] {
2253+
name: @x:1
2254+
}
2255+
}
2256+
}
2257+
COMPREHENSION [27] {
2258+
iter_var: @c:3
2259+
iter_range: {
2260+
IDENT [28] {
2261+
name: @index0
2262+
}
2263+
}
2264+
accu_var: @x:3
2265+
accu_init: {
2266+
LIST [29] {
2267+
elements: {
2268+
}
2269+
}
2270+
}
2271+
loop_condition: {
2272+
CONSTANT [30] { value: true }
2273+
}
2274+
loop_step: {
2275+
CALL [31] {
2276+
function: _+_
2277+
args: {
2278+
IDENT [32] {
2279+
name: @x:3
2280+
}
2281+
LIST [33] {
2282+
elements: {
2283+
COMPREHENSION [34] {
2284+
iter_var: @c:2
2285+
iter_range: {
2286+
IDENT [35] {
2287+
name: @index0
2288+
}
2289+
}
2290+
accu_var: @x:2
2291+
accu_init: {
2292+
LIST [36] {
2293+
elements: {
2294+
}
2295+
}
2296+
}
2297+
loop_condition: {
2298+
CONSTANT [37] { value: true }
2299+
}
2300+
loop_step: {
2301+
CALL [38] {
2302+
function: _+_
2303+
args: {
2304+
IDENT [39] {
2305+
name: @x:2
2306+
}
2307+
LIST [40] {
2308+
elements: {
2309+
CALL [41] {
2310+
function: _+_
2311+
args: {
2312+
IDENT [42] {
2313+
name: @c:2
2314+
}
2315+
CONSTANT [43] { value: 1 }
2316+
}
2317+
}
2318+
}
2319+
}
2320+
}
2321+
}
2322+
}
2323+
result: {
2324+
IDENT [44] {
2325+
name: @x:2
2326+
}
2327+
}
2328+
}
2329+
}
2330+
}
2331+
}
2332+
}
2333+
}
2334+
result: {
2335+
IDENT [45] {
2336+
name: @x:3
2337+
}
2338+
}
2339+
}
2340+
}
2341+
}
2342+
}
2343+
}
21542344
Test case: INCLUSION_LIST
21552345
Source: 1 in [1,2,3] && 2 in [1,2,3] && 3 in [3, [1,2,3]] && 1 in [1,2,3]
21562346
=====>

0 commit comments

Comments
 (0)