-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fewer processes and Sender
s
#49
Conversation
9319eee
to
46837ae
Compare
Sender
sSender
s
src/ghci/stdout.rs
Outdated
@@ -203,20 +128,17 @@ impl GhciStdout { | |||
} | |||
|
|||
#[instrument(skip_all, level = "debug")] | |||
async fn show_modules(&mut self, sender: oneshot::Sender<ModuleSet>) -> miette::Result<()> { | |||
pub async fn show_modules(&mut self) -> miette::Result<ModuleSet> { |
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.
pub async fn show_modules(&mut self) -> miette::Result<ModuleSet> { | |
pub fn show_modules(&mut self) -> miette::Result<ModuleSet> { |
Can be synchronous.
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 think this async
is still necessary. There's a .await
in this function
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.
Looks good. I spotted a couple methods that can be made non-async
, but after that we can merge.
This change does not borrow-check but this is to show the first step of this refactor which is to remove the process and the corresponding event channel.
The overall approach I took was to give the `Ghci` struct ownership of the `stdout` value and have all of the `GhciStdin` methods that need it borrow it mutably. This makes the `GhciStdin` methods more verbose (they now need an explicit `stdout` parameter which needs to be threaded throughout), but the long-term goal is that this will be a net simplification when we can get rid of the sender/receiver channels completely.
This is where the major compression kicks in. Now that we don't have separate processes we can remove the use of `Sender`s for passing the result and pass it directly using Rust's built-in support for `async` chaining.
46837ae
to
4cd9f78
Compare
… as caught by @9999years
The main motivation for this change was to remove
Sender
-based result-passing in favor of passing values directly through return values. However, in order to do this I had to remove the subprocesses that were managingGhciStdout
andGhciStderr
.The basic approach I used to make this work and appease the borrow-checker was:
Ghci
struct own all three ofstdin
/stdout
/stderr
I think there's actually a better way to do this that doesn't require as much parameter passing, which is to move the methods on
GhciStdin
/GhciStdout
/GhciStderr
to become methods onGhci
, but I'll save that for a separate refactor since this change was already starting to get a big large. I picked this approach for my first pass since it led to the smallest diff for ease of review.Then once I finished that refactor I was able get rid of all the
Sender
-related logic and instead pass the results that would have normally been passed viaSender
s via the function's return value instead. If you squint you can sort of think of this as analogous to converting code from "continuation-passing style" to "direct style".The only
Sender
I didn't get rid of wasSyncSentinel
since I'm trying to keep this PR focused on justGhci{Stdin,Stdout,Stderr}
.