Skip to content

Add ExecutionContext: cancellation + progress for boolean evaluation#41

Merged
zmerlynn merged 1 commit into
mainfrom
add-execution-context
May 3, 2026
Merged

Add ExecutionContext: cancellation + progress for boolean evaluation#41
zmerlynn merged 1 commit into
mainfrom
add-execution-context

Conversation

@zmerlynn

@zmerlynn zmerlynn commented May 3, 2026

Copy link
Copy Markdown
Owner

Binds upstream's `ManifoldExecutionContext` (added post-v3.4.1, available on wasm-uu since shim v0.4.0-alpha.1 in #40). Lets another thread cancel a long-running boolean evaluation or observe its progress.

Surface (manifold-csg): `ExecutionContext::{new, cancel, is_cancelled, progress}` (`Send + Sync` per upstream's "safe to read/write from any thread" guarantee) + `Manifold::status_with_context(&ExecutionContext)` to trigger cancellable evaluation. `API_COVERAGE.md` updated.

Re upstream #1674 (within-phase cancel refactor): zero `bindings/c/` files touched, so our bindings stay accurate.

Versions stay at 0.1.8 / 3.4.107 (additive on top of #40's pre-bump).

Test plan

  • 219 host tests pass (was 214; +5 new)
  • wasm-uu build clean, produced wasm has zero unexpected imports
  • fmt + clippy clean
  • CI green

Binds the upstream `ManifoldExecutionContext` C API surface added in
manifold's master post-v3.4.1 (`5f95a3a`) and now natively supported in
the wasm-uu lane via shim v0.4.0-alpha.1 (PR #40).

Why it matters: manifold operations are lazy. Building a CSG tree is
cheap; the actual evaluation runs when something queries the result
(num_tri, mesh extraction, status). For nontrivial trees this can be
seconds to minutes, and there was previously no way to cooperatively
abort it. ExecutionContext fixes that — pass it to a new
`status_with_context` method and another thread can `cancel()` it.

Use case examples:
- Web demos / interactive UIs: cancel a stale boolean when the user
  changes inputs.
- Server-side: timeout long-running ops without dropping the worker.
- Batch processing: progress observation for status reporting.

C API surface added (10 items in manifold-csg-sys):
- `ManifoldExecutionContext` opaque type
- 4 lifecycle: `_size`, `_alloc`, `_destruct`, `_delete`
- 1 constructor: `manifold_execution_context(mem)`
- 3 control: `_cancel`, `_cancelled`, `_progress`
- 1 cancellable trigger: `manifold_status_with_context`

Safe wrapper (manifold-csg):
- New `execution` module with `ExecutionContext` struct (`Send + Sync`,
  justified by upstream's "safe to read/write from any thread" guarantee
  in the C header).
- Methods: `new()`, `cancel()`, `is_cancelled()`, `progress()`, `Drop`.
- `Manifold::status_with_context(&self, &ExecutionContext) -> ManifoldError`
  for the cancellable evaluation trigger.
- 5 integration tests: initial state, sticky cancel, cross-thread
  cancel via Arc, status_with_context happy path, status_with_context
  with already-cancelled context.
- API_COVERAGE.md updated with a new "Execution Context" section.

Verified end-to-end:
- 219 host integration tests pass (was 214; +5 new ExecutionContext)
- wasm-uu CI-equivalent build clean; produced wasm has zero unexpected
  imports (confirms ExecutionContext links cleanly through the shim's
  v0.4.0-alpha.1 helper)
- cargo fmt + cargo clippy clean

Versions stay at 0.1.8 / 3.4.107 (pre-bumped by #40, this addition is
additive so the bump still covers it).
@zmerlynn zmerlynn force-pushed the add-execution-context branch from bd158f0 to e3af8c7 Compare May 3, 2026 16:15
@zmerlynn zmerlynn merged commit fe18df1 into main May 3, 2026
12 checks passed
@zmerlynn zmerlynn deleted the add-execution-context branch May 3, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant