[oscars-integration] Thread MutationContext through buitlin standard library objects - #5479
Conversation
310be44 to
f2ddfe2
Compare
There was a problem hiding this comment.
🟡 Changes recommended
There are multiple verified compilation/logic issues in the new MutationContext threading (notably several &&MutationContext argument mismatches and an incorrect in_with value in JSON compilation).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR continues the oscars GC integration by threading a MutationContext/GC allocator handle through engine initialization, compilation, runtime environments, and several builtin/object construction paths, while adding an oscars_backend feature surface to boa_gc and boa_string.
Changes:
- Introduces
boa_gc::GcContextand exposes it onContext(Context::alloc,Context::gc_collector) to centralize GC allocations and collector access. - Threads
MutationContextthrough bytecode compilation (ByteCompiler,FunctionCompiler) and multiple VM/module/script/builtin code paths, replacing manyMutationContext::dummy()call sites. - Adds
oscars_backendfeature wiring across crates (GC/string/engine), plus supporting glue (dummy/leaky WeakMap,Trace/Finalizeadjustments, workflow branch triggers).
File summaries
| File | Description |
|---|---|
| tests/macros/tests/gcd_callback.rs | Updates test to use MutationContext::global() and adjusts lint allowances. |
| tests/fuzz/Cargo.toml | Adds a patch override for boa_string when running fuzzing workspace standalone. |
| examples/src/bin/jstypedarray.rs | Updates example to use MutationContext::global() bridge. |
| examples/src/bin/derive.rs | Adds crate-level lint allowance. |
| core/string/src/tests.rs | Replaces assert!(.. == ..) with assert_eq! in builder tests. |
| core/string/src/lib.rs | Adds oscars_backend Trace/Finalize impls for JsString. |
| core/string/src/builder.rs | Refactors match-arm formatting and adds clippy allows in latin1 conversion path. |
| core/string/Cargo.toml | Adds optional oscars dependency and oscars_backend feature. |
| core/runtime/src/test262.rs | Adjusts downcast/clone flow for SharedArrayBuffer to match new borrow semantics. |
| core/runtime/src/microtask/tests.rs | Updates log cloning to deref through guard before cloning. |
| core/runtime/src/console/tests.rs | Updates log cloning + loosens table header substring assertions for output differences. |
| core/runtime/src/abort/mod.rs | Updates borrow/clone pattern for oscars backend guard types. |
| core/macros/src/lib.rs | Refactors derive_trace to avoid mutable-by-value argument and adjust implementation generation. |
| core/interner/src/sym.rs | Switches Sym to derive Trace and uses #[unsafe_ignore_trace] field attribute. |
| core/gc/src/trace.rs | Wraps custom_trace! bodies in unsafe {} blocks to satisfy unsafe-op linting. |
| core/gc/src/test/weak.rs | Updates Gc type annotation in size-of test for branded lifetime. |
| core/gc/src/pointers/weak_map.rs | Adds WeakMap::get_value convenience accessor. |
| core/gc/src/pointers/mutation_context.rs | Makes dummy() const and adds global() alias constructor. |
| core/gc/src/oscars_weak_map.rs | Adds dummy/leaky WeakMap for oscars_backend. |
| core/gc/src/lib.rs | Adds oscars backend re-exports, tracing macros, GcContext, and feature gating adjustments. |
| core/gc/src/context.rs | Introduces GcContext with collector access and allocation helper methods. |
| core/gc/src/cell.rs | Converts assertions to assert_eq!/assert_ne! for clearer diagnostics. |
| core/gc/Cargo.toml | Reworks feature flags for oscars backend and propagates feature flags to dependencies. |
| core/engine/src/vm/tests.rs | Disables a GC stress test under oscars_backend. |
| core/engine/src/vm/opcode/push/environment.rs | Threads GC allocator usage through env ops and replaces dummy allocations with context.alloc. |
| core/engine/src/vm/opcode/function.rs | Adds explicit type in closure to satisfy inference under new backend types. |
| core/engine/src/vm/opcode/await/mod.rs | Replaces dummy allocations with context.alloc and fixes capture cloning. |
| core/engine/src/vm/mod.rs | Makes Vm::new require a MutationContext to allocate initial codeblock. |
| core/engine/src/vm/inline_cache/mod.rs | Adds explicit Shape binding to satisfy type inference. |
| core/engine/src/vm/code_block.rs | Adds clippy allow for clone_on_copy. |
| core/engine/src/value/integer.rs | Converts equality assertions to assert_eq!/assert_ne!. |
| core/engine/src/value/inner/nan_boxed.rs | Adjusts raw pointer handling and imports for oscars backend compatibility. |
| core/engine/src/value/inner/legacy.rs | Refactors custom_trace! match to avoid matching on &this. |
| core/engine/src/value/equality.rs | Converts debug assert to debug_assert_eq!. |
| core/engine/src/script.rs | Switches script inner allocations to context.alloc and threads MutationContext into compilation. |
| core/engine/src/realm.rs | Requires MutationContext for realm creation and allocations. |
| core/engine/src/object/shape/unique_shape.rs | Adds _in variants and threads MutationContext through shape/weak-shape operations. |
| core/engine/src/object/shape/shared_shape/template.rs | Adds _in variants for template shape transitions and object creation. |
| core/engine/src/object/shape/shared_shape/mod.rs | Adds _in transition APIs and threads MutationContext through transitions/weak upgrades. |
| core/engine/src/object/shape/shared_shape/forward_transition.rs | Adds _in insertion helpers and updates weak allocation to use provided context. |
| core/engine/src/object/shape/root_shape.rs | Adds RootShape::new_in and routes default construction through global context. |
| core/engine/src/object/shape/mod.rs | Adds _in variants for transitions and routes old APIs through global context. |
| core/engine/src/object/mod.rs | Documents TypeId usage differences under oscars backend. |
| core/engine/src/object/jsobject.rs | Adds _in constructors and changes raw pointer APIs to untyped *const () for backend compatibility. |
| core/engine/src/object/builtins/jsweakset.rs | Uses context.gc_collector() to initialize weak set backing store. |
| core/engine/src/object/builtins/jsweakmap.rs | Uses context.gc_collector() to initialize weak map backing store. |
| core/engine/src/object/builtins/jstypedarray.rs | Updates doc example to use context.alloc. |
| core/engine/src/object/builtins/jspromise.rs | Uses context.alloc for state allocation; makes JsFuture cloneable. |
| core/engine/src/object/builtins/jsfunction.rs | Adds empty_intrinsic_function_in and routes old API via global context. |
| core/engine/src/native_function/mod.rs | Switches closure allocations to MutationContext::global() and adjusts downcast/clone with guard deref. |
| core/engine/src/native_function/continuation.rs | Switches coroutine allocations to MutationContext::global() and adjusts raw Gc conversions. |
| core/engine/src/module/synthetic.rs | Threads MutationContext into compilation; switches to context.alloc for codeblock allocation. |
| core/engine/src/module/source.rs | Threads MutationContext into compilation; switches to context.alloc for codeblock allocation. |
| core/engine/src/module/mod.rs | Switches module allocations and test data insertion to context.alloc; adjusts guard cloning. |
| core/engine/src/module/loader/mod.rs | Derives GC traits for module cache key used inside GC-traced structures. |
| core/engine/src/lib.rs | Adds clippy allowances expected under oscars backend (Gc becoming Copy, etc.). |
| core/engine/src/host_defined.rs | Relaxes Finalize bound on HostDefined. |
| core/engine/src/error/mod.rs | Updates downcast/clone patterns and custom_trace! match to match new backend semantics. |
| core/engine/src/environments/runtime/mod.rs | Threads MutationContext through environment stack pushes and updates allocation call sites. |
| core/engine/src/context/mod.rs | Adds Context.gc: GcContext, plus alloc/gc_collector; threads MC through realm/vm creation. |
| core/engine/src/context/intrinsics.rs | Removes Default reliance by introducing uninit(mc) constructors and threading MC through templates/constructors. |
| core/engine/src/bytecompiler/mod.rs | Adds McWrapper and stores MutationContext reference in compiler; threads it to nested compilers. |
| core/engine/src/bytecompiler/function.rs | Threads MC through FunctionCompiler::compile and uses it for codeblock allocation. |
| core/engine/src/bytecompiler/declarations.rs | Passes compiler MC into nested function compilation. |
| core/engine/src/bytecompiler/class.rs | Passes compiler MC into nested compilation and uses it for codeblock allocations. |
| core/engine/src/builtins/weak/weak_ref.rs | Uses context.gc_collector() for WeakGc operations and adjusts tests for oscars backend. |
| core/engine/src/builtins/weak_set/mod.rs | Uses context.gc_collector() and disables tests under oscars backend. |
| core/engine/src/builtins/weak_map/mod.rs | Uses context.gc_collector() + new WeakMap::get_value helper; disables tests under oscars backend. |
| core/engine/src/builtins/uri/mod.rs | Adds uninit_in(mc) and routes default via global context. |
| core/engine/src/builtins/set/ordered_set.rs | Refactors custom_trace! loop variable naming to avoid borrow issues. |
| core/engine/src/builtins/promise/mod.rs | Switches multiple allocations to context.alloc for promise state tracking. |
| core/engine/src/builtins/json/mod.rs | Threads MC into ByteCompiler creation and switches codeblock allocation to context.alloc. |
| core/engine/src/builtins/iterable/mod.rs | Adds uninit_in(mc) and routes default via global context. |
| core/engine/src/builtins/intl/locale/utils.rs | Adjusts downcast/clone to deref guard under oscars backend. |
| core/engine/src/builtins/intl/locale/mod.rs | Adjusts downcast/clone to deref guard under oscars backend. |
| core/engine/src/builtins/intl/list_format/mod.rs | Converts assert to assert_eq!. |
| core/engine/src/builtins/generator/mod.rs | Refactors custom_trace! match to avoid matching on &this. |
| core/engine/src/builtins/function/mod.rs | Threads MC into function compilation and updates environment stack calls. |
| core/engine/src/builtins/function/arguments.rs | Adjusts environment deref under oscars backend. |
| core/engine/src/builtins/finalization_registry/tests.rs | Disables miri tests under oscars backend. |
| core/engine/src/builtins/finalization_registry/mod.rs | Uses context.gc_collector() for weak refs/ephemerons and adjusts upgrade/value paths. |
| core/engine/src/builtins/eval/mod.rs | Threads MC into eval compilation and switches codeblock allocation to context.alloc. |
| core/engine/Cargo.toml | Adds oscars_backend feature mapping to GC/string crates. |
| core/engine/benches/full.rs | Updates benchmark realm creation to pass a MutationContext. |
| Cargo.toml | Adds typeid dependency and patches boa_string git source to local path. |
| Cargo.lock | Updates oscars git revision and adds new transitive deps (typeid, etc.). |
| .github/workflows/webassembly.yml | Adds dev/oscars-gc to workflow branch triggers. |
| .github/workflows/test262.yml | Adds dev/oscars-gc triggers and skips test262 job when targeting that base branch. |
| .github/workflows/rust.yml | Adds dev/oscars-gc to workflow branch triggers. |
| .github/workflows/pull_request.yml | Adds dev/oscars-gc to workflow branch triggers. |
Review details
Suppressed comments (1)
core/engine/src/module/loader/mod.rs:294
- Deriving
boa_gc::TraceforModuleCacheKeywill requirePathBufandImportAttributeto implementTrace, but there doesn't appear to be aTraceimpl for those types in the repo. Since these fields contain no GC pointers, mark them with#[unsafe_ignore_trace]so the derive doesn't requireTracebounds.
- Files reviewed: 89/90 changed files
- Comments generated: 9
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| self.push_env(Environment::Declarative(Gc::new( | ||
| &unsafe { boa_gc::MutationContext::dummy() }, | ||
| &gc, | ||
| DeclarativeEnvironment::new( |
| @@ -302,15 +303,14 @@ impl Json { | |||
| false, | |||
| false, | |||
| context.interner_mut(), | |||
| in_with, | |||
| &gc, | |||
| false, | |||
| false, | ||
| context.interner_mut(), | ||
| &mc, | ||
| false, |
| context.interner_mut(), | ||
| &mc, | ||
| false, |
| context.interner_mut(), | ||
| &mc, | ||
| false, |
| false, | ||
| context.interner_mut(), | ||
| &mc, | ||
| in_with, |
| context.realm().scope().clone(), | ||
| context.realm().scope().clone(), | ||
| function.scopes(), | ||
| function.contains_direct_eval(), | ||
| context.interner_mut(), | ||
| &mc, | ||
| ); |
| pub fn create_realm(&mut self) -> JsResult<Realm> { | ||
| let realm = Realm::create(self.host_hooks.as_ref(), &self.root_shape)?; | ||
| let realm = Realm::create(self.host_hooks.as_ref(), &self.root_shape, &unsafe { | ||
| boa_gc::MutationContext::global() | ||
| })?; |
| let ephemeron = self.get(key)?; | ||
| ephemeron | ||
| .value(&unsafe { crate::MutationContext::dummy() }) | ||
| .map(|v| v.clone()) |
3ae36eb to
00f6c4a
Compare
00f6c4a to
e57db95
Compare
…l GC state (#5480) <!--- Thank you for contributing to Boa! Please fill out the template below, and remove or add any information as you feel necessary. ---> follow up to #5479 --------- Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Mustafa Senoglu <mmustafasenoglu0@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tyler Breisacher <matrixfrog@gmail.com> Co-authored-by: José Julián Espina <jedel0124@gmail.com> Co-authored-by: Kaustubh Shivarkar <kaustubh.devlop@gmail.com> Co-authored-by: Hans Larsen <681969+hansl@users.noreply.github.com> Co-authored-by: Camilo Díaz Repka <camilojdiaz@gmail.com> Co-authored-by: mmustafasenoglu <mmustafasenoglu0@gmail.com> Co-authored-by: Vellumic <161718748+Vellumic@users.noreply.github.com> Co-authored-by: MAN$I VERMA <vmansi756@gmail.com> Co-authored-by: Tomáš Olvecký <tomas.olvecky@gmail.com> Co-authored-by: Pratush Shyam Gupt <143210487+psg-19@users.noreply.github.com> Co-authored-by: Aayush Mainali <aayushmainali.codes@gmail.com> Co-authored-by: GordonYuanyc <39959912+GordonYuanyc@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: magic-akari <akari.ccino@gmail.com> Co-authored-by: Nguyen Anh Tu (Elior) <122720156+xcb3d@users.noreply.github.com> Co-authored-by: Elior Nguyen <anhtunguyendev@wavenet.com.tw> Co-authored-by: Hitesh <hiteshshonak1@gmail.com> Co-authored-by: Kumar Tanay <32425567+tkshsbcue@users.noreply.github.com> Co-authored-by: jedel1043 <jedel@startmail.com> Co-authored-by: Zaid <161572905+iammdzaidalam@users.noreply.github.com> Co-authored-by: Jorge Polanco <55784702+Jorge-Polanco-Roque@users.noreply.github.com> Co-authored-by: ChrisJr404 <Sintation@gmail.com> Co-authored-by: Chris (ChrisJr404) <11917633+ChrisJr404@users.noreply.github.com> Co-authored-by: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Co-authored-by: Ayush Raj <light1ooo7710@gmail.com> Co-authored-by: yush-1018 <yush1018@gmail.com> Co-authored-by: Kevin Ness <nekevss@gmail.com>
Stacked on #5478, this PR enforces threading
MutationContextthrough all internal builtins, removing previous temporary fallbacks.Key Changes:
*_inmethods, temporary methods likeJsObject::new_inare gone. Main methods (e.g.,JsObject::new) have absorbed their signatures and now require the context.Defaultfor core objects:StandardConstructors,IntrinsicObjectsandIntrinsicscan no longer useDefault::default(); they must be instantiated viauninit(mc)boa_class) were updated to dynamically fetchcontext.gc_collector()without violating Rust's mutable borrowing rules.&unsafe { boa_gc::MutationContext::global() }to minimize immediate code breakage