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: Importing rego.v1 in v0 support modules when applicable #6698

Conversation

johanfylling
Copy link
Contributor

Prioritizing generating v0 Rego with rego.v1 import when producing support modules for non---v1-compatible optimized builds.

Affects opa build when the -O flag is used for optimization, and opa eval for partial evaluation with the -p flag.

Fixes: #6450

return true
}
return false
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to create tests for this before un-drafting this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it even possible to retain var names such that they conflict with v1 keywords? Or are they all rewritten? Any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

@srenatus any idea about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could do something similar for imports in the generated support module, but I believe all references would be locally rewritten to complete refs anyways ..

Copy link

netlify bot commented Apr 15, 2024

Deploy Preview for openpolicyagent ready!

Name Link
🔨 Latest commit 65ebbde
🔍 Latest deploy log https://app.netlify.com/sites/openpolicyagent/deploys/662936fdbe94d20008ffd897
😎 Deploy Preview https://deploy-preview-6698--openpolicyagent.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@johanfylling johanfylling marked this pull request as ready for review April 16, 2024 08:50
Prioritizing generating v0 Rego with `rego.v1` import when producing support modules for non-`--v1-compatible` optimized builds.

Affects `opa build` when the `-O` flag is used for optimization, and `opa eval` for partial evaluation with the `-p` flag.

Fixes: open-policy-agent#6450
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
@ashutosh-narkar ashutosh-narkar force-pushed the rego-v1/v0compat1_support_modules branch from 049bcc7 to 80dfbbf Compare April 22, 2024 21:20
Copy link
Member

@ashutosh-narkar ashutosh-narkar left a comment

Choose a reason for hiding this comment

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

The changes look fine. Few comments 👇

query: "data.test.p",
module: `package test

import rego.v1
Copy link
Member

Choose a reason for hiding this comment

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

If the module had the future import would the optimized module use the rego import if regoV1ImportCapable: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. When we build the support module, we don't have this information retained. We could probably trace the content of a single support rule back to it's origin module and do whatever relevant imports it does, but I'm not sure that's worth the effort, given that multiple origin modules could be contributing to the same support module, and they can all have their own import scheme.
I think the important thing here is that we produce Rego that is in line with the code style we recommend, which is to use the rego.v1 import.

input.x == 1
}`,
},
// rego.v1 import not used, since rule name conflicts with future keyword
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I'm missing something but if we have regoV1ImportCapable: true, then shouldn't there be a compile error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. regoV1ImportCapable is only an indication for if we have the capability to use the rego.v1 import (the rego_v1_import feature is in the capabilities file). We opt-out of using it if there are any existing rules that will conflict with that import; such ase the contains rule in this test case.

return true
}
return false
})
Copy link
Member

Choose a reason for hiding this comment

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

@srenatus any idea about this?

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
@johanfylling johanfylling merged commit b58e87f into open-policy-agent:main Apr 24, 2024
26 checks passed
@johanfylling johanfylling deleted the rego-v1/v0compat1_support_modules branch April 24, 2024 17:02
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.

Optimized bundle build doesn't respect rego.v1 and future.keywords imports
2 participants