Bump cel-go to v0.10.1

This commit is contained in:
cici37 2022-03-10 14:50:35 -08:00
parent 425ff1c8e2
commit 7572b26fba
10 changed files with 38 additions and 33 deletions

2
go.mod
View File

@ -269,7 +269,7 @@ replace (
github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e
github.com/google/btree => github.com/google/btree v1.0.1 github.com/google/btree => github.com/google/btree v1.0.1
github.com/google/cadvisor => github.com/google/cadvisor v0.43.0 github.com/google/cadvisor => github.com/google/cadvisor v0.43.0
github.com/google/cel-go => github.com/google/cel-go v0.10.0 github.com/google/cel-go => github.com/google/cel-go v0.10.1
github.com/google/cel-spec => github.com/google/cel-spec v0.6.0 github.com/google/cel-spec => github.com/google/cel-spec v0.6.0
github.com/google/go-cmp => github.com/google/go-cmp v0.5.5 github.com/google/go-cmp => github.com/google/go-cmp v0.5.5
github.com/google/gofuzz => github.com/google/gofuzz v1.1.0 github.com/google/gofuzz => github.com/google/gofuzz v1.1.0

4
go.sum
View File

@ -221,8 +221,8 @@ github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/cadvisor v0.43.0 h1:z0ULgYPKZ7L/c7Zjq+ZD6ltklWwYdCSvBMgSjNC/hGo= github.com/google/cadvisor v0.43.0 h1:z0ULgYPKZ7L/c7Zjq+ZD6ltklWwYdCSvBMgSjNC/hGo=
github.com/google/cadvisor v0.43.0/go.mod h1:+RdMSbc3FVr5NYCD2dOEJy/LI0jYJ/0xJXkzWXEyiFQ= github.com/google/cadvisor v0.43.0/go.mod h1:+RdMSbc3FVr5NYCD2dOEJy/LI0jYJ/0xJXkzWXEyiFQ=
github.com/google/cel-go v0.10.0 h1:SBdarVzHoCXsTjqX+Lsgg9asSO7bViwgizzDi9kBigg= github.com/google/cel-go v0.10.1 h1:MQBGSZGnDwh7T/un+mzGKOMz3x+4E/GDPprWjDL+1Jg=
github.com/google/cel-go v0.10.0/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w= github.com/google/cel-go v0.10.1/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w=
github.com/google/cel-spec v0.6.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA= github.com/google/cel-spec v0.6.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=

View File

@ -7,7 +7,7 @@ go 1.16
require ( require (
github.com/emicklei/go-restful v2.9.5+incompatible github.com/emicklei/go-restful v2.9.5+incompatible
github.com/gogo/protobuf v1.3.2 github.com/gogo/protobuf v1.3.2
github.com/google/cel-go v0.10.0 github.com/google/cel-go v0.10.1
github.com/google/go-cmp v0.5.5 github.com/google/go-cmp v0.5.5
github.com/google/gofuzz v1.1.0 github.com/google/gofuzz v1.1.0
github.com/google/uuid v1.1.2 github.com/google/uuid v1.1.2

View File

@ -229,8 +229,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/cel-go v0.10.0 h1:SBdarVzHoCXsTjqX+Lsgg9asSO7bViwgizzDi9kBigg= github.com/google/cel-go v0.10.1 h1:MQBGSZGnDwh7T/un+mzGKOMz3x+4E/GDPprWjDL+1Jg=
github.com/google/cel-go v0.10.0/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w= github.com/google/cel-go v0.10.1/go.mod h1:U7ayypeSkw23szu4GaQTPJGx66c20mx8JklMSxrmI1w=
github.com/google/cel-spec v0.6.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA= github.com/google/cel-spec v0.6.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=

View File

@ -102,6 +102,8 @@ func (ed *EvalDetails) State() interpreter.EvalState {
return ed.state return ed.state
} }
// ActualCost returns the tracked cost through the course of execution when `CostTracking` is enabled.
// Otherwise, returns nil if the cost was not enabled.
func (ed *EvalDetails) ActualCost() *uint64 { func (ed *EvalDetails) ActualCost() *uint64 {
if ed.costTracker == nil { if ed.costTracker == nil {
return nil return nil
@ -291,6 +293,9 @@ func (p *prog) Eval(input interface{}) (v ref.Val, det *EvalDetails, err error)
// ContextEval implements the Program interface. // ContextEval implements the Program interface.
func (p *prog) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) { func (p *prog) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) {
if ctx == nil {
return nil, nil, fmt.Errorf("context can not be nil")
}
// Configure the input, making sure to wrap Activation inputs in the special ctxActivation which // Configure the input, making sure to wrap Activation inputs in the special ctxActivation which
// exposes the #interrupted variable and manages rate-limited checks of the ctx.Done() state. // exposes the #interrupted variable and manages rate-limited checks of the ctx.Done() state.
var vars interpreter.Activation var vars interpreter.Activation
@ -360,16 +365,20 @@ func (gen *progGen) Eval(input interface{}) (ref.Val, *EvalDetails, error) {
// ContextEval implements the Program interface method. // ContextEval implements the Program interface method.
func (gen *progGen) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) { func (gen *progGen) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) {
if ctx == nil {
return nil, nil, fmt.Errorf("context can not be nil")
}
// The factory based Eval() differs from the standard evaluation model in that it generates a // The factory based Eval() differs from the standard evaluation model in that it generates a
// new EvalState instance for each call to ensure that unique evaluations yield unique stateful // new EvalState instance for each call to ensure that unique evaluations yield unique stateful
// results. // results.
state := interpreter.NewEvalState() state := interpreter.NewEvalState()
det := &EvalDetails{state: state} costTracker := &interpreter.CostTracker{}
det := &EvalDetails{state: state, costTracker: costTracker}
// Generate a new instance of the interpretable using the factory configured during the call to // Generate a new instance of the interpretable using the factory configured during the call to
// newProgram(). It is incredibly unlikely that the factory call will generate an error given // newProgram(). It is incredibly unlikely that the factory call will generate an error given
// the factory test performed within the Program() call. // the factory test performed within the Program() call.
p, err := gen.factory(state, &interpreter.CostTracker{}) p, err := gen.factory(state, costTracker)
if err != nil { if err != nil {
return nil, det, err return nil, det, err
} }

View File

@ -37,7 +37,7 @@ type CostEstimator interface {
EstimateSize(element AstNode) *SizeEstimate EstimateSize(element AstNode) *SizeEstimate
// EstimateCallCost returns the estimated cost of an invocation, or nil if // EstimateCallCost returns the estimated cost of an invocation, or nil if
// the estimator has no estimate to provide. // the estimator has no estimate to provide.
EstimateCallCost(overloadId string, target *AstNode, args []AstNode) *CallEstimate EstimateCallCost(function, overloadID string, target *AstNode, args []AstNode) *CallEstimate
} }
// CallEstimate includes a CostEstimate for the call, and an optional estimate of the result object size. // CallEstimate includes a CostEstimate for the call, and an optional estimate of the result object size.
@ -384,7 +384,7 @@ func (c *coster) costCall(e *exprpb.Expr) CostEstimate {
fnCost := CostEstimate{Min: uint64(math.MaxUint64), Max: 0} fnCost := CostEstimate{Min: uint64(math.MaxUint64), Max: 0}
var resultSize *SizeEstimate var resultSize *SizeEstimate
for _, overload := range ref.GetOverloadId() { for _, overload := range ref.GetOverloadId() {
overloadCost := c.functionCost(overload, &targetType, argTypes, argCosts) overloadCost := c.functionCost(call.GetFunction(), overload, &targetType, argTypes, argCosts)
fnCost = fnCost.Union(overloadCost.CostEstimate) fnCost = fnCost.Union(overloadCost.CostEstimate)
if overloadCost.ResultSize != nil { if overloadCost.ResultSize != nil {
if resultSize == nil { if resultSize == nil {
@ -425,9 +425,8 @@ func (c *coster) costCreateStruct(e *exprpb.Expr) CostEstimate {
str := e.GetStructExpr() str := e.GetStructExpr()
if str.MessageName != "" { if str.MessageName != "" {
return c.costCreateMessage(e) return c.costCreateMessage(e)
} else {
return c.costCreateMap(e)
} }
return c.costCreateMap(e)
} }
func (c *coster) costCreateMap(e *exprpb.Expr) CostEstimate { func (c *coster) costCreateMap(e *exprpb.Expr) CostEstimate {
@ -480,7 +479,7 @@ func (c *coster) sizeEstimate(t AstNode) SizeEstimate {
return SizeEstimate{Min: 0, Max: math.MaxUint64} return SizeEstimate{Min: 0, Max: math.MaxUint64}
} }
func (c *coster) functionCost(overloadId string, target *AstNode, args []AstNode, argCosts []CostEstimate) CallEstimate { func (c *coster) functionCost(function, overloadID string, target *AstNode, args []AstNode, argCosts []CostEstimate) CallEstimate {
argCostSum := func() CostEstimate { argCostSum := func() CostEstimate {
var sum CostEstimate var sum CostEstimate
for _, a := range argCosts { for _, a := range argCosts {
@ -489,11 +488,11 @@ func (c *coster) functionCost(overloadId string, target *AstNode, args []AstNode
return sum return sum
} }
if est := c.estimator.EstimateCallCost(overloadId, target, args); est != nil { if est := c.estimator.EstimateCallCost(function, overloadID, target, args); est != nil {
callEst := *est callEst := *est
return CallEstimate{CostEstimate: callEst.Add(argCostSum())} return CallEstimate{CostEstimate: callEst.Add(argCostSum())}
} }
switch overloadId { switch overloadID {
// O(n) functions // O(n) functions
case overloads.StartsWithString, overloads.EndsWithString, overloads.StringToBytes, overloads.BytesToString: case overloads.StartsWithString, overloads.EndsWithString, overloads.StringToBytes, overloads.BytesToString:
if len(args) == 1 { if len(args) == 1 {
@ -544,7 +543,7 @@ func (c *coster) functionCost(overloadId string, target *AstNode, args []AstNode
lhsSize := c.sizeEstimate(args[0]) lhsSize := c.sizeEstimate(args[0])
rhsSize := c.sizeEstimate(args[1]) rhsSize := c.sizeEstimate(args[1])
resultSize := lhsSize.Add(rhsSize) resultSize := lhsSize.Add(rhsSize)
switch overloadId { switch overloadID {
case overloads.AddList: case overloads.AddList:
// list concatenation is O(1), but we handle it here to track size // list concatenation is O(1), but we handle it here to track size
return CallEstimate{CostEstimate: CostEstimate{Min: 1, Max: 1}.Add(argCostSum()), ResultSize: &resultSize} return CallEstimate{CostEstimate: CostEstimate{Min: 1, Max: 1}.Add(argCostSum()), ResultSize: &resultSize}

View File

@ -259,8 +259,6 @@ func maybeOptimizeSetMembership(i Interpretable, inlist InterpretableCall) (Inte
if !types.IsError(iv) { if !types.IsError(iv) {
valueSet[iv] = types.True valueSet[iv] = types.True
} }
default:
break
} }
} }
return &evalSetMembership{ return &evalSetMembership{

View File

@ -101,8 +101,6 @@ func EvalStateObserver(state EvalState) EvalObserver {
} }
} }
// TODO: Replace all usages of ExhaustiveEval with ExhaustiveEvalWrapper
// ExhaustiveEval replaces operations that short-circuit with versions that evaluate // ExhaustiveEval replaces operations that short-circuit with versions that evaluate
// expressions and couples this behavior with the TrackState() decorator to provide // expressions and couples this behavior with the TrackState() decorator to provide
// insight into the evaluation state of the entire expression. EvalState must be // insight into the evaluation state of the entire expression. EvalState must be
@ -115,6 +113,11 @@ func ExhaustiveEval() InterpretableDecorator {
} }
} }
// InterruptableEval annotates comprehension loops with information that indicates they
// should check the `#interrupted` state within a custom Activation.
//
// The custom activation is currently managed higher up in the stack within the 'cel' package
// and should not require any custom support on behalf of callers.
func InterruptableEval() InterpretableDecorator { func InterruptableEval() InterpretableDecorator {
return decInterruptFolds() return decInterruptFolds()
} }

View File

@ -12,10 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package interpreter provides functions to evaluate parsed expressions with
// the option to augment the evaluation with inputs and functions supplied at
// evaluation time.
package interpreter package interpreter
import ( import (
@ -35,7 +31,7 @@ import (
// estimate to provide. CEL attempts to provide reasonable estimates for its standard function library, so CallCost // estimate to provide. CEL attempts to provide reasonable estimates for its standard function library, so CallCost
// should typically not need to provide an estimate for CELs standard function. // should typically not need to provide an estimate for CELs standard function.
type ActualCostEstimator interface { type ActualCostEstimator interface {
CallCost(overloadId string, args []ref.Val) *uint64 CallCost(function, overloadID string, args []ref.Val, result ref.Val) *uint64
} }
// CostObserver provides an observer that tracks runtime cost. // CostObserver provides an observer that tracks runtime cost.
@ -46,7 +42,7 @@ func CostObserver(tracker *CostTracker) EvalObserver {
// TODO: Push identifiers on to the stack before observing constant qualifiers that apply to them // TODO: Push identifiers on to the stack before observing constant qualifiers that apply to them
// and enable the below pop. Once enabled this can case can be collapsed into the Qualifier case. // and enable the below pop. Once enabled this can case can be collapsed into the Qualifier case.
//tracker.stack.pop(1) //tracker.stack.pop(1)
tracker.cost += 1 tracker.cost++
case InterpretableConst: case InterpretableConst:
// zero cost // zero cost
case InterpretableAttribute: case InterpretableAttribute:
@ -59,10 +55,10 @@ func CostObserver(tracker *CostTracker) EvalObserver {
// Ternary has no direct cost. All cost is from the conditional and the true/false branch expressions. // Ternary has no direct cost. All cost is from the conditional and the true/false branch expressions.
case Qualifier: case Qualifier:
tracker.stack.pop(1) tracker.stack.pop(1)
tracker.cost += 1 tracker.cost++
case InterpretableCall: case InterpretableCall:
if argVals, ok := tracker.stack.pop(len(t.Args())); ok { if argVals, ok := tracker.stack.pop(len(t.Args())); ok {
tracker.cost += tracker.costCall(t, argVals) tracker.cost += tracker.costCall(t, argVals, val)
} }
case InterpretableConstructor: case InterpretableConstructor:
switch t.Type() { switch t.Type() {
@ -97,10 +93,10 @@ func (c CostTracker) ActualCost() uint64 {
return c.cost return c.cost
} }
func (c CostTracker) costCall(call InterpretableCall, argValues []ref.Val) uint64 { func (c CostTracker) costCall(call InterpretableCall, argValues []ref.Val, result ref.Val) uint64 {
var cost uint64 var cost uint64
if c.Estimator != nil { if c.Estimator != nil {
callCost := c.Estimator.CallCost(call.OverloadID(), argValues) callCost := c.Estimator.CallCost(call.Function(), call.OverloadID(), argValues, result)
if callCost != nil { if callCost != nil {
cost += *callCost cost += *callCost
return cost return cost
@ -160,7 +156,7 @@ func (c CostTracker) costCall(call InterpretableCall, argValues []ref.Val) uint6
// - Computing the size of strings, byte sequences, lists and maps. // - Computing the size of strings, byte sequences, lists and maps.
// - Logical operations and all operators on fixed width scalars (comparisons, equality) // - Logical operations and all operators on fixed width scalars (comparisons, equality)
// - Any functions that don't have a declared cost either here or in provided ActualCostEstimator. // - Any functions that don't have a declared cost either here or in provided ActualCostEstimator.
cost += 1 cost++
} }
return cost return cost

4
vendor/modules.txt vendored
View File

@ -371,7 +371,7 @@ github.com/google/cadvisor/utils/sysfs
github.com/google/cadvisor/utils/sysinfo github.com/google/cadvisor/utils/sysinfo
github.com/google/cadvisor/version github.com/google/cadvisor/version
github.com/google/cadvisor/watcher github.com/google/cadvisor/watcher
# github.com/google/cel-go v0.10.0 => github.com/google/cel-go v0.10.0 # github.com/google/cel-go v0.10.1 => github.com/google/cel-go v0.10.1
github.com/google/cel-go/cel github.com/google/cel-go/cel
github.com/google/cel-go/checker github.com/google/cel-go/checker
github.com/google/cel-go/checker/decls github.com/google/cel-go/checker/decls
@ -2541,7 +2541,7 @@ sigs.k8s.io/yaml
# github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e # github.com/golangplus/testing => github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e
# github.com/google/btree => github.com/google/btree v1.0.1 # github.com/google/btree => github.com/google/btree v1.0.1
# github.com/google/cadvisor => github.com/google/cadvisor v0.43.0 # github.com/google/cadvisor => github.com/google/cadvisor v0.43.0
# github.com/google/cel-go => github.com/google/cel-go v0.10.0 # github.com/google/cel-go => github.com/google/cel-go v0.10.1
# github.com/google/cel-spec => github.com/google/cel-spec v0.6.0 # github.com/google/cel-spec => github.com/google/cel-spec v0.6.0
# github.com/google/go-cmp => github.com/google/go-cmp v0.5.5 # github.com/google/go-cmp => github.com/google/go-cmp v0.5.5
# github.com/google/gofuzz => github.com/google/gofuzz v1.1.0 # github.com/google/gofuzz => github.com/google/gofuzz v1.1.0