-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
format package unexpectedly mutating AST nodes #2439
Labels
Comments
tsandall
added a commit
to tsandall/opa
that referenced
this issue
May 29, 2020
As part of this change, also update the format package to unmangle the variables slightly differently--just remove the wildcard prefix instead of translating the variable names. This makes it easier to tell where the variables came from in the first place and is a bit less complicated. Fixes open-policy-agent#2439 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
patrick-east
pushed a commit
that referenced
this issue
May 29, 2020
As part of this change, also update the format package to unmangle the variables slightly differently--just remove the wildcard prefix instead of translating the variable names. This makes it easier to tell where the variables came from in the first place and is a bit less complicated. Fixes #2439 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
patrick-east
pushed a commit
to patrick-east/opa
that referenced
this issue
Jun 1, 2020
As part of this change, also update the format package to unmangle the variables slightly differently--just remove the wildcard prefix instead of translating the variable names. This makes it easier to tell where the variables came from in the first place and is a bit less complicated. Fixes open-policy-agent#2439 Signed-off-by: Torin Sandall <torinsandall@gmail.com> (cherry picked from commit fe18f11)
This was referenced Jun 1, 2020
patrick-east
pushed a commit
that referenced
this issue
Jun 1, 2020
As part of this change, also update the format package to unmangle the variables slightly differently--just remove the wildcard prefix instead of translating the variable names. This makes it easier to tell where the variables came from in the first place and is a bit less complicated. Fixes #2439 Signed-off-by: Torin Sandall <torinsandall@gmail.com> (cherry picked from commit fe18f11)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
format.Ast
function may mutate AST nodes to un-mangle wildcard variables. The problem is that this mutation/un-mangling is not applied consistently across multiple calls toformat.Ast
if the the inputs toformat.Ast
contain pointers to the same term strurcts. This problem can be reproduced by running the newopa build
command with optimization enabled and multiple entrypoints specified:x.rego
run the build:
inspect the output:
We run into this with
opa build
because the compiler only generates a single result term for all entrypoint PE runs--e.g., the compiler outputs rules like this:and
Under the hood, the $result variable in the rule heads point to the same memory. The $result variable in the bodies point to different memory due to rewriting that happens on build. When the format package runs on one of the modules the $result variables are un-mangled to
__wildcard0__
consistently--however, when the $result in the head is un-mangled, the term is mutated in place--this causes the term in the other module to get updated. When the format package runs on the other module, it only sees one occurrence of $result so it doesn't do any unmangling.The text was updated successfully, but these errors were encountered: