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

ast: Disqualify indexing if candidate found in nested comprehension #2515

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

tsandall
Copy link
Member

@tsandall tsandall commented Jul 8, 2020

In v0.20. we added support for indexing and caching of comprehensions
in certain cases. There was a bug in the index construction that
allowed for comprehensions to be indexed and cached
incorrectly. Specifically, if any of the candidate keys appear in
nested comprehensions, indexing should not be performed because the
evaluator does not close over variable bindings from the outer scope
when evaluating the comprehension (because this would require cache
invalidation if there were multiple assignments to the variables in
the outer scope).

This fix updates the compiler to check if the candidates appear inside
of any nested comprehensions. If a match is found, no indexing is
performed.

Fixes #2497

Signed-off-by: Torin Sandall torinsandall@gmail.com

@tsandall tsandall requested a review from patrick-east July 8, 2020 15:47
@tsandall
Copy link
Member Author

tsandall commented Jul 8, 2020

@jaspervdj-luminal PTAL.

@tsandall
Copy link
Member Author

tsandall commented Jul 8, 2020

We should probably backport this onto v0.20 and v0.21 as bugfix releases.

Copy link
Contributor

@jaspervdj-luminal jaspervdj-luminal left a comment

Choose a reason for hiding this comment

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

Neat! Agree with the approach.

In v0.20. we added support for indexing and caching of comprehensions
in certain cases. There was a bug in the index construction that
allowed for comprehensions to be indexed and cached
incorrectly. Specifically, if any of the candidate keys appear in
nested comprehensions, indexing should not be performed because the
evaluator does not close over variable bindings from the outer scope
when evaluating the comprehension (because this would require cache
invalidation if there were multiple assignments to the variables in
the outer scope).

This fix updates the compiler to check if the candidates appear inside
of any nested comprehensions. If a match is found, no indexing is
performed.

Fixes open-policy-agent#2497

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Copy link
Contributor

@patrick-east patrick-east left a comment

Choose a reason for hiding this comment

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

LGTM

@tsandall tsandall merged commit e9779eb into open-policy-agent:master Jul 8, 2020
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.

Possible regression for dynamic dispatch + nested comprehensions
3 participants