Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bundler/bundle_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,11 @@ pub mod bv2_impl {

/// TYPE_ONLY moved
/// down to bundler (T5); bake (in runtime, T6) constructs values of this type.
#[derive(Clone)]
pub enum BuiltInModule {
Import(Box<[u8]>),
Code(Box<[u8]>),
Import(std::borrow::Cow<'static, [u8]>),
/// `Cow::Borrowed` is one of Bun's embedded sources.
Code(std::borrow::Cow<'static, [u8]>),
}

/// `EntryPointList` flags.
Expand Down Expand Up @@ -475,7 +477,7 @@ pub mod bv2_impl {
}
impl Framework {
/// Construct the bundler-side TYPE_ONLY view. Called from
/// `bun_runtime::bake::Framework::init_transpiler_with_options`; the
/// `bun_runtime::bake::Framework::as_bundler_view`; the
/// runtime owns the canonical `bake.Framework` and projects the
/// fields the bundler reads.
pub fn new(
Expand Down
6 changes: 3 additions & 3 deletions src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ impl<'a> Transpiler<'a> {

/// The resolver
/// crate carries a FORWARD_DECL subset of `BundleOptions`, so re-project
/// rather than `Clone`. Called after `init_transpiler_with_options` mutates
/// rather than `Clone`. Called after `init_transpiler` mutates
/// `self.options` so the resolver sees the same conditions/target/public_path.
pub fn sync_resolver_opts(&mut self) {
self.resolver.opts = resolver_bundle_options_subset(&self.options);
Expand Down Expand Up @@ -1025,8 +1025,8 @@ fn resolver_bundle_options_subset(
.zip(f.built_in_modules.values().iter())
{
let rv = match v {
B::Import(p) => R::Import(p.clone()),
B::Code(c) => R::Code(c.clone()),
B::Import(p) => R::Import(p.as_ref().into()),
B::Code(c) => R::Code(c.as_ref().into()),
};
m.put(k, rv).expect("oom");
}
Expand Down
2 changes: 1 addition & 1 deletion src/ptr/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ pub unsafe fn boxed_slices_as_borrowed<T, A: core::alloc::Allocator>(s: &[Box<[T
// bare `&'static [u8]` carries no proof, so a refactor can silently feed
// it a stack slice.
// • Population B (~24) — bytes are owned by a value with a `Drop` that runs
// before process exit (UserOptions arena, FetchTasklet, JSC slice, SSL
// before process exit (FetchTasklet, JSC slice, SSL
// session). The widen is unsound the moment the value escapes the holder.
//
// `Interned` is the type-level proof that a `&'static [u8]` came from
Expand Down
23 changes: 7 additions & 16 deletions src/runtime/bake/DevServer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@ pub(crate) struct Options<'a> {
pub broadcast_console_log_from_browser_to_server: bool,
}

// Note: the fields (`arena`, `root`, `vm`, `framework`,
// `bundler_options`, `broadcast_console_log_from_browser_to_server`) are
// required with no sensible zero value, so `Default` is intentionally NOT
// implemented. Callers construct `Options` via struct-literal at the call site
// (see `bake_body.rs::UserOptions::into_dev_server_options`).

// The fields `client_graph`, `server_graph`, `directory_watchers`, and `assets`
// all use `@fieldParentPointer` to access DevServer's state. This pattern has
// made it easier to group related fields together, but one must remember those
Expand Down Expand Up @@ -507,8 +501,6 @@ pub(crate) fn init(options: Options) -> JsResult<Box<DevServer>> {
);
w!(generation, 0);
w!(graph_safety_lock, ThreadLock::init_unlocked());
w!(framework, options.framework);
w!(bundler_options, options.bundler_options);
w!(emit_incremental_visualizer_events, 0);
w!(emit_memory_visualizer_events, 0);
w!(
Expand All @@ -518,9 +510,7 @@ pub(crate) fn init(options: Options) -> JsResult<Box<DevServer>> {
// `dev.frontend_only = dev.framework.file_system_router_types.len == 0`
w!(
frontend_only,
(*addr_of_mut!((*p).framework))
.file_system_router_types
.is_empty()
options.framework.file_system_router_types.is_empty()
);
w!(client_graph, IncrementalGraph::default());
w!(server_graph, IncrementalGraph::default());
Expand Down Expand Up @@ -630,8 +620,7 @@ pub(crate) fn init(options: Options) -> JsResult<Box<DevServer>> {
//
// SAFETY: `init_transpiler` writes the slot via `MaybeUninit::write` (see
// `bake_body.rs`), so the previous (uninitialized) bytes are never dropped.
// `framework`/`log`/`bundler_options` were written above; reborrowing each
// individually via `addr_of_mut!` is sound because no `&mut DevServer` exists.
// `log` was written above; reborrowing it is sound because no `&mut DevServer` exists.
// Note: `Transpiler<'static>` erases the arena lifetime — `options.arena`
// is the `UserOptions.arena` which is moved into / outlives the `DevServer`
// box. Widen `'a → 'static` here once.
Expand All @@ -644,9 +633,10 @@ pub(crate) fn init(options: Options) -> JsResult<Box<DevServer>> {
// accessed below were each written above and are reborrowed disjointly via
// `addr_of_mut!`, so no overlapping `&mut` exists.
unsafe {
let framework = &mut *addr_of_mut!((*p).framework);
// Still in `options`, so that an early return drops them.
let framework = &options.framework;
let log = &mut *addr_of_mut!((*p).log);
let bundler_options = &mut *addr_of_mut!((*p).bundler_options);
let bundler_options = &options.bundler_options;

match framework.init_transpiler(
arena,
Expand Down Expand Up @@ -699,6 +689,8 @@ pub(crate) fn init(options: Options) -> JsResult<Box<DevServer>> {
}

w!(bundler_framework_views, bundler_framework_views);
w!(framework, options.framework);
w!(bundler_options, options.bundler_options);
}

// ── every field is now written ───────────────────────────────────────────
Expand Down Expand Up @@ -753,7 +745,6 @@ pub(crate) fn init(options: Options) -> JsResult<Box<DevServer>> {
unsafe { &mut (*(*dev_ptr).server_transpiler.as_mut_ptr()).resolver },
// SAFETY: see above; `client_transpiler` was initialized and is disjoint from `framework`.
unsafe { &mut (*(*dev_ptr).client_transpiler.as_mut_ptr()).resolver },
options.arena,
)
.is_err()
{
Expand Down
Loading
Loading