support opaque kinds
Kubernetes-commit: 953fbaca487c45e3e1fc655d212008a2be01ac53
This commit is contained in:
parent
cbc488649b
commit
65a6ca8228
|
|
@ -33,7 +33,7 @@ type CIDR struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CIDRType = cel.ObjectType("net.CIDR")
|
CIDRType = cel.OpaqueType("net.CIDR")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertToNative implements ref.Val.ConvertToNative.
|
// ConvertToNative implements ref.Val.ConvertToNative.
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ type IP struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
IPType = cel.ObjectType("net.IP")
|
IPType = cel.OpaqueType("net.IP")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertToNative implements ref.Val.ConvertToNative.
|
// ConvertToNative implements ref.Val.ConvertToNative.
|
||||||
|
|
|
||||||
|
|
@ -498,8 +498,15 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
|
||||||
rhs := args[1]
|
rhs := args[1]
|
||||||
if lhs.Type().Equal(rhs.Type()) == types.True {
|
if lhs.Type().Equal(rhs.Type()) == types.True {
|
||||||
t := lhs.Type()
|
t := lhs.Type()
|
||||||
|
if t.Kind() == types.OpaqueKind {
|
||||||
|
switch t.TypeName() {
|
||||||
|
case cel.IPType.TypeName(), cel.CIDRType.TypeName():
|
||||||
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if t.Kind() == types.StructKind {
|
||||||
switch t {
|
switch t {
|
||||||
case cel.IPType, cel.CIDRType, cel.QuantityType: // O(1) cost equality checks
|
case cel.QuantityType: // O(1) cost equality checks
|
||||||
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}}
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: 1}}
|
||||||
case cel.FormatType:
|
case cel.FormatType:
|
||||||
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: cel.MaxFormatSize}.MultiplyByCostFactor(common.StringTraversalCostFactor)}
|
return &checker.CallEstimate{CostEstimate: checker.CostEstimate{Min: 1, Max: cel.MaxFormatSize}.MultiplyByCostFactor(common.StringTraversalCostFactor)}
|
||||||
|
|
@ -515,6 +522,7 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if panicOnUnknown && !knownUnhandledFunctions[function] {
|
if panicOnUnknown && !knownUnhandledFunctions[function] {
|
||||||
panic(fmt.Errorf("EstimateCallCost: unhandled function %q, target %v, args %v", function, target, args))
|
panic(fmt.Errorf("EstimateCallCost: unhandled function %q, target %v, args %v", function, target, args))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue