-
Notifications
You must be signed in to change notification settings - Fork 486
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
'unsafeEvaluateCek' is overly lazy #3876
Comments
So what should we do in |
Drop first' :: (a -> c) -> (a, b) -> (c, b)
first' f (x, y) = (f x, y) I did check that that makes tests pass. |
Fixed |
Where's the PR that fixed this? I'm sure I saw a GitHub notification about this going past a while ago, but I can't find the PR now. |
Ah, I think it must have been #3877. I was misled by the fact that it says it's about tests. |
Area
[x] Plutus Foundation Related to the GHC plugin, Haskell-to-Plutus compiler, on-chain code
[] Plutus Application Framework Related to the Plutus application backend (PAB), emulator, Plutus libraries
[] Marlowe Related to Marlowe
[] Other Any other topic (Playgrounds, etc.)
So we have this issue with
unsafeEvaluateCek
not forcing the final result of a builtin application when the result ofunsafeEvaluateCek
is forced. I thought it might be some strictness problem within the definition of the CEK machine, however after inspecting and reinspecting all of its internals, I wasn't able to spot any problem, everything there looks exactly like it's supposed to. Then I looked intorunCekM
and nothing there seemed suspicious as well. So I started inserting bangs everywhere until I made the CEK machine so stupidly strict that it started forcing the result of a builtin application before doing budgeting for it and yet it still wasn't strict enough somehow. At this point I was convinced that the problem is not in the definition of the CEK machine, but rather how it was invoked. And indeed,unsafeEvaluateCek
is defined like this:and this seemingly innocuous definition is our culprit.
first
uses an irrefutable match (viabimap
) for(,)
(i.e. matches lazily on the spine of the tuple), which causes all subsequent forcing to WHNF not to force anything. Comparewith
So in our case forcing the result of
unsafeEvaluateCek
to WHNF does not do anything AT ALL, no evaluation happens whatsoever.Solution? Never use
bimap
,first
andsecond
over(,)
: if laziness is required, use something with a more suggestive name, if it's not,bimap
will do the wrong thing and so you should use the strict version of the function.And yeah, in case you're curious, the
Functor
instance for(,) a
matches strictly on the spine of the tuple, just for some extra confusion.I absolutely hate the reason why the
Bifunctor
instance for(,)
was implemented differently.The text was updated successfully, but these errors were encountered: