MCPcopy Create free account
hub / github.com/cel-expr/cel-go / evaluateExpr

Function evaluateExpr

cel/folding.go:168–190  ·  view source on GitHub ↗
(ctx *OptimizerContext, a *ast.AST, navigableExpr ast.NavigableExpr, activation Activation)

Source from the content-addressed store, hash-verified

166}
167
168func evaluateExpr(ctx *OptimizerContext, a *ast.AST, navigableExpr ast.NavigableExpr, activation Activation) (ref.Val, error) {
169 partialActivation, err := ctx.PartialVars(activation)
170 if err != nil {
171 return nil, err
172 }
173 subAST := &Ast{
174 impl: ast.NewCheckedAST(ast.NewAST(navigableExpr, a.SourceInfo()), a.TypeMap(), a.ReferenceMap()),
175 }
176 prg, err := ctx.Program(subAST)
177 if err != nil {
178 return nil, errCannotFold
179 }
180 // Folding will not attempt to call async functions which are all marked as late-bound,
181 // but the presence of such functions requires the use of `ConcurrentEval` in order to
182 // avoid an early return error which blocks async functions from running in `Eval` and
183 // `ContextEval` call paths.
184 resCh := prg.ConcurrentEval(context.Background(), partialActivation)
185 res := <-resCh
186 if res.Err != nil || types.IsUnknown(res.Val) {
187 return nil, errCannotFold
188 }
189 return res.Val, nil
190}
191
192func isLateBoundFunctionCall(ctx *OptimizerContext, expr ast.Expr) bool {
193 call := expr.AsCall()

Callers 1

tryFoldMethod · 0.85

Calls 9

NewCheckedASTFunction · 0.92
NewASTFunction · 0.92
IsUnknownFunction · 0.92
PartialVarsMethod · 0.80
TypeMapMethod · 0.80
ReferenceMapMethod · 0.80
ProgramMethod · 0.80
ConcurrentEvalMethod · 0.65
SourceInfoMethod · 0.45

Tested by

no test coverage detected