func (and *evalExhaustiveAnd) ID() int64 {
	return and.id
}
ID implements the Interpretable interface method.
package interpreter
import (
	"math"
	"github.com/google/cel-go/common/operators"
	"github.com/google/cel-go/common/overloads"
	"github.com/google/cel-go/common/types"
	"github.com/google/cel-go/common/types/ref"
	"github.com/google/cel-go/common/types/traits"
	"github.com/google/cel-go/interpreter/functions"
)
type Interpretable interface {
	ID() int64
	Eval(activation Activation) ref.Val
}
type InterpretableConst interface {
	Interpretable
	Value() ref.Val
}
type InterpretableAttribute interface {
	Interpretable
	Attr() Attribute
	Adapter() ref.TypeAdapter
	AddQualifier(Qualifier) (Attribute, error)
	Qualify(vars Activation, obj interface{}) (interface{}, error)
	Resolve(Activation) (interface{}, error)
}
type InterpretableCall interface {
	Interpretable
	Function() string
	OverloadID() string
	Args() []Interpretable
}
type evalTestOnly struct {
	id        int64
	op        Interpretable
	field     types.String
	fieldType *ref.FieldType
}
func (test *evalTestOnly) ID() int64 {
	return test.id
}
func (test *evalTestOnly) Eval(ctx Activation) ref.Val {
	if test.fieldType != nil {
		opAttr, ok := test.op.(InterpretableAttribute)
		if ok {
			opVal, err := opAttr.Resolve(ctx)
			if err != nil {
				return types.NewErr(err.Error())
			}
			refVal, ok := opVal.(ref.Val)
			if ok {
				opVal = refVal.Value()
			}
			if test.fieldType.IsSet(opVal) {
				return types.True
			}
			return types.False
		}
	}
	obj := test.op.Eval(ctx)
	tester, ok := obj.(traits.FieldTester)
	if ok {
		return tester.IsSet(test.field)
	}
	container, ok := obj.(traits.Container)
	if ok {
		return container.Contains(test.field)
	}
	return types.ValOrErr(obj, "invalid type for field selection.")
}
func (test *evalTestOnly) Cost() (min, max int64) {
	min, max = estimateCost(test.op)
	min++
	max++
	return
}
func NewConstValue(id int64, val ref.Val) InterpretableConst {
	return &evalConst{
		id:  id,
		val: val,
	}
}
type evalConst struct {
	id  int64
	val ref.Val
}
func (cons *evalConst) ID() int64 {
	return cons.id
}
func (cons *evalConst) Eval(ctx Activation) ref.Val {
	return cons.val
}
func (cons *evalConst) Cost() (min, max int64) {
	return 0, 0
}
func (cons *evalConst) Value() ref.Val {
	return cons.val
}
type evalOr struct {
	id  int64
	lhs Interpretable
	rhs Interpretable
}
func (or *evalOr) ID() int64 {
	return or.id
}
func (or *evalOr) Eval(ctx Activation) ref.Val {
	lVal := or.lhs.Eval(ctx)
	lBool, lok := lVal.(types.Bool)
	if lok && lBool == types.True {
		return types.True
	}
	rVal := or.rhs.Eval(ctx)
	rBool, rok := rVal.(types.Bool)
	if rok && rBool == types.True {
		return types.True
	}
	if lok && rok {
		return types.False
	}
	if types.IsUnknown(lVal) {
		return lVal
	}
	if types.IsUnknown(rVal) {
		return rVal
	}
	if types.IsError(lVal) {
		return lVal
	}
	return types.ValOrErr(rVal, "no such overload")
}
func (or *evalOr) Cost() (min, max int64) {
	return calShortCircuitBinaryOpsCost(or.lhs, or.rhs)
}
type evalAnd struct {
	id  int64
	lhs Interpretable
	rhs Interpretable
}
func (and *evalAnd) ID() int64 {
	return and.id
}
func (and *evalAnd) Eval(ctx Activation) ref.Val {
	lVal := and.lhs.Eval(ctx)
	lBool, lok := lVal.(types.Bool)
	if lok && lBool == types.False {
		return types.False
	}
	rVal := and.rhs.Eval(ctx)
	rBool, rok := rVal.(types.Bool)
	if rok && rBool == types.False {
		return types.False
	}
	if lok && rok {
		return types.True
	}
	if types.IsUnknown(lVal) {
		return lVal
	}
	if types.IsUnknown(rVal) {
		return rVal
	}
	if types.IsError(lVal) {
		return lVal
	}
	return types.ValOrErr(rVal, "no such overload")
}
func (and *evalAnd) Cost() (min, max int64) {
	return calShortCircuitBinaryOpsCost(and.lhs, and.rhs)
}
func calShortCircuitBinaryOpsCost(lhs, rhs Interpretable) (min, max int64) {
	lMin, lMax := estimateCost(lhs)
	_, rMax := estimateCost(rhs)
	return lMin, lMax + rMax + 1
}
type evalEq struct {
	id  int64
	lhs Interpretable
	rhs Interpretable
}
func (eq *evalEq) ID() int64 {
	return eq.id
}
func (eq *evalEq) Eval(ctx Activation) ref.Val {
	lVal := eq.lhs.Eval(ctx)
	rVal := eq.rhs.Eval(ctx)
	return lVal.Equal(rVal)
}
func (eq *evalEq) Cost() (min, max int64) {
	return calExhaustiveBinaryOpsCost(eq.lhs, eq.rhs)
}
func (*evalEq) Function() string {
	return operators.Equals
}
func (*evalEq) OverloadID() string {
	return overloads.Equals
}
func (eq *evalEq) Args() []Interpretable {
	return []Interpretable{eq.lhs, eq.rhs}
}
type evalNe struct {
	id  int64
	lhs Interpretable
	rhs Interpretable
}
func (ne *evalNe) ID() int64 {
	return ne.id
}
func (ne *evalNe) Eval(ctx Activation) ref.Val {
	lVal := ne.lhs.Eval(ctx)
	rVal := ne.rhs.Eval(ctx)
	eqVal := lVal.Equal(rVal)
	eqBool, ok := eqVal.(types.Bool)
	if !ok {
		return types.ValOrErr(eqVal, "no such overload: _!=_")
	}
	return !eqBool
}
func (ne *evalNe) Cost() (min, max int64) {
	return calExhaustiveBinaryOpsCost(ne.lhs, ne.rhs)
}
func (*evalNe) Function() string {
	return operators.NotEquals
}
func (*evalNe) OverloadID() string {
	return overloads.NotEquals
}
func (ne *evalNe) Args() []Interpretable {
	return []Interpretable{ne.lhs, ne.rhs}
}
type evalZeroArity struct {
	id       int64
	function string
	overload string
	impl     functions.FunctionOp
}
func (zero *evalZeroArity) ID() int64 {
	return zero.id
}
func (zero *evalZeroArity) Eval(ctx Activation) ref.Val {
	return zero.impl()
}
func (zero *evalZeroArity) Cost() (min, max int64) {
	return 1, 1
}
func (zero *evalZeroArity) Function() string {
	return zero.function
}
func (zero *evalZeroArity) OverloadID() string {
	return zero.overload
}
func (zero *evalZeroArity) Args() []Interpretable {
	return []Interpretable{}
}
type evalUnary struct {
	id       int64
	function string
	overload string
	arg      Interpretable
	trait    int
	impl     functions.UnaryOp
}
func (un *evalUnary) ID() int64 {
	return un.id
}
func (un *evalUnary) Eval(ctx Activation) ref.Val {
	argVal := un.arg.Eval(ctx)
	if types.IsUnknownOrError(argVal) {
		return argVal
	}
	if un.impl != nil && (un.trait == 0 || argVal.Type().HasTrait(un.trait)) {
		return un.impl(argVal)
	}
	if argVal.Type().HasTrait(traits.ReceiverType) {
		return argVal.(traits.Receiver).Receive(un.function, un.overload, []ref.Val{})
	}
	return types.NewErr("no such overload: %s", un.function)
}
func (un *evalUnary) Cost() (min, max int64) {
	min, max = estimateCost(un.arg)
	min++  
	max++
	return
}
func (un *evalUnary) Function() string {
	return un.function
}
func (un *evalUnary) OverloadID() string {
	return un.overload
}
func (un *evalUnary) Args() []Interpretable {
	return []Interpretable{un.arg}
}
type evalBinary struct {
	id       int64
	function string
	overload string
	lhs      Interpretable
	rhs      Interpretable
	trait    int
	impl     functions.BinaryOp
}
func (bin *evalBinary) ID() int64 {
	return bin.id
}
func (bin *evalBinary) Eval(ctx Activation) ref.Val {
	lVal := bin.lhs.Eval(ctx)
	rVal := bin.rhs.Eval(ctx)
	if types.IsUnknownOrError(lVal) {
		return lVal
	}
	if types.IsUnknownOrError(rVal) {
		return rVal
	}
	if bin.impl != nil && (bin.trait == 0 || lVal.Type().HasTrait(bin.trait)) {
		return bin.impl(lVal, rVal)
	}
	if lVal.Type().HasTrait(traits.ReceiverType) {
		return lVal.(traits.Receiver).Receive(bin.function, bin.overload, []ref.Val{rVal})
	}
	return types.NewErr("no such overload: %s", bin.function)
}
func (bin *evalBinary) Cost() (min, max int64) {
	return calExhaustiveBinaryOpsCost(bin.lhs, bin.rhs)
}
func (bin *evalBinary) Function() string {
	return bin.function
}
func (bin *evalBinary) OverloadID() string {
	return bin.overload
}
func (bin *evalBinary) Args() []Interpretable {
	return []Interpretable{bin.lhs, bin.rhs}
}
type evalVarArgs struct {
	id       int64
	function string
	overload string
	args     []Interpretable
	trait    int
	impl     functions.FunctionOp
}
func (fn *evalVarArgs) ID() int64 {
	return fn.id
}
func (fn *evalVarArgs) Eval(ctx Activation) ref.Val {
	argVals := make([]ref.Val, len(fn.args))
	for i, arg := range fn.args {
		argVals[i] = arg.Eval(ctx)
		if types.IsUnknownOrError(argVals[i]) {
			return argVals[i]
		}
	}
	arg0 := argVals[0]
	if fn.impl != nil && (fn.trait == 0 || arg0.Type().HasTrait(fn.trait)) {
		return fn.impl(argVals...)
	}
	if arg0.Type().HasTrait(traits.ReceiverType) {
		return arg0.(traits.Receiver).Receive(fn.function, fn.overload, argVals[1:])
	}
	return types.NewErr("no such overload: %s", fn.function)
}
func (fn *evalVarArgs) Cost() (min, max int64) {
	min, max = sumOfCost(fn.args)
	min++  
	max++
	return
}
func (fn *evalVarArgs) Function() string {
	return fn.function
}
func (fn *evalVarArgs) OverloadID() string {
	return fn.overload
}
func (fn *evalVarArgs) Args() []Interpretable {
	return fn.args
}
type evalList struct {
	id      int64
	elems   []Interpretable
	adapter ref.TypeAdapter
}
func (l *evalList) ID() int64 {
	return l.id
}
func (l *evalList) Eval(ctx Activation) ref.Val {
	elemVals := make([]ref.Val, len(l.elems))
	for i, elem := range l.elems {
		elemVal := elem.Eval(ctx)
		if types.IsUnknownOrError(elemVal) {
			return elemVal
		}
		elemVals[i] = elemVal
	}
	return l.adapter.NativeToValue(elemVals)
}
func (l *evalList) Cost() (min, max int64) {
	return sumOfCost(l.elems)
}
type evalMap struct {
	id      int64
	keys    []Interpretable
	vals    []Interpretable
	adapter ref.TypeAdapter
}
func (m *evalMap) ID() int64 {
	return m.id
}
func (m *evalMap) Eval(ctx Activation) ref.Val {
	entries := make(map[ref.Val]ref.Val)
	for i, key := range m.keys {
		keyVal := key.Eval(ctx)
		if types.IsUnknownOrError(keyVal) {
			return keyVal
		}
		valVal := m.vals[i].Eval(ctx)
		if types.IsUnknownOrError(valVal) {
			return valVal
		}
		entries[keyVal] = valVal
	}
	return m.adapter.NativeToValue(entries)
}
func (m *evalMap) Cost() (min, max int64) {
	kMin, kMax := sumOfCost(m.keys)
	vMin, vMax := sumOfCost(m.vals)
	return kMin + vMin, kMax + vMax
}
type evalObj struct {
	id       int64
	typeName string
	fields   []string
	vals     []Interpretable
	provider ref.TypeProvider
}
func (o *evalObj) ID() int64 {
	return o.id
}
func (o *evalObj) Eval(ctx Activation) ref.Val {
	fieldVals := make(map[string]ref.Val)
	for i, field := range o.fields {
		val := o.vals[i].Eval(ctx)
		if types.IsUnknownOrError(val) {
			return val
		}
		fieldVals[field] = val
	}
	return o.provider.NewValue(o.typeName, fieldVals)
}
func (o *evalObj) Cost() (min, max int64) {
	return sumOfCost(o.vals)
}
func sumOfCost(interps []Interpretable) (min, max int64) {
	min, max = 0, 0
	for _, in := range interps {
		minT, maxT := estimateCost(in)
		min += minT
		max += maxT
	}
	return
}
type evalFold struct {
	id        int64
	accuVar   string
	iterVar   string
	iterRange Interpretable
	accu      Interpretable
	cond      Interpretable
	step      Interpretable
	result    Interpretable
}
func (fold *evalFold) ID() int64 {
	return fold.id
}
func (fold *evalFold) Eval(ctx Activation) ref.Val {
	foldRange := fold.iterRange.Eval(ctx)
	if !foldRange.Type().HasTrait(traits.IterableType) {
		return types.ValOrErr(foldRange, "got '%T', expected iterable type", foldRange)
	}
	accuCtx := varActivationPool.Get().(*varActivation)
	accuCtx.parent = ctx
	accuCtx.name = fold.accuVar
	accuCtx.val = fold.accu.Eval(ctx)
	iterCtx := varActivationPool.Get().(*varActivation)
	iterCtx.parent = accuCtx
	iterCtx.name = fold.iterVar
	it := foldRange.(traits.Iterable).Iterator()
	for it.HasNext() == types.True {
		iterCtx.val = it.Next()
		cond := fold.cond.Eval(iterCtx)
		condBool, ok := cond.(types.Bool)
		if !types.IsUnknown(cond) && ok && condBool != types.True {
			break
		}
		accuCtx.val = fold.step.Eval(iterCtx)
	}
	res := fold.result.Eval(accuCtx)
	varActivationPool.Put(iterCtx)
	varActivationPool.Put(accuCtx)
	return res
}
func (fold *evalFold) Cost() (min, max int64) {
	iMin, iMax := estimateCost(fold.iterRange)
	foldRange := fold.iterRange.Eval(EmptyActivation())
	if !foldRange.Type().HasTrait(traits.IterableType) {
		return 0, math.MaxInt64
	}
	var rangeCnt int64
	it := foldRange.(traits.Iterable).Iterator()
	for it.HasNext() == types.True {
		it.Next()
		rangeCnt++
	}
	aMin, aMax := estimateCost(fold.accu)
	cMin, cMax := estimateCost(fold.cond)
	sMin, sMax := estimateCost(fold.step)
	rMin, rMax := estimateCost(fold.result)
	return iMin + aMin + cMin + sMin + rMin,
		iMax + aMax + cMax*rangeCnt + sMax*rangeCnt + rMax
}
type evalSetMembership struct {
	inst        Interpretable
	arg         Interpretable
	argTypeName string
	valueSet    map[ref.Val]ref.Val
}
func (e *evalSetMembership) ID() int64 {
	return e.inst.ID()
}
func (e *evalSetMembership) Eval(ctx Activation) ref.Val {
	val := e.arg.Eval(ctx)
	if val.Type().TypeName() != e.argTypeName {
		return types.ValOrErr(val, "no such overload")
	}
	if ret, found := e.valueSet[val]; found {
		return ret
	}
	return types.False
}
func (e *evalSetMembership) Cost() (min, max int64) {
	return estimateCost(e.arg)
}
type evalWatch struct {
	Interpretable
	observer evalObserver
}
func (e *evalWatch) Eval(ctx Activation) ref.Val {
	val := e.Interpretable.Eval(ctx)
	e.observer(e.ID(), val)
	return val
}
func (e *evalWatch) Cost() (min, max int64) {
	return estimateCost(e.Interpretable)
}
type evalWatchAttr struct {
	InterpretableAttribute
	observer evalObserver
}
func (e *evalWatchAttr) AddQualifier(q Qualifier) (Attribute, error) {
	cq, isConst := q.(ConstantQualifier)
	if isConst {
		q = &evalWatchConstQual{
			ConstantQualifier: cq,
			observer:          e.observer,
			adapter:           e.InterpretableAttribute.Adapter(),
		}
	} else {
		q = &evalWatchQual{
			Qualifier: q,
			observer:  e.observer,
			adapter:   e.InterpretableAttribute.Adapter(),
		}
	}
	_, err := e.InterpretableAttribute.AddQualifier(q)
	return e, err
}
type evalWatchConstQual struct {
	ConstantQualifier
	observer evalObserver
	adapter  ref.TypeAdapter
}
func (e *evalWatchConstQual) Cost() (min, max int64) {
	return estimateCost(e.ConstantQualifier)
}
func (e *evalWatchConstQual) Qualify(vars Activation, obj interface{}) (interface{}, error) {
	out, err := e.ConstantQualifier.Qualify(vars, obj)
	var val ref.Val
	if err != nil {
		val = types.NewErr(err.Error())
	} else {
		val = e.adapter.NativeToValue(out)
	}
	e.observer(e.ID(), val)
	return out, err
}
func (e *evalWatchConstQual) QualifierValueEquals(value interface{}) bool {
	qve, ok := e.ConstantQualifier.(qualifierValueEquator)
	return ok && qve.QualifierValueEquals(value)
}
type evalWatchQual struct {
	Qualifier
	observer evalObserver
	adapter  ref.TypeAdapter
}
func (e *evalWatchQual) Cost() (min, max int64) {
	return estimateCost(e.Qualifier)
}
func (e *evalWatchQual) Qualify(vars Activation, obj interface{}) (interface{}, error) {
	out, err := e.Qualifier.Qualify(vars, obj)
	var val ref.Val
	if err != nil {
		val = types.NewErr(err.Error())
	} else {
		val = e.adapter.NativeToValue(out)
	}
	e.observer(e.ID(), val)
	return out, err
}
func (e *evalWatchAttr) Cost() (min, max int64) {
	return estimateCost(e.InterpretableAttribute)
}
func (e *evalWatchAttr) Eval(vars Activation) ref.Val {
	val := e.InterpretableAttribute.Eval(vars)
	e.observer(e.ID(), val)
	return val
}
type evalWatchConst struct {
	InterpretableConst
	observer evalObserver
}
func (e *evalWatchConst) Eval(vars Activation) ref.Val {
	val := e.Value()
	e.observer(e.ID(), val)
	return val
}
func (e *evalWatchConst) Cost() (min, max int64) {
	return estimateCost(e.InterpretableConst)
}
type evalExhaustiveOr struct {
	id  int64
	lhs Interpretable
	rhs Interpretable
}
func (or *evalExhaustiveOr) ID() int64 {
	return or.id
}
func (or *evalExhaustiveOr) Eval(ctx Activation) ref.Val {
	lVal := or.lhs.Eval(ctx)
	rVal := or.rhs.Eval(ctx)
	lBool, lok := lVal.(types.Bool)
	if lok && lBool == types.True {
		return types.True
	}
	rBool, rok := rVal.(types.Bool)
	if rok && rBool == types.True {
		return types.True
	}
	if lok && rok {
		return types.False
	}
	if types.IsUnknown(lVal) {
		return lVal
	}
	if types.IsUnknown(rVal) {
		return rVal
	}
	if types.IsError(lVal) {
		return lVal
	}
	return types.ValOrErr(rVal, "no such overload")
}
func (or *evalExhaustiveOr) Cost() (min, max int64) {
	return calExhaustiveBinaryOpsCost(or.lhs, or.rhs)
}
type evalExhaustiveAnd struct {
	id  int64
	lhs Interpretable
	rhs Interpretable
}