-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
planner: fix ref heads processing #5418
planner: fix ref heads processing #5418
Conversation
7214708
to
b5a4a5c
Compare
b5a4a5c
to
c1ab3b0
Compare
With the introduction of ref heads in open-policy-agent#4660, the planned IR still mostly worked, but it was bypassing the CallDynamic optimization when it shouldn't have. This commit re-works some of the rule planning to more robustly handle ref heads. Also adds a few test cases to get a grip on what should and should not happen. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
c1ab3b0
to
4834c9a
Compare
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.
📝 comments
default: // cut off | ||
r = r[:len(r)-1] | ||
} | ||
val := p.rules.LookupOrInsert(r) |
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.
ℹ️ We now take care of the last ref segment when builtin ruletrie
, not when retrieving something from it.
This is what the changes comes down to:
- putting the rules into the rule trie without any non-string pieces:
- so
a.b.c = 1
is a different node thana.b[1] = 2
- so
- taking care of building objects or not when planning any given rule set, not by passing a boolean to
planRules()
- the
optimizeLookup
code flow had to be adjusted to not make the change in (1.) avoid optimizations that are desired.
default: | ||
// Needs to be fixed if we allow non-string ref pieces, like `p.q[3][4].r = x` | ||
pathPieces = append(pathPieces, q.String()) | ||
panic("impossible") |
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.
If our functions had "path pieces" that are not strings, they'll fail in the call_dynamic mapping lookup. For #4660, we've started out with string prefixes (not generic refs), so this should be OK.
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.
I appreciate the battery of testcases for this PR. It looks like there was some nice refactoring done, especially in internal/planner/planner.go
Thanks for the review!
Mostly just reverting a shoddy first try 😅 Hope this one is more robust 🤞 |
With the introduction of ref heads in #4660, the planned IR still mostly worked, but it was bypassing the CallDynamic optimization when it shouldn't have.
This commit re-works some of the rule planning to more robustly handle ref heads.
Also adds a few test cases to get a grip on what should and should not happen.