Conversation
This comment was marked as outdated.
This comment was marked as outdated.
4938422 to
170b02a
Compare
|
/bigbonk roast this pr |
This comment was marked as outdated.
This comment was marked as outdated.
ba7b471 to
8a6f84a
Compare
|
/bigbonk roast this pr |
This comment has been minimized.
This comment has been minimized.
57bfc1c to
1d356e2
Compare
This comment has been minimized.
This comment has been minimized.
1d356e2 to
1525e8e
Compare
|
/bigbonk roast this pr |
This comment was marked as outdated.
This comment was marked as outdated.
d64dc80 to
2a09295
Compare
2a09295 to
ec26bc5
Compare
|
/bigbonk roast this pr |
|
@anonrig Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
ec26bc5 to
9dbfffd
Compare
|
/bigbonk roast this pr |
There was a problem hiding this comment.
Review Update
Re-reviewing after a thorough read of the full diff. My earlier review (review #3905780686) had several incorrect findings that I want to correct, plus new findings from this deeper pass.
Corrections to prior review
- Issue #1 (was High):
unwrap/unwrap_refnull handling — This was already correctly handled.WrappableRc::from_js()atv8.rs:1580returnsOption<Self>and checkshandle.get().is_null(). Bothunwrapandunwrap_refpropagateNonevia?. Apologies for the false alarm. - Issue #2 (was Medium): Docstring mismatch — Fixed. The docstring and signature now both describe
Option<Self>. - Issue #3 (was Medium):
WeakRef::get()safety — No longer applicable. Theget()method was removed; the API now usesupgrade() -> Option<Ref<R>>which is sound. - Issue #5 (was Low):
todo!()in proc macro — Fixed. Now uses propersyn::Erroratlib.rs:389-393.
New findings below (posted as inline comments)
This review was generated by an AI assistant and may contain inaccuracies.
| @@ -0,0 +1,265 @@ | |||
| use std::cell::Cell; | |||
There was a problem hiding this comment.
[MEDIUM] Missing copyright header on new file.
This file is new in this PR but is missing the project copyright/license header. Per the review checklist, every new .rs file must begin with:
// Copyright (c) 2026 Cloudflare, Inc.
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
// https://opensource.org/licenses/Apache-2.0
Same applies to gc.rs and resource_conversion.rs.
| } | ||
| .expect("wrappable data already cleared"); | ||
| // data[0] is Rc::into_raw(*const R) — points directly to R. | ||
| trait_ptr.data.cast::<R>() |
There was a problem hiding this comment.
[MEDIUM] resolve_resource performs an unchecked type cast.
trait_ptr.data.cast::<R>() reinterprets the Rc::into_raw pointer as R with no runtime verification that the Wrappable actually holds type R. The C++ side only checks WORKERD_RUST_WRAPPABLE_TAG (confirming "this is a Rust object") but doesn't verify which specific Rust type it holds.
The safety contract ("caller must ensure the type R matches") is upheld by the proc-macro-generated code, but this is a one-line type confusion away from silent memory corruption. Consider storing a TypeId in an additional data slot and adding a debug_assert! check:
debug_assert_eq!(
stored_type_id,
TypeId::of::<R>(),
"type mismatch in resolve_resource"
);This would catch type confusion bugs during development/testing with zero cost in release builds.
| reason = "Pin<&mut> comes from a raw pointer, not from &self" | ||
| )] | ||
| unsafe fn as_pin_mut(&self) -> Pin<&mut ffi::Wrappable> { | ||
| unsafe { Pin::new_unchecked(&mut *self.handle.get().cast_mut()) } |
There was a problem hiding this comment.
[LOW] as_pin_mut safety comment could be strengthened.
Invariant #3 ("Non-reentrant FFI") is not entirely accurate: wrappable_visit_ref at ffi.c++:454 calls wrappable.visitRef(*gcVisitor, parentMaybe, *ref_strong), which traces child Wrappables, which calls wrappable_invoke_trace, which calls back into Rust's GarbageCollected::trace(). However, the re-entry creates a Pin<&mut Wrappable> for a different Wrappable (the child), not the same one, so the &mut uniqueness invariant holds.
Consider clarifying the comment to say: "C++ methods may re-enter Rust for different Wrappables during tracing, but never create a second Pin<&mut Wrappable> for the same object."
|
|
||
| ### `WeakRef<R>` | ||
|
|
||
| Weak reference that doesn't prevent GC collection. Use `upgrade()` to get a `Ref<R>` if the resource is still alive, or `get()` for a temporary `&R`. |
There was a problem hiding this comment.
[LOW] Stale API reference.
get() is mentioned here but WeakRef only exposes upgrade() and is_alive() — there is no get() method.
| Weak reference that doesn't prevent GC collection. Use `upgrade()` to get a `Ref<R>` if the resource is still alive, or `get()` for a temporary `&R`. | |
| Weak reference that doesn't prevent GC collection. Use `upgrade()` to get a `Ref<R>` if the resource is still alive. |
|
Review posted successfully. Here's a summary of what was posted: Corrections to prior review:
New findings (5 inline comments):
|
Adds gc support to Rust owned objects using the existing GC implementation, rather than using cppgc heap, which the draft implementation used: #5638.