Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested CallExpr cost estimation #571

Merged
merged 10 commits into from Aug 17, 2022
3 changes: 3 additions & 0 deletions checker/cost.go
Expand Up @@ -476,6 +476,9 @@ func (c *coster) sizeEstimate(t AstNode) SizeEstimate {
if l := c.estimator.EstimateSize(t); l != nil {
return *l
}
if _, ok := t.Expr().ExprKind.(*exprpb.Expr_CallExpr); ok {
DangerOnTheRanger marked this conversation as resolved.
Show resolved Hide resolved
DangerOnTheRanger marked this conversation as resolved.
Show resolved Hide resolved
return SizeEstimate{Min: 1, Max: 1}
}
return SizeEstimate{Min: 0, Max: math.MaxUint64}
}

Expand Down
9 changes: 9 additions & 0 deletions checker/cost_test.go
Expand Up @@ -354,6 +354,15 @@ func TestCost(t *testing.T) {
hints: map[string]int64{"str1": 10, "str2": 10},
wanted: CostEstimate{Min: 2, Max: 6},
},
{
name: "list size comparison",
expr: `list1.size() == list2.size()`,
DangerOnTheRanger marked this conversation as resolved.
Show resolved Hide resolved
decls: []*exprpb.Decl{
decls.NewVar("list1", decls.NewListType(decls.Int)),
decls.NewVar("list2", decls.NewListType(decls.Int)),
},
wanted: CostEstimate{Min: 5, Max: 5},
},
}

for _, tc := range cases {
Expand Down