Skip to content

Commit

Permalink
Static optimizer for constant folding (#804)
Browse files Browse the repository at this point in the history
* Optimizer API with Constant Folding implementatiton
* Better logical folds and additional tests
* Add a configurable limit to constant folding
  • Loading branch information
TristonianJones authored Aug 30, 2023
1 parent 509c1d6 commit 705546a
Show file tree
Hide file tree
Showing 9 changed files with 1,575 additions and 8 deletions.
3 changes: 3 additions & 0 deletions cel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ go_library(
"cel.go",
"decls.go",
"env.go",
"folding.go",
"io.go",
"library.go",
"macro.go",
"optimizer.go",
"options.go",
"program.go",
"validator.go",
Expand Down Expand Up @@ -56,6 +58,7 @@ go_test(
"cel_test.go",
"decls_test.go",
"env_test.go",
"folding_test.go",
"io_test.go",
"validator_test.go",
],
Expand Down
8 changes: 8 additions & 0 deletions cel/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Ast struct {
}

// Expr returns the proto serializable instance of the parsed/checked expression.
//
// Deprecated: prefer cel.AstToCheckedExpr() or cel.AstToParsedExpr() and call GetExpr()
// the result instead.
func (ast *Ast) Expr() *exprpb.Expr {
if ast == nil {
return nil
Expand Down Expand Up @@ -221,6 +224,11 @@ func (e *Env) Check(ast *Ast) (*Ast, *Issues) {
source: ast.Source(),
impl: checked}

// Avoid creating a validator config if it's not needed.
if len(e.validators) == 0 {
return ast, nil
}

// Generate a validator configuration from the set of configured validators.
vConfig := newValidatorConfig()
for _, v := range e.validators {
Expand Down
Loading

0 comments on commit 705546a

Please sign in to comment.