-
Notifications
You must be signed in to change notification settings - Fork 257
Preserve source information during CEL policy composition. #1253
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
base: master
Are you sure you want to change the base?
Conversation
|
/gcbrun |
cel/optimizer.go
Outdated
| func updateOffsetRanges(idGen ast.IDGenerator, info *ast.SourceInfo) { | ||
| newRanges := make(map[int64]ast.OffsetRange) | ||
| sortedOldIDs := []int64{} | ||
| for oldID := range info.OffsetRanges() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer copy(dst, src) to the for-loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://pkg.go.dev/builtin#copy it only works with slices, but in this case I am trying to copy the keys from a map.
policy/compiler.go
Outdated
| keepIDs = make(map[int64]bool) | ||
| } else { | ||
| // Remove offset ranges for ids without a corresponding AST node. This can happen because the | ||
| // checker deletes some nodes while rewriting the AST. For example the Select operand is deleted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should be able to do this cleanup within the parser and the checker rather than here. Could we explore that approach instead? Maybe as a separate PR so we can remove the cleanup here after that one is submitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #1258.
The old implementation outputs the wrong source information for policy files derived from the dummy AST created by RuleComposer.Compose. This change fixes that by preserving the correct source and merging the offset ranges of the rule match expressions inserted by the composer optimizer into the final AST.
The old implementation outputs the wrong source information for policy files derived from the dummy AST created by RuleComposer.Compose. This change fixes that by preserving the correct source and merging the offset ranges of the rule match expressions inserted by the composer optimizer into the final AST.