-
Notifications
You must be signed in to change notification settings - Fork 34
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
Mysterious case of vars dropped in iteration after rewrite #982
Comments
I've been zooming in on what the compiler does to found.vars[__local290__][__local291__] contains __local295__ if {
__local289__ = data.regal.ast._rules[__local288__]
sprintf("%d", [__local288__], __local1972__)
__local290__ = __local1972__
walk(__local289__, [path, value])
regal.last(path, __local1973__)
data.regal.ast._find_vars(value, __local1973__, __local1974__)
__local292__ = __local1974__[__local291__]
__local295__ = __local292__[__local294__]
}
found.refs[__local298__] contains value if {
__local297__ = data.regal.ast._rules[__local296__]
sprintf("%d", [__local296__], __local1975__)
__local298__ = __local1975__
walk(__local297__, [_, value])
data.regal.ast.is_ref(value)
}
found.symbols[__local301__] contains __local3060__ if {
__local300__ = data.regal.ast._rules[__local299__]
sprintf("%d", [__local299__], __local1976__)
__local301__ = __local1976__
walk(__local300__, [_, value])
__local3060__ = value.symbols
} With the change, we get: found.vars[__local290__][__local291__] contains __local295__ if {
__local289__ = data.regal.ast._rules[__local288__]
sprintf("%d", [__local288__], __local1973__)
__local290__ = __local1973__
walk(__local289__, [path, value])
regal.last(path, __local1974__)
data.regal.ast._find_vars(value, __local1974__, __local1975__)
__local292__ = __local1975__[__local291__]
__local295__ = __local292__[__local294__]
}
found[__local299__][__local298__] contains __local300__ if {
__local297__ = data.regal.ast._rules[__local296__]
sprintf("%d", [__local296__], __local1976__)
__local298__ = __local1976__
walk(__local297__, [_, value])
data.regal.ast.refs_or_symbols(value, __local1977__)
[__local299__, __local300__] = __local1977__
} Now, we know from looking at this in our zoom call, that for the second eval, this is what failed: __local292__ = __local1975__[__local291__] (it's the |
I spent some time just now trying to narrow this one down somewhat, and while I still haven't got a clue as to what the cause of this is, I've at least found that:
i.e. going from this lintQuery = ast.MustParseBody(`lint := {
"violations": data.regal.main.lint.violations,
"notices": data.regal.main.lint.notices,
}`) to this lintQuery = ast.MustParseBody(`lint := {
"violations": data.regal.main.lint.violations,
"notices": data.regal.main.lint.notices,
"vars": data.regal.ast.found.vars,
}`)
I don't know what to make of this, but perhaps it'll help someone else get closer to a resolution of this mystery... :) CC @johanfylling @srenatus |
Starting to really narrow it down now! Turns out there's a single rule that when enabled triggers this, and when disabled things work as expected again.
There are many rules that query
|
I wonder if this isn't a virtual-cache thing 🤔 .. |
Finally able to reproduce this in OPA: open-policy-agent/opa#6926 Since this isn't an issue in any current code used in this project, I'll close this issue. Definitely coming back to this when fixed in OPA though! |
Time to revisit this, perhaps? 🤔 |
Yes, too much to do right now, but once we have OPA v0.68.0 out and about, let's do that! And create a new issue about it being much slower than |
I was hoping to be able to reproduce this in OPA only, but so far I've not been able to do so. Therefore I'll file an issue here, and we can see where to take it later. This is by all means a bug somewhere, but since it doesn't affect Regal as the code currently is shipped, I won't label it as such.
In an effort to reduce the number of
walk
calls made, I've tried to replace two "static" rules with one dynamic. The code below is found in the search.rego file.Old
New
While this seems to work, the remaining "static" rule now shows some truly weird behavior:
Storing the result of
_find_vars(value, regal.last(path))
shows a few vars found in the input AST. However, printing the value of thecontext
in thesome
iteration below shows only a few of those.Example input to reproduce:
p.rego
Now run:
Before the change, the output of
print
will be:As expected. After the change, the output is:
As seen, the
some
var that should have been bound to context dissapeared somewhere.The text was updated successfully, but these errors were encountered: