Skip to content

Commit

Permalink
Remove hack references.
Browse files Browse the repository at this point in the history
  • Loading branch information
DangerOnTheRanger committed Mar 3, 2023
1 parent 739dcdd commit 22aee46
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
9 changes: 5 additions & 4 deletions interpreter/interpretable.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ type InterpretableConstructor interface {
// Core Interpretable implementations used during the program planning phase.

type evalTestOnly struct {
id int64
attr InterpretableAttribute
qual Qualifier
field types.String
id int64
attr InterpretableAttribute
qual Qualifier
field types.String
isProtoField bool
}

// ID implements the Interpretable interface method.
Expand Down
16 changes: 12 additions & 4 deletions interpreter/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,19 @@ func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) {

// Return the test only eval expression.
if sel.GetTestOnly() {
isProtoField := false
if opType.GetMessageType() != "" {
ft, found := p.provider.FindFieldType(opType.GetMessageType(), sel.GetField())
if found && ft.IsSet != nil && ft.GetFrom != nil {
isProtoField = true
}
}
return &evalTestOnly{
id: expr.GetId(),
field: types.String(sel.GetField()),
attr: attr,
qual: qual,
id: expr.GetId(),
field: types.String(sel.GetField()),
attr: attr,
qual: qual,
isProtoField: isProtoField,
}, nil
}

Expand Down
6 changes: 6 additions & 0 deletions interpreter/runtimecost.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ type ActualCostEstimator interface {
func CostObserver(tracker *CostTracker) EvalObserver {
observer := func(id int64, programStep any, val ref.Val) {
switch t := programStep.(type) {
case *evalTestOnly:
// Protobuf has() checks do not incur runtime cost due to not using Eval()
// in older versions of CEL; this keeps the runtime cost behavior consistent
if !t.isProtoField {
tracker.cost++
}
case ConstantQualifier:
// 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.
Expand Down

0 comments on commit 22aee46

Please sign in to comment.