Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/socket-patch-cli/src/ecosystem_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,10 @@ impl JvmScope {
/// temporary in that fn's poll frame first, and a debug build keeps the
/// room for it. Here the temporary is in a frame that is gone before
/// anything is polled: never inlined, or it would be the caller's again.
///
/// The core crate has the same helper for the patch engines
/// (`patch::apply::boxed`), with a `Send` bound this one does not need;
/// keep the two in step.
#[inline(never)]
pub(crate) fn boxed<'a, T, F, Fut>(
make: F,
Expand Down
32 changes: 31 additions & 1 deletion crates/socket-patch-core/src/patch/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,32 @@ struct FileOp {
saved: Option<PathBuf>,
}

/// Box the future `make` returns, built in this (non-async) frame so that
/// the caller's poll frame holds only the pointer.
///
/// A debug build keeps room in an `async fn`'s poll frame for every future
/// it awaits inline, in every branch, and `Box::pin(big(..))` written there
/// builds the future in that frame first. The patch engines sit deep in the
/// call chain of `apply`, `rollback` and `remove`, and the whole chain has
/// to fit the stack of the thread it runs on (2 MiB for a test's). Here the
/// temporary is in a frame that is gone before anything is polled: never
/// inlined, or it would be the caller's again.
///
/// The CLI has the same helper for its command frames
/// (`ecosystem_dispatch::boxed`), without the `Send` bound: this one keeps
/// the engines' futures `Send`, as they were before they were boxed. Keep
/// the two in step.
#[inline(never)]
pub(crate) fn boxed<'a, T, F, Fut>(
make: F,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = T> + Send + 'a>>
where
F: FnOnce() -> Fut,
Fut: std::future::Future<Output = T> + Send + 'a,
{
Box::pin(make())
}

/// The sibling name an original is kept under during a [`PackageWrite`].
const SAVED_PREFIX: &str = ".socket-orig-";

Expand Down Expand Up @@ -1516,8 +1542,12 @@ pub async fn apply_package_patch(
dry_run: bool,
policy: MismatchPolicy,
) -> ApplyResult {
// One copy's engine runs behind a pointer: its future is the largest
// of the chain, and every caller up to the command would otherwise
// hold room for it in its own poll frame (see `boxed`).
crate::patch::store_copies::fan_out(scope, package_key, pkg_path, |path| async move {
apply_package_patch_at(scope, package_key, &path, files, sources, dry_run, policy).await
boxed(|| apply_package_patch_at(scope, package_key, &path, files, sources, dry_run, policy))
.await
})
.await
}
Expand Down
13 changes: 10 additions & 3 deletions crates/socket-patch-core/src/patch/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,13 @@ pub async fn rollback_package_patch(
blobs_path: &Path,
dry_run: bool,
) -> RollbackResult {
// One copy's engine runs behind a pointer, as apply's does (see
// `apply::boxed`).
crate::patch::store_copies::fan_out(scope, package_key, pkg_path, |path| async move {
rollback_package_patch_at(scope, package_key, &path, files, blobs_path, dry_run).await
crate::patch::apply::boxed(|| {
rollback_package_patch_at(scope, package_key, &path, files, blobs_path, dry_run)
})
.await
})
.await
}
Expand Down Expand Up @@ -432,8 +437,10 @@ pub async fn rollback_store_copies_holding_patch(
if !holds_this_patch(&copy, files).await {
continue;
}
let copy_result =
rollback_package_patch_at(scope, package_key, &copy, files, blobs_path, dry_run).await;
let copy_result = crate::patch::apply::boxed(|| {
rollback_package_patch_at(scope, package_key, &copy, files, blobs_path, dry_run)
})
.await;
let result = folded.get_or_insert_with(|| RollbackResult {
package_key: package_key.to_string(),
package_path: pkg_path.display().to_string(),
Expand Down
Loading