Skip to content
Merged
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
6 changes: 5 additions & 1 deletion optimizer/src/main/java/dev/cel/optimizer/MutableAst.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ public CelAbstractSyntaxTree replaceSubtree(
CelAbstractSyntaxTree ast, CelExpr newExpr, long exprIdToReplace) {
return replaceSubtreeWithNewAst(
ast,
CelAbstractSyntaxTree.newParsedAst(newExpr, CelSource.newBuilder().build()),
CelAbstractSyntaxTree.newParsedAst(
newExpr,
// Copy the macro call information to the new AST such that macro call map can be
// normalized post-replacement.
CelSource.newBuilder().addAllMacroCalls(ast.getSource().getMacroCalls()).build()),
exprIdToReplace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public void constantFold_success(String source, String expected) throws Exceptio
@TestParameters(
"{source: 'cel.bind(r0, [1, 2, 3], cel.bind(r1, 1 in r0 && 2 in x, r1))', expected:"
+ " 'cel.bind(r0, [1, 2, 3], cel.bind(r1, 1 in r0 && 2 in x, r1))'}")
@TestParameters("{source: 'false ? false : cel.bind(a, x, a)', expected: 'cel.bind(a, x, a)'}")
public void constantFold_macros_macroCallMetadataPopulated(String source, String expected)
throws Exception {
Cel cel =
Expand Down Expand Up @@ -247,6 +248,8 @@ public void constantFold_macros_macroCallMetadataPopulated(String source, String
@TestParameters(
"{source: '[{}, {\"a\": 1}, {\"b\": 2}].filter(m, has({\"a\": true}.a)) == "
+ " [{}, {\"a\": 1}, {\"b\": 2}]'}")
@TestParameters("{source: 'cel.bind(r0, [1, 2, 3], cel.bind(r1, 1 in r0 && 2 in r0, r1))'}")
@TestParameters("{source: 'false ? false : cel.bind(a, true, a)'}")
public void constantFold_macros_withoutMacroCallMetadata(String source) throws Exception {
Cel cel =
CelFactory.standardCelBuilder()
Expand All @@ -255,7 +258,7 @@ public void constantFold_macros_withoutMacroCallMetadata(String source) throws E
.addMessageTypes(TestAllTypes.getDescriptor())
.setStandardMacros(CelStandardMacro.STANDARD_MACROS)
.setOptions(CelOptions.current().populateMacroCalls(false).build())
.addCompilerLibraries(CelOptionalLibrary.INSTANCE)
.addCompilerLibraries(CelExtensions.bindings(), CelOptionalLibrary.INSTANCE)
.addRuntimeLibraries(CelOptionalLibrary.INSTANCE)
.build();
CelOptimizer celOptimizer =
Expand Down