-
Notifications
You must be signed in to change notification settings - Fork 479
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
Don't evaluate away builtins where the result might be unserializable #5664
Conversation
See the note. The test case does evaluate the uncompress application until you add the guard, so this is working as desired. We can see if it fixes Kenneth's problem.
This is a solution indeed. After reading your PR, I started wondering if going with option 3 (using a rewrite rule) is a better solution. The way this evaluateBuiltins bottom-up transformation is that it will go deep and cancel the saturated uncompress builtin. The problem is that when the transformation will go up, it will not apply an evaluate builtin which is worthwile and would not lead to serialisazation problems. Anyway it is difficult to explain so here is some test you could try:
This should ideally turn into (con bool true), but based on what I am reading in this PR, I suspect that it will not reduce |
Just for information,
in PLC, or
with |
Yep, that's absolutely a downside. I'm not so worried about that.
I think it's generally a bit awkward to have a pass that undoes what a different pass does. Not impossible though! One reason I like the current approach is that I think it also naturally extends to other types we might have in future that have this problem. On the other hand, I do think that running a later pass is nice in that the earlier passes don't have to know about the serializability problem. If we had many passes that could produce new constants then what we're doing here would be quite annoying. So I'm unsure. |
I am ok to go with this more principal approach, but I would appreciate a comment that 'a separate later pass to undo the evaluation would optimize more'. Also add please my example as a golden test with a comment! |
I've tried this on my branch and it enables me to get rid of all the workarounds and write what I'd expect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solves the original problem and the downsides don't seem too problematic. Maybe we could revisit it if we think of a better approach later (although that's a good way to bury the issue in the backlog for months/years).
Some (ValueOf DefaultUniBLS12_381_G1_Element _) -> True | ||
Some (ValueOf DefaultUniBLS12_381_G2_Element _) -> True | ||
Some (ValueOf DefaultUniBLS12_381_MlResult _) -> True | ||
_ -> False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could tediously spell out all the other cases here so that if we add more types to the universe we'd be forced to look at this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could, but I'm not sure it's worth it. This is a weird special case...
{ _biSemanticsVariant :: PLC.BuiltinSemanticsVariant fun | ||
, _biMatcherLike :: Map.Map fun (BuiltinMatcherLike uni fun) | ||
-- See Note [Unserializable constants] | ||
, _biUnserializableConstants :: Some (ValueOf uni) -> Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care about -ize versus -ise? Probably not: I think we're pretty inconsistent elsewhere. You could go for broke and call them "unzerializable" though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're massively inconsistent. I'm inconsistent in my own writing. I have no idea which is which, I just use them randomly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do these for G1 too?
I think you're right, but I'd suggest that if you've got a term involving these things that can be statically reduced then you've done something wrong because you probably shouldn't be doing that computation on the chain anyway. |
Ah, I remembered the other reason not to do a later pass: it can't handle the |
That's right. See this for example. |
f006475
to
413b3a9
Compare
Added. |
See the note. The test case does evaluate the uncompress application until you add the guard, so this is working as desired. We can see if it fixes Kenneth's problem.
Pre-submit checklist: