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/compiler: retain unprocessed parsed modules #4910

Closed
srenatus opened this issue Jul 20, 2022 · 1 comment · Fixed by #4921
Closed

ast/compiler: retain unprocessed parsed modules #4910

srenatus opened this issue Jul 20, 2022 · 1 comment · Fixed by #4921

Comments

@srenatus
Copy link
Contributor

It would sometimes be handy -- when using OPA via Go -- to be able to retrieve the modules that the compiler has worked on in pristine state. So far, the code flow goes like this:

  1. c.Modules is a map[string]*Module of parsed ast.Module structs, as per the ast package's ParseModule(string, string) (*Module, error)
  2. c.Compile() is run
  3. c.Modules now contains the modules that have been rewritten by the various compiler stages

The enhancement here would be to add a new compiler options, e.g.

func (c *Compiler) WithKeepModules(yes bool) *Compiler {
	c.keepModules = yes
	return c
}

and if it was provided during compiler setup, we'd copy the modules into c.ParsedModules, a map[string]*Module to add to the compiler struct.

@tsandall
Copy link
Member

In addition, the ParsedModules map should include modules pulled in via the module loader callback.

@srenatus srenatus added this to Backlog in Open Policy Agent via automation Jul 21, 2022
@srenatus srenatus self-assigned this Jul 21, 2022
@srenatus srenatus moved this from Backlog to Planned - v0.43 in Open Policy Agent Jul 21, 2022
srenatus added a commit to srenatus/opa that referenced this issue Jul 25, 2022
The included change resetting `c.sorted` in `(*Compiler).Compile(...)` was
necessary to test the repeated compilation without a panic.

Fixes open-policy-agent#4910.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Open Policy Agent automation moved this from Planned - v0.43 to Done Jul 25, 2022
srenatus added a commit that referenced this issue Jul 25, 2022
The included change resetting `c.sorted` in `(*Compiler).Compile(...)` was
necessary to test the repeated compilation without a panic.

Fixes #4910.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

2 participants