Repository navigation
hot: keep the entry-point promise alive while the reload loop polls it #41146
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
583df13
Keep the entry-point promise alive while the hot-reload loop polls it
robobun 163da1f
Store the entry-point promise in a WriteBarrier on the global object
robobun fb78b9d
Trim the comments around the entry-point promise slot
robobun 614df8c
Merge remote-tracking branch 'origin/main' into robobun/6fc7ba56/entr…
robobun 3a0de54
Test that bun test prints a build error when a GC runs before the report
robobun 281bcbd
Merge remote-tracking branch 'origin/main' into robobun/69f196b1/root…
robobun b0f0f08
Remove the entry-point promise slot from Zig::GlobalObject
robobun 6964fa4
hot: root the entry-point promise on VirtualMachine
mq1n 449404e
Run the handled-rejection test for 20 boots and allow the debug reloa…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -708,8 +708,8 @@ unsafe fn load_preloads(vm: *mut VirtualMachine) -> bun_jsc::CrateResult<*mut JS | |
| // SAFETY: per fn contract — `vm` is the live per-thread VM. | ||
| unsafe { (*vm).is_in_preload = true }; | ||
| // Note: copy the raw ptr into a guard-owned local so the defer body | ||
| // doesn't borrow the fn param — later `(*vm).pending_internal_promise = …` | ||
| // would otherwise alias the guard's capture. | ||
| // doesn't borrow the fn param — later mutable VM access would otherwise | ||
| // alias the guard's capture. | ||
|
Comment on lines
+711
to
+712
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code |
||
| let vm_for_guard = vm; | ||
| scopeguard::defer! { | ||
| // SAFETY: per fn contract. | ||
|
|
@@ -820,7 +820,7 @@ unsafe fn load_preloads(vm: *mut VirtualMachine) -> bun_jsc::CrateResult<*mut JS | |
| }; | ||
|
|
||
| // SAFETY: per fn contract. | ||
| unsafe { (*vm).pending_internal_promise = Some(promise) }; | ||
| unsafe { (*vm).set_pending_internal_promise(promise) }; | ||
| let _protected = JSValue::from_cell(promise).protected(); | ||
|
|
||
| // ── wait ──────────────────────────────────────────────────────── | ||
|
|
@@ -837,16 +837,20 @@ unsafe fn load_preloads(vm: *mut VirtualMachine) -> bun_jsc::CrateResult<*mut JS | |
| // SAFETY: `pending_internal_promise` was set just above (or | ||
| // swapped by HMR to another live cell); `status()` is a | ||
| // read-only FFI call on a live JSC heap cell. | ||
| let pip = unsafe { &*vm }.pending_internal_promise.unwrap_or(promise); | ||
| let pip = unsafe { &*vm } | ||
| .pending_internal_promise() | ||
| .unwrap_or(promise); | ||
| // SAFETY: `pip` is a live JSC heap cell (set just above or | ||
| // the protected `promise` fallback). | ||
| // the `_protected` promise fallback). | ||
| if unsafe { &*pip }.status() != PromiseStatus::Pending { | ||
| break; | ||
| } | ||
| // SAFETY: `el` is the live per-thread event loop. | ||
| unsafe { (*el).tick() }; | ||
| // SAFETY: per fn contract — `vm` is the live per-thread VM. | ||
| let pip = unsafe { &*vm }.pending_internal_promise.unwrap_or(promise); | ||
| let pip = unsafe { &*vm } | ||
| .pending_internal_promise() | ||
| .unwrap_or(promise); | ||
| // SAFETY: `pip` is a live JSC heap cell (see above). | ||
| if unsafe { &*pip }.status() == PromiseStatus::Pending { | ||
| // SAFETY: per fn contract — short-lived `&mut *vm` for the | ||
|
|
@@ -862,7 +866,8 @@ unsafe fn load_preloads(vm: *mut VirtualMachine) -> bun_jsc::CrateResult<*mut JS | |
| } | ||
| } | ||
|
|
||
| // SAFETY: `promise` is a live (still-protected) JSC heap cell. | ||
| // SAFETY: `promise` is rooted by `_protected` even if HMR swapped the | ||
| // VM's pending-entry slot while the loop ran. | ||
| if unsafe { &*promise }.status() == PromiseStatus::Rejected { | ||
| return Ok(promise); | ||
| } | ||
|
|
@@ -872,7 +877,7 @@ unsafe fn load_preloads(vm: *mut VirtualMachine) -> bun_jsc::CrateResult<*mut JS | |
| if !unsafe { &*vm }.script_allowed() { | ||
| return Ok(core::ptr::null_mut()); | ||
| } | ||
| // `_protected` drops here → unprotect. | ||
| // `_protected` drops here. | ||
| } | ||
|
|
||
| // Under --isolate each test file gets | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need a paragraph-long comment to justify why the workaround is OK, the code is wrong — fix the code