(ctx *OptimizerContext, a *ast.AST, navigableExpr ast.NavigableExpr, activation Activation)
| 166 | } |
| 167 | |
| 168 | func 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 | |
| 192 | func isLateBoundFunctionCall(ctx *OptimizerContext, expr ast.Expr) bool { |
| 193 | call := expr.AsCall() |
no test coverage detected