Skip to content

Commit b023645

Browse files
Cost tracking for list operations (#1192)
1 parent 41023c5 commit b023645

File tree

6 files changed

+547
-35
lines changed

6 files changed

+547
-35
lines changed

‎checker/cost.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,16 +545,17 @@ func (c *coster) costCall(e ast.Expr) CostEstimate {
545545
if len(overloadIDs) == 0 {
546546
return CostEstimate{}
547547
}
548-
var targetType AstNode
548+
var targetType *AstNode
549549
if call.IsMemberFunction() {
550550
sum = sum.Add(c.cost(call.Target()))
551-
targetType = c.newAstNode(call.Target())
551+
var t AstNode = c.newAstNode(call.Target())
552+
targetType = &t
552553
}
553554
// Pick a cost estimate range that covers all the overload cost estimation ranges
554555
fnCost := CostEstimate{Min: uint64(math.MaxUint64), Max: 0}
555556
var resultSize *SizeEstimate
556557
for _, overload := range overloadIDs {
557-
overloadCost := c.functionCost(e, call.FunctionName(), overload, &targetType, argTypes, argCosts)
558+
overloadCost := c.functionCost(e, call.FunctionName(), overload, targetType, argTypes, argCosts)
558559
fnCost = fnCost.Union(overloadCost.CostEstimate)
559560
if overloadCost.ResultSize != nil {
560561
if resultSize == nil {

‎ext/BUILD.bazel‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ go_library(
2727
deps = [
2828
"//cel:go_default_library",
2929
"//checker:go_default_library",
30+
"//common:go_default_library",
3031
"//common/ast:go_default_library",
3132
"//common/decls:go_default_library",
3233
"//common/env:go_default_library",
@@ -70,6 +71,7 @@ go_test(
7071
deps = [
7172
"//cel:go_default_library",
7273
"//checker:go_default_library",
74+
"//common:go_default_library",
7375
"//common/env:go_default_library",
7476
"//common/types:go_default_library",
7577
"//common/types/ref:go_default_library",

‎ext/README.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ zero-based.
412412

413413
### Distinct
414414

415-
**Introduced in version 2**
415+
**Introduced in version 2 (cost support in version 3)**
416416

417417
Returns the distinct elements of a list.
418418

@@ -426,7 +426,7 @@ Examples:
426426

427427
### Flatten
428428

429-
**Introduced in version 1**
429+
**Introduced in version 1 (cost support in version 3)**
430430

431431
Flattens a list recursively.
432432
If an optional depth is provided, the list is flattened to a the specificied level.
@@ -445,7 +445,7 @@ Examples:
445445

446446
### Range
447447

448-
**Introduced in version 2**
448+
**Introduced in version 2 (cost support in version 3)**
449449

450450
Returns a list of integers from 0 to n-1.
451451

@@ -458,7 +458,7 @@ Examples:
458458

459459
### Reverse
460460

461-
**Introduced in version 2**
461+
**Introduced in version 2 (cost support in version 3)**
462462

463463
Returns the elements of a list in reverse order.
464464

@@ -471,6 +471,7 @@ Examples:
471471

472472
### Slice
473473

474+
**Introduced in version 0 (cost support in version 3)**
474475

475476
Returns a new sub-list using the indexes provided.
476477

@@ -483,7 +484,7 @@ Examples:
483484

484485
### Sort
485486

486-
**Introduced in version 2**
487+
**Introduced in version 2 (cost support in version 3)**
487488

488489
Sorts a list with comparable elements. If the element type is not comparable
489490
or the element types are not the same, the function will produce an error.
@@ -500,7 +501,7 @@ Examples:
500501

501502
### SortBy
502503

503-
**Introduced in version 2**
504+
**Introduced in version 2 (cost support in version 3)**
504505

505506
Sorts a list by a key value, i.e., the order is determined by the result of
506507
an expression applied to each element of the list.

0 commit comments

Comments
 (0)