Skip to content

Commit

Permalink
Minor test, code, and error hygiene changes (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Aug 16, 2023
1 parent 6643a4a commit 0bd4d39
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 17 deletions.
1 change: 1 addition & 0 deletions cel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ go_test(
"decls_test.go",
"env_test.go",
"io_test.go",
"validator_test.go",
],
data = [
"//cel/testdata:gen_test_fds",
Expand Down
6 changes: 1 addition & 5 deletions cel/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ func AstToCheckedExpr(a *Ast) (*exprpb.CheckedExpr, error) {
if !a.IsChecked() {
return nil, fmt.Errorf("cannot convert unchecked ast")
}
checked, err := astToExprAST(a)
if err != nil {
return nil, err
}
return ast.ToProto(checked)
return ast.ToProto(a.impl)
}

// ParsedExprToAst converts a parsed expression proto message to an Ast.
Expand Down
2 changes: 1 addition & 1 deletion cel/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestAstToProto(t *testing.T) {
}
checked, err := AstToCheckedExpr(ast)
if err != nil {
t.Fatalf("AstToCheckeExpr(ast) failed: %v", err)
t.Fatalf("AstToCheckedExpr(ast) failed: %v", err)
}
ast4 := CheckedExprToAst(checked)
if !proto.Equal(ast4.Expr(), ast.Expr()) {
Expand Down
11 changes: 1 addition & 10 deletions cel/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"sync"

"github.com/google/cel-go/common/ast"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"github.com/google/cel-go/interpreter"
Expand Down Expand Up @@ -244,11 +243,7 @@ func newProgram(e *Env, a *Ast, opts []ProgramOption) (Program, error) {

func (p *prog) initInterpretable(a *Ast, decs []interpreter.InterpretableDecorator) (*prog, error) {
// When the AST has been exprAST it contains metadata that can be used to speed up program execution.
exprAST, err := astToExprAST(a)
if err != nil {
return nil, err
}
interpretable, err := p.interpreter.NewInterpretable(exprAST, decs...)
interpretable, err := p.interpreter.NewInterpretable(a.impl, decs...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -517,10 +512,6 @@ func (p *evalActivationPool) Put(value any) {
p.Pool.Put(a)
}

func astToExprAST(a *Ast) (*ast.AST, error) {
return a.impl, nil
}

var (
// activationPool is an internally managed pool of Activation values that wrap map[string]any inputs
activationPool = newEvalActivationPool()
Expand Down
2 changes: 1 addition & 1 deletion common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e *Errors) GetErrors() []*Error {
// Append creates a new Errors object with the current and input errors.
func (e *Errors) Append(errs []*Error) *Errors {
return &Errors{
errors: append(e.errors, errs...),
errors: append(e.errors[:], errs...),
source: e.source,
numErrors: e.numErrors + len(errs),
maxErrorsToReport: e.maxErrorsToReport,
Expand Down

0 comments on commit 0bd4d39

Please sign in to comment.