Repository navigation
feat: add MI_NO_PROCESS_DETACH (skip automatic mi_process_done at exit) - #284
Merged
Merged
Conversation
Bun parity P3 (issue #268). Ports Bun's MI_NO_PROCESS_DETACH: a CMake option, an early return in _mi_auto_process_done (src/init.c) so nothing runs from the automatic exit path, and a #ifndef-guarded destructor registration (src/prim/prim.c) so the destructor is never installed at all. All three hunks carry "imported from oven-sh/mimalloc @ 942b8342, MIT" provenance. Confirmed the Windows DllMain/TLS-callback and atexit exit paths (src/prim/windows/prim.c) all funnel through _mi_auto_process_done, so the init.c early return covers them too. Documented in include/mimalloc/profile.h and README that MIMALLOC_PROF_DUMP_AT_EXIT/DHAT dump-at-exit are consequently skipped as well -- an embedder using MI_NO_PROCESS_DETACH must call mi_prof_dump/mi_dhat_dump itself. test/test-no-process-detach.c is built twice (with and without the define, against a dedicated mimalloc-static-no-detach target) and checked for opposite outcomes on the MIMALLOC_VERBOSE=1 "process done" line. The issue originally scoped this via ctest's PASS_REGULAR_EXPRESSION/FAIL_REGULAR_EXPRESSION, but those have no bundle equivalent and the #277 bundle-roundtrip c-unit gate refuses them outright -- generalized the existing run-negative.cmake `cmake -P` harness pattern into test/run-text-check.cmake (MODE=REQUIRE|FORBID, the zero-exit mirror of run-negative.cmake's non-zero-exit contract) instead, with a matching forbid_text field through ci/bundle_tests.py and ci/run_test_bundle.py plus unit test coverage. See the evidence comment on #268 for the bundle_tests.py error this fixes. MIMALLOC_FORKS.md pass-3 row updated to IMPORTED (#268). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…S_DETACH
Trailing rust-only commit (CLAUDE.md rule 2): src/init.c and src/prim/prim.c
changed in the previous commit, so amalgamate-c/amalgamate-h regenerate
rust/mimalloc-pprof/vendor/mimalloc-pprof-amalgamated.{c,h}. cargo run -p
xtask -- check confirms the vendor tree matches, and cargo test -p
mimalloc-pprof passes.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
…ption Opus review of PR #284 (blocking): with -DMI_NO_PROCESS_DETACH=ON, mi_defines already carries MI_NO_PROCESS_DETACH=1 into mimalloc-static itself, so mimalloc-test-no-process-detach (the REQUIRE/positive control) linked against mimalloc-static never prints "process done" and fails by construction. No c-unit job sets the option, which is why CI stayed green. Guard the REQUIRE half with `NOT MI_NO_PROCESS_DETACH` so it is skipped (mimalloc-static is not detach-enabled to test against) rather than failing for the wrong reason; the FORBID half (its own always-detach-enabled mimalloc-static-no-detach) keeps running unconditionally. Also switched mimalloc-static-no-detach to build from src/static.c (single TU) instead of the full source list -- the exact Bun-consumer compile shape this issue's acceptance check already exercises. Verified: Release without the option (both tests PASS), Release with -DMI_NO_PROCESS_DETACH=ON (only test-no-process-detach-skipped registered, PASS), and MI_PPROF=OFF with the option (same, PASS). Nits: include/mimalloc/dhat.h now carries the MI_NO_PROCESS_DETACH / MIMALLOC_DHAT_DUMP_AT_EXIT interaction note profile.h already referenced but dhat.h itself lacked; README's DHAT section gets the same dump-at-exit warning the PROF section already has. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
Trailing rust-only commit (CLAUDE.md rule 2): include/mimalloc/dhat.h changed
in the previous commit (MI_NO_PROCESS_DETACH interaction note), so
amalgamate-c/amalgamate-h regenerate rust/mimalloc-pprof/vendor/mimalloc-pprof-amalgamated.{c,h}
(dhat.h is inlined into both). cargo run -p xtask -- check confirms the
vendor tree matches, and cargo test -p mimalloc-pprof passes.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
Owner
Author
|
Opus review: APPROVE after the CMake guard fix ( |
9 tasks
zackees
added a commit
that referenced
this pull request
Sep 2, 2026
Issue #274 (Bun parity P9b). docs/bun-gap-analysis-2026-09-02.md re-runs the 2026-09-01 analysis's four checks against Bun's current pin: the scripts/build/deps/mimalloc.ts commit (942b8342) has not moved, and all five consumer files (mimalloc_sys.rs, MimallocArena.rs, MimallocWTFMalloc.h, BunJSCModule.h, heapStats-mimalloc.test.ts) are byte-identical to what was cached in that session -- no new gap exists at Bun's current pin, so no new sub-issue is filed. The rest of the doc is a status table for every item and gap ID (B1-B20) from the 2026-09-01 analysis against what has actually merged since (#276, #281, #284, #286, #289, #291, #297) versus what's still open (#299, #302, and the items tied to them): 7/9 required-before-pitch items done, 11/20 B-numbered gaps done, 1 partial, 0 new. docs/ci-gates.md gains a `bun-surface` row and a short section explaining why that CI job is temporarily continue-on-error (mi_on_thread_idle isn't on main yet) with a dated TODO for when to make it a hard gate. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bun parity P3 (Closes #268, sub-issue of #264). Ports Bun's
MI_NO_PROCESS_DETACH(
oven-sh/mimalloc@942b8342, MIT): a CMake option, an early return in_mi_auto_process_done(src/init.c), and a#ifndef-guarded destructorregistration (
src/prim/prim.c). All three ported hunks carry provenance comments.DllMain/TLS-callback andatexitexit paths(
src/prim/windows/prim.c) all funnel through_mi_auto_process_done, so theinit.cearly return covers Windows too.include/mimalloc/profile.hand the README thatMIMALLOC_PROF_DUMP_AT_EXIT/DHAT dump-at-exit are consequently also skipped —an embedder using
MI_NO_PROCESS_DETACHmust callmi_prof_dump/mi_dhat_dumpitself.
MIMALLOC_FORKS.mdpass-3 row updated to IMPORTED (Bun parity P3: add MI_NO_PROCESS_DETACH #268).c++ -x c++ -std=c++17 -c src/static.c -Iinclude -DMI_STATIC_LIB -DMI_NO_PROCESS_DETACH=1 -DMI_SKIP_COLLECT_ON_EXIT=1compiles clean, and
nm -C | grep mi_process_detachis empty.Deviation from the issue's test plan (rule 7, evidence-first)
The issue's step 3 said "a CMake
add_testwithPASS_REGULAR_EXPRESSION/FAIL_REGULAR_EXPRESSIONis enough" — that doesn't survive the#277bundlegate, which is part of the required
c-unitmerge gates:Fix: generalized the existing
test/run-negative.cmakecmake -Pharnesspattern (already lowered by the bundler) into a new
test/run-text-check.cmake(
MODE=REQUIRE|FORBID, the zero-exit mirror ofrun-negative.cmake'snon-zero-exit contract), plus a matching
forbid_textfield throughci/bundle_tests.py/ci/run_test_bundle.pywith unit test coverage. Postedas a comment on #268 with the same evidence.
test/test-no-process-detach.cis built twice — once against the normalstatic lib, once against a dedicated
mimalloc-static-no-detachtargetcompiled with
MI_NO_PROCESS_DETACH=1— and both are checked against oppositeexpectations on the
MIMALLOC_VERBOSE=1"process done" line.Test plan
uv run ci/verify_local.py --keep-going:MI_TRACK_ASAN did not survive configure(no ASan runtime installed in this dev container; unrelated to this change)ctest -R test-no-process-detach: bothtest-no-process-detach-runsandtest-no-process-detach-skippedPASS.cargo run -p xtask -- checkandcargo test -p mimalloc-pprof: pass.Notes for reviewers
src/init.c/src/prim/prim.c/CMakeLists.txt/test/*are in one commit;the
rust/mimalloc-pprof/vendor/*amalgamation regeneration is a separatetrailing commit (rule 2).
/WXis not set anywhere inCMakeLists.txttoday, so the now-unreachable tail of_mi_auto_process_doneunderMI_NO_PROCESS_DETACH(C4702) should not faila Windows build — but this wasn't testable on this Linux dev box, so flag if
the win-msvc job surfaces it.
Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S
🤖 Generated with Claude Code
https://claude.ai/code/session_01YT4jVokb2gdT8ngFrH8i8S