Skip to content
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 Senders #49

Merged
merged 6 commits into from
Aug 29, 2023
Merged

Conversation

Gabriella439
Copy link
Contributor

@Gabriella439 Gabriella439 commented Aug 25, 2023

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 managing GhciStdout and GhciStderr.

The basic approach I used to make this work and appease the borrow-checker was:

  • Make the Ghci struct own all three of stdin/stdout/stderr
  • Any method that required more than one of them would borrow the other ones it was missing

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 on Ghci, 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 via Senders 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 was SyncSentinel since I'm trying to keep this PR focused on just Ghci{Stdin,Stdout,Stderr}.

@github-actions github-actions bot added the patch Bug fixes or non-functional changes label Aug 25, 2023
src/ghci/stderr.rs Outdated Show resolved Hide resolved
@Gabriella439 Gabriella439 changed the title Fewer processes and (almost) no Senders Fewer processes and Senders Aug 28, 2023
src/ghci/stdout.rs Outdated Show resolved Hide resolved
@@ -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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub async fn show_modules(&mut self) -> miette::Result<ModuleSet> {
pub fn show_modules(&mut self) -> miette::Result<ModuleSet> {

Can be synchronous.

Copy link
Contributor Author

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

Copy link
Member

@9999years 9999years left a 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.
@Gabriella439 Gabriella439 enabled auto-merge (squash) August 28, 2023 23:45
@Gabriella439 Gabriella439 merged commit e704f0b into main Aug 29, 2023
15 checks passed
@Gabriella439 Gabriella439 deleted the gabriella/no_stdout_process_2 branch August 29, 2023 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Bug fixes or non-functional changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants