-
Notifications
You must be signed in to change notification settings - Fork 631
[CDEC-464] Switch uses of pipes
to conduit
#3305
Conversation
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 marked two areas that need attention.
I did not replace uses of pipes
in the post-mortem
executable from cardano-sl-tools
, since it does not build at present.
Once this PR is up I will look at bumping dependencies to get post-mortem
buildable, and then will change uses of pipes
there.
lib/src/Pos/Diffusion/Full/Block.hs
Outdated
lift $ sendRaw conv $ serializeMsgStreamBlock $ MsgSerializedBlock b | ||
loop nodeId conv (window - 1) | ||
mB <- await | ||
case mB of |
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.
❗️ The await
from conduit
returns a (Maybe a)
. The await
from pipes
returns an a
.
The conduit docs say here:
Wait for a single input value from upstream. If no data is available, returns Nothing. Once await returns Nothing, subsequent calls will also return Nothing.
It seems like if/when we hit the Nothing
case, we will loop forever. However in the previous pipes
code, I believe the Nothing
values would just be dropped, so I think the behavior should be the same.
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.
With conduit, await
returning a Nothing
means there is no more data to be got from the source.
I therefore think the we should not loop there. Instead, the Nothing
case should just do pure ()
or pure someReturnValue
depending on what is required.
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 chunk is in IO ()
, so pure ()
seems appropriate.
hoistLogic :: Monad m => (forall x . m x -> n x) -> Logic m -> Logic n | ||
hoistLogic nat logic = logic | ||
{ getSerializedBlock = nat . getSerializedBlock logic | ||
, streamBlocks = unsafeHoist nat . streamBlocks logic | ||
, streamBlocks = transPipe nat . streamBlocks logic |
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.
❗️transPipe
comes with a warning in the docs:
Note that the monad transforming function will be run multiple times, resulting in unintuitive behavior in some cases. For a fuller treatment, please see:
https://github.com/snoyberg/conduit/wiki/Dealing-with-monad-transformers
From reading the github post I think we're ok, because the only use of hoistLogic
calls elimRealMode
to unwrap a ReaderT, which shouldn't involve the state-carry-over effects mentioned as potential problems.
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.
Yep, that seems legit!
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.
Another way of saying this is that the passed in function foo :: (forall x. m x -> n x)
must be a monad morphism and not just any natural transformation. What this means, more or less, is that foo a >> foo b
should behave the same as foo (a >> b)
. If we set foo = flip evalState 1
, it's easy to see how these two examples will behave differently. I would recommend improving the documentation here, saying that the given function is expected to be a monad morphism.
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.
74ffa66
to
8c4e8ce
Compare
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.
The handling of the Nothing
case from the return of Counduit.await
is not correct and needs fixing.
8c4e8ce
to
221c1bf
Compare
d52d77c
to
2c5c07c
Compare
pipes
to conduit
pipes
to conduit
2c5c07c
to
172bcc0
Compare
172bcc0
to
3e5d6e9
Compare
I did not replace uses of `pipes` in the `post-mortem` executable from `cardano-sl-tools`, since it does not build at present.
3e5d6e9
to
d1f9688
Compare
@erikd I believe that I've confirmed correct behavior between the latest revision on this branch, the As such, this should be safe to merge. |
Description
The Cardano SL codebase currently depends on the pipes package in addition to depending on conduit.
Since used of conduit is far more prevalent we should replace all usage of pipes with conduit.
Linked issue
https://iohk.myjetbrains.com/youtrack/issue/CDEC-464
Type of change
Developer checklist
Testing checklist
^ no new tests added - existing ones should cover these changes.