Skip to content

fix(moonrun): use the shared null handle - #2222

Merged
peter-jerry-ye merged 1 commit into
moonbitlang:mainfrom
peter-jerry-ye:codex/moonrun-async-null-conventions
Sep 17, 2026
Merged

peter-jerry-ye merged 1 commit into
moonbitlang:mainfrom
peter-jerry-ye:codex/moonrun-async-null-conventions

Conversation

@peter-jerry-ye

@peter-jerry-ye peter-jerry-ye commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Async used literal zero for null buffers and address-info results even though these values are encoded slotmap keys. Optional process and stdio arguments also accepted zero alongside the reserved invalid Resource, mixing two different absence conventions.

Use the existing runtime null Handle, derived from HostKey::null(), for nullable buffers, core executable-path results, TLS buffer results, address-info terminators, and null-accepting cleanup. Slotmap guarantees that this key cannot identify a live entry. Update the matching null predicates and remove INVALID_HOST_HANDLE. Optional Resources accept the sentinel returned by invalid_fd(); other values undergo ordinary validation. Buffer leasing uses its owning table's validation directly.

Nullable Handle values change, while import signatures stay the same. The supplied buffer and address-info wrappers recognize null through host predicates. TLS connection creation returns a live pending object, and setup reports initialization failures through a status and the object's error message. TLS cleanup rejects zero with Badf; the shared null Handle remains a no-op. This deliberately stops accepting literal zero as an alias for null cleanup or absent Resources.

The companion guest cleanup in moonbitlang/async#611 removes the redundant TLS connection null checks. Existing wrappers work with this host change because connection creation returns a live Handle. Merge this Moonrun change before the companion cleanup. The async submodule update remains separate.

Regression tests cover null production, predicates, cleanup, address-info termination, and core path errors, plus rejected zero, wrong-family, and stale Resource Handles. An import-level test verifies that freeing a zero TLS Handle reports Badf on both engines. The developer guide distinguishes the unallocated null key from the live reserved invalid Resource. Further table migrations remain separate.

@semanticdiff-com

semanticdiff-com Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/moonrun/src/async_api/c_buffer.rs  67% smaller
  crates/moonrun/src/runtime/mod.rs  25% smaller
  crates/moonrun/src/async_host/mod.rs  12% smaller
  crates/moonrun/src/async_api/socket.rs  9% smaller
  crates/moonrun/src/async_api/thread_pool.rs  2% smaller
  crates/moonrun/src/async_api/process.rs  2% smaller
  crates/moonrun/tests/engine_backends.rs  2% smaller
  crates/moonrun/CONTEXT.md Unsupported file format
  crates/moonrun/docs/dev/host-handles.md Unsupported file format
  crates/moonrun/src/core_api.rs  0% smaller

@peter-jerry-ye
peter-jerry-ye force-pushed the codex/moonrun-async-null-conventions branch from 0c151dc to 11cf074 Compare September 17, 2026 03:51
@peter-jerry-ye peter-jerry-ye changed the title fix(moonrun): distinguish resource absence from ABI null fix(moonrun): use the shared null handle Sep 17, 2026
@peter-jerry-ye
peter-jerry-ye force-pushed the codex/moonrun-async-null-conventions branch from 11cf074 to 36d5689 Compare September 17, 2026 05:50
@peter-jerry-ye
peter-jerry-ye merged commit 3c4d7c3 into moonbitlang:main Sep 17, 2026
16 checks passed
@peter-jerry-ye
peter-jerry-ye deleted the codex/moonrun-async-null-conventions branch September 17, 2026 07:09
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