Skip to content

Conversation

@TristonianJones
Copy link
Collaborator

Type checking correctly resolves namespaced function names like base64.encode; however, this information was being lost at evaluation time with the fragment base64 being treated as a variable name and encode as the function name.

This PR fixes the glitch for namespaced function resolution ensuring the evaluator honors the CEL program container name and qualified function names.

@TristonianJones
Copy link
Collaborator Author

TristonianJones commented Apr 23, 2020

@JimLarson PTAL, the PR now introduces AST rewrites at Check time to drop / consolidate parse-time AST fragments in favor of ASTs that more accurately represent the eval intent.

Note, while the AST is modified, the following features have been preserved to ensure that generated ASTs are compatible with existing evaluators:

  • overload_id names remain the same and are preserved in the CheckedExpr.reference_map
    (Go, Java)
  • qualified function names are packed into the CallExpr.function field without a leading '.' as the
    names are expected to be fully-qualified post-check. C++ does not consider the leading '.'
    during name resolution. (Go, C++)
  • qualified identifier names are packed into an IdentExpr.name field without a leading '.' as the
    names are expected to be fully-qualified post-check. This may result in slightly more resolution
    cost for evaluators that only consider the parsed representation and attempt field resolution
    for backwards compatibility (C++)
  • qualified type names are packed into the CreateStructExpr..message_name.

In most cases, the net effect will be simpler, more consistent evaluation of checked expressions within evaluators, even when the evaluator ignores the checker metadata produced in the reference_map and type_map.

Once submitted, I'm going to apply a v0.5.0 release label to indicate the potential for a breaking change in the AST representation.

@TristonianJones
Copy link
Collaborator Author

PTAL whenever you have a chance @JimLarson. Thanks.

}

func (c *checker) checkIdent(e *exprpb.Expr) {
// Rewrite the identifier to its fully qualified name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider putting this comment at line 150, in the block where we're actually doing this rewrite.

return
}
// Check to see whether the overload resolves.
call.Function = fn.GetName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment "Overwrite function name with fully-qualified resolved name."

@TristonianJones TristonianJones merged commit abf6094 into google:master May 6, 2020
@TristonianJones TristonianJones deleted the fix-eval-func-resolution branch May 6, 2020 13:34
TristonianJones added a commit to rachelmyers/cel-go that referenced this pull request Jun 15, 2020
* Fix namespaced function resolution
* Introduce AST rewrites at Check-time to better handle function / ident resolution at evaluation time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants