Run pin-dependency.sh and update-vendor.sh.

This commit is contained in:
Kermit Alexander II
2022-08-22 16:59:14 +00:00
parent d581cc90ad
commit 4a703d6cbc
17 changed files with 192 additions and 166 deletions

View File

@@ -835,7 +835,9 @@ func (fold *evalFold) Eval(ctx Activation) ref.Val {
varActivationPool.Put(accuCtx)
// Convert a mutable list to an immutable one, if the comprehension has generated a list as a result.
if !types.IsUnknownOrError(res) && buildingList {
res = res.(traits.MutableLister).ToImmutableList()
if _, ok := res.(traits.MutableLister); ok {
res = res.(traits.MutableLister).ToImmutableList()
}
}
return res
}

View File

@@ -95,7 +95,7 @@ type planner struct {
// such as state-tracking, expression re-write, and possibly efficient thread-safe memoization of
// repeated expressions.
func (p *planner) Plan(expr *exprpb.Expr) (Interpretable, error) {
switch expr.ExprKind.(type) {
switch expr.GetExprKind().(type) {
case *exprpb.Expr_CallExpr:
return p.decorate(p.planCall(expr))
case *exprpb.Expr_IdentExpr:
@@ -146,10 +146,10 @@ func (p *planner) planIdent(expr *exprpb.Expr) (Interpretable, error) {
func (p *planner) planCheckedIdent(id int64, identRef *exprpb.Reference) (Interpretable, error) {
// Plan a constant reference if this is the case for this simple identifier.
if identRef.Value != nil {
if identRef.GetValue() != nil {
return p.Plan(&exprpb.Expr{Id: id,
ExprKind: &exprpb.Expr_ConstExpr{
ConstExpr: identRef.Value,
ConstExpr: identRef.GetValue(),
}})
}
@@ -157,9 +157,9 @@ func (p *planner) planCheckedIdent(id int64, identRef *exprpb.Reference) (Interp
// registered with the provider.
cType := p.typeMap[id]
if cType.GetType() != nil {
cVal, found := p.provider.FindIdent(identRef.Name)
cVal, found := p.provider.FindIdent(identRef.GetName())
if !found {
return nil, fmt.Errorf("reference to undefined type: %s", identRef.Name)
return nil, fmt.Errorf("reference to undefined type: %s", identRef.GetName())
}
return NewConstValue(id, cVal), nil
}
@@ -167,14 +167,15 @@ func (p *planner) planCheckedIdent(id int64, identRef *exprpb.Reference) (Interp
// Otherwise, return the attribute for the resolved identifier name.
return &evalAttr{
adapter: p.adapter,
attr: p.attrFactory.AbsoluteAttribute(id, identRef.Name),
attr: p.attrFactory.AbsoluteAttribute(id, identRef.GetName()),
}, nil
}
// planSelect creates an Interpretable with either:
// a) selects a field from a map or proto.
// b) creates a field presence test for a select within a has() macro.
// c) resolves the select expression to a namespaced identifier.
//
// a) selects a field from a map or proto.
// b) creates a field presence test for a select within a has() macro.
// c) resolves the select expression to a namespaced identifier.
func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) {
// If the Select id appears in the reference map from the CheckedExpr proto then it is either
// a namespaced identifier or enum value.
@@ -193,7 +194,7 @@ func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) {
var fieldType *ref.FieldType
opType := p.typeMap[sel.GetOperand().GetId()]
if opType.GetMessageType() != "" {
ft, found := p.provider.FindFieldType(opType.GetMessageType(), sel.Field)
ft, found := p.provider.FindFieldType(opType.GetMessageType(), sel.GetField())
if found && ft.IsSet != nil && ft.GetFrom != nil {
fieldType = ft
}
@@ -213,15 +214,15 @@ func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) {
if sel.TestOnly {
// Return the test only eval expression.
return &evalTestOnly{
id: expr.Id,
field: types.String(sel.Field),
id: expr.GetId(),
field: types.String(sel.GetField()),
fieldType: fieldType,
op: op,
}, nil
}
// Build a qualifier.
qual, err := p.attrFactory.NewQualifier(
opType, expr.Id, sel.Field)
opType, expr.GetId(), sel.GetField())
if err != nil {
return nil, err
}
@@ -329,7 +330,7 @@ func (p *planner) planCallZero(expr *exprpb.Expr,
return nil, fmt.Errorf("no such overload: %s()", function)
}
return &evalZeroArity{
id: expr.Id,
id: expr.GetId(),
function: function,
overload: overload,
impl: impl.Function,
@@ -354,7 +355,7 @@ func (p *planner) planCallUnary(expr *exprpb.Expr,
nonStrict = impl.NonStrict
}
return &evalUnary{
id: expr.Id,
id: expr.GetId(),
function: function,
overload: overload,
arg: args[0],
@@ -382,7 +383,7 @@ func (p *planner) planCallBinary(expr *exprpb.Expr,
nonStrict = impl.NonStrict
}
return &evalBinary{
id: expr.Id,
id: expr.GetId(),
function: function,
overload: overload,
lhs: args[0],
@@ -411,7 +412,7 @@ func (p *planner) planCallVarArgs(expr *exprpb.Expr,
nonStrict = impl.NonStrict
}
return &evalVarArgs{
id: expr.Id,
id: expr.GetId(),
function: function,
overload: overload,
args: args,
@@ -425,7 +426,7 @@ func (p *planner) planCallVarArgs(expr *exprpb.Expr,
func (p *planner) planCallEqual(expr *exprpb.Expr,
args []Interpretable) (Interpretable, error) {
return &evalEq{
id: expr.Id,
id: expr.GetId(),
lhs: args[0],
rhs: args[1],
}, nil
@@ -435,7 +436,7 @@ func (p *planner) planCallEqual(expr *exprpb.Expr,
func (p *planner) planCallNotEqual(expr *exprpb.Expr,
args []Interpretable) (Interpretable, error) {
return &evalNe{
id: expr.Id,
id: expr.GetId(),
lhs: args[0],
rhs: args[1],
}, nil
@@ -445,7 +446,7 @@ func (p *planner) planCallNotEqual(expr *exprpb.Expr,
func (p *planner) planCallLogicalAnd(expr *exprpb.Expr,
args []Interpretable) (Interpretable, error) {
return &evalAnd{
id: expr.Id,
id: expr.GetId(),
lhs: args[0],
rhs: args[1],
}, nil
@@ -455,7 +456,7 @@ func (p *planner) planCallLogicalAnd(expr *exprpb.Expr,
func (p *planner) planCallLogicalOr(expr *exprpb.Expr,
args []Interpretable) (Interpretable, error) {
return &evalOr{
id: expr.Id,
id: expr.GetId(),
lhs: args[0],
rhs: args[1],
}, nil
@@ -486,7 +487,7 @@ func (p *planner) planCallConditional(expr *exprpb.Expr,
return &evalAttr{
adapter: p.adapter,
attr: p.attrFactory.ConditionalAttribute(expr.Id, cond, tAttr, fAttr),
attr: p.attrFactory.ConditionalAttribute(expr.GetId(), cond, tAttr, fAttr),
}, nil
}
@@ -541,7 +542,7 @@ func (p *planner) planCreateList(expr *exprpb.Expr) (Interpretable, error) {
elems[i] = elemVal
}
return &evalList{
id: expr.Id,
id: expr.GetId(),
elems: elems,
adapter: p.adapter,
}, nil
@@ -570,7 +571,7 @@ func (p *planner) planCreateStruct(expr *exprpb.Expr) (Interpretable, error) {
vals[i] = valVal
}
return &evalMap{
id: expr.Id,
id: expr.GetId(),
keys: keys,
vals: vals,
adapter: p.adapter,
@@ -596,7 +597,7 @@ func (p *planner) planCreateObj(expr *exprpb.Expr) (Interpretable, error) {
vals[i] = val
}
return &evalObj{
id: expr.Id,
id: expr.GetId(),
typeName: typeName,
fields: fields,
vals: vals,
@@ -628,7 +629,7 @@ func (p *planner) planComprehension(expr *exprpb.Expr) (Interpretable, error) {
return nil, err
}
return &evalFold{
id: expr.Id,
id: expr.GetId(),
accuVar: fold.AccuVar,
accu: accu,
iterVar: fold.IterVar,
@@ -646,12 +647,12 @@ func (p *planner) planConst(expr *exprpb.Expr) (Interpretable, error) {
if err != nil {
return nil, err
}
return NewConstValue(expr.Id, val), nil
return NewConstValue(expr.GetId(), val), nil
}
// constValue converts a proto Constant value to a ref.Val.
func (p *planner) constValue(c *exprpb.Constant) (ref.Val, error) {
switch c.ConstantKind.(type) {
switch c.GetConstantKind().(type) {
case *exprpb.Constant_BoolValue:
return p.adapter.NativeToValue(c.GetBoolValue()), nil
case *exprpb.Constant_BytesValue:

View File

@@ -41,17 +41,23 @@ type astPruner struct {
// A)
// 1) Evaluate expr with some unknowns,
// 2) If result is unknown:
// a) PruneAst
// b) Goto 1
//
// a) PruneAst
// b) Goto 1
//
// Functional call results which are known would be effectively cached across
// iterations.
//
// B)
// 1) Compile the expression (maybe via a service and maybe after checking a
// compiled expression does not exists in local cache)
//
// compiled expression does not exists in local cache)
//
// 2) Prepare the environment and the interpreter. Activation might be empty.
// 3) Eval the expression. This might return unknown or error or a concrete
// value.
//
// value.
//
// 4) PruneAst
// 4) Maybe cache the expression
// This is effectively constant folding the expression. How the environment is
@@ -232,9 +238,9 @@ func (p *astPruner) prune(node *exprpb.Expr) (*exprpb.Expr, bool) {
// transform, or expression was not evaluated. If possible, drill down
// more.
switch node.ExprKind.(type) {
switch node.GetExprKind().(type) {
case *exprpb.Expr_SelectExpr:
if operand, pruned := p.prune(node.GetSelectExpr().Operand); pruned {
if operand, pruned := p.prune(node.GetSelectExpr().GetOperand()); pruned {
return &exprpb.Expr{
Id: node.GetId(),
ExprKind: &exprpb.Expr_SelectExpr{