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
'opa build -t wasm' with functions defined on entrypoint fails with "undefined ref" #4411
Comments
Tests don't use the wasm eval path iirc... I suppose that's worth fixing. And the overlying problem, too, of course. Thanks for reporting |
Sent too early. That fail is at build time, before anything is evaluated. |
So it only happens with |
The example can be boiled down to package reproduction
g(_) = true
f(x) = g(x) However, it's unclear to me what the desired outcome of that Wasm bundle build is: If we only have functions in a package, evaluating the package's extent (i.e. using entrypoint If we have a rule in the that package, using that as entrypoint would seem like a decent workaround, since it's got the same result, and would not trigger this limitation. In the example above, if we had package reproduction
q = f(1) # new
g(_) = true
f(x) = g(x) and used I wonder when this would not be an option 🤔 I suppose if you have more than one rule, package reproduction
q = f(1)
r = f(2) # new
g(_) = true
f(x) = g(x) it would be desirable to have a Bottom line, there is a bug in the compiler code triggered here; but for prioritizing, it would help to know more about your use -- i.e., is the mentioned workaround viable for you? |
Thank you for confirming. As you discovered, the reproduction (and your further reduction) is trivial and not interesting. This comes up when composing multiple functions into complex rules. I attempted a simplest example of the problem in this issue, but here's the shape where this comes up: query_filter_has_x(query, filter) = {"bool": true, "reason": "filter has x"} {
query[filter].x
} else = {"bool": false, "reason": "filter does not have x"}
query_filter_has_y(query, filter) = {"bool": true, "reason": "filter has y"} {
query[filter].y
} else = {"bool": false, "reason": "filter does not have y"}
query_filter_blah(query, filter) = {"bool": true, "reason": "filter blah"} {
query[filter].blah
} else = {"bool": false, "reason": "filter does not blah"}
# with the above shape, you can start composing things which will propagate reasons to the output
# imagine utils.bool_and, utils.bool_or, and utils.bool_not do what you think they should
# and return {"bool": bool, "reason": string} shapes
query_filter_something_more_complex(query, filter) = utils.bool_and(
[
query_filter_has_x(query, filter),
utils.bool_not(query_filter_has_y(query, filter)),
utils.bool_or(
[
query_filter_has_y(query, filter),
query_filter_blah(query, filter)
],
{
"true_reason": "y or blah",
"false_reason": "not y or not blah"
}
],
{
"true_reason": "something more complex",
"false_reason": "something not more complex"
}
)
# then we use these constructs for actual rules
allow = {
query_filter_something_more_complex(my_query, my_filter).bool
}
reason["allow_something_more_complex"] = query_filter_something_more_complex(my_query, my_filter).reason The
When attempting function composition like this, things will fail to compile. That's the real use case, function composition. The real use case uses Regarding prioritization, while the pattern I shared above will not compile in a single package, we did manage to find a workaround and noticed that if we put the functions being composed in a separate package, then we can compose them. This has worked so far, and may work for now. My concern is with artificially breaking things out into packages instead of keeping code that goes together together. |
I'm glad you've got a workaround; this still is something we should fix. I'd have to dig in a bit to understand the rationale behind the current way things are done 🔍 May I ask about your use case? I'm always curious about people using wasm 😅 |
Oh, nothing exciting, run in Node.js :) |
Using npm-opa-wasm? |
🤔 ... const {loadPolicy} = require("@open-policy-agent/opa-wasm") Yes. Very helpful. |
@tristanls Whats your use case? Would passing |
@srenatus I am having difficulty understanding what package reproduction
q = f(1)
r = f(2) # new
g(_) = true
f(x) = g(x) What is pruned when When I tried to use latest
I got
|
Please try again with 0.44.0. |
@tristanls if you find the time, I'd be curious to know if this helped solve your issue 🙂 |
Let's reopen if this still is a problem! 🧹 |
Short description
Everything builds and tests pass. When attempting to build for WASM:
Problem observed on 0.38.0, 0.37.2
Steps To Reproduce
reproduction.rego
reproduction_test.rego
Expected behavior
Successful WASM build or test build failing or tests not passing.
Additional context
The text was updated successfully, but these errors were encountered: