Skip to content
Open
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
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ len_without_is_empty = "allow"
needless_return = "allow"
module_inception = "allow"
missing_safety_doc = "allow"
let_unit_value = "allow"
needless_update = "allow"
explicit_auto_deref = "allow"
doc_lazy_continuation = "allow"
Expand Down
61 changes: 22 additions & 39 deletions src/ast/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,33 +910,19 @@ impl DeclaredSymbolList {
core::mem::take(self)
}

pub fn clone(&self) -> core::result::Result<DeclaredSymbolList, bun_alloc::AllocError> {
Ok(DeclaredSymbolList {
entries: self.entries.clone()?,
})
}

#[inline]
pub fn len(&self) -> usize {
self.entries.len()
}

pub fn append(
&mut self,
entry: DeclaredSymbol,
) -> core::result::Result<(), bun_alloc::AllocError> {
self.ensure_unused_capacity(1)?;
pub fn append(&mut self, entry: DeclaredSymbol) {
self.ensure_unused_capacity(1);
self.append_assume_capacity(entry);
Ok(())
}

pub fn append_list(
&mut self,
other: &DeclaredSymbolList,
) -> core::result::Result<(), bun_alloc::AllocError> {
self.ensure_unused_capacity(other.len())?;
pub fn append_list(&mut self, other: &DeclaredSymbolList) {
self.ensure_unused_capacity(other.len());
self.append_list_assume_capacity(other);
Ok(())
}

pub(crate) fn append_list_assume_capacity(&mut self, other: &DeclaredSymbolList) {
Expand All @@ -947,18 +933,12 @@ impl DeclaredSymbolList {
self.entries.append_assume_capacity(entry);
}

pub fn ensure_total_capacity(
&mut self,
count: usize,
) -> core::result::Result<(), bun_alloc::AllocError> {
self.entries.ensure_total_capacity(count)
pub fn ensure_total_capacity(&mut self, count: usize) {
self.entries.ensure_total_capacity(count);
}

pub fn ensure_unused_capacity(
&mut self,
count: usize,
) -> core::result::Result<(), bun_alloc::AllocError> {
self.entries.ensure_unused_capacity(count)
pub fn ensure_unused_capacity(&mut self, count: usize) {
self.entries.ensure_unused_capacity(count);
}

pub fn clear_retaining_capacity(&mut self) {
Expand All @@ -967,23 +947,26 @@ impl DeclaredSymbolList {

// `deinit` → Drop on MultiArrayList; no explicit body needed.

pub fn init_capacity(
capacity: usize,
) -> core::result::Result<DeclaredSymbolList, bun_alloc::AllocError> {
pub fn init_capacity(capacity: usize) -> DeclaredSymbolList {
let mut entries = MultiArrayList::new_in(bun_alloc::AstAlloc);
entries.ensure_unused_capacity(capacity)?;
Ok(DeclaredSymbolList { entries })
entries.ensure_unused_capacity(capacity);
DeclaredSymbolList { entries }
}

pub fn from_slice(
entries: &[DeclaredSymbol],
) -> core::result::Result<DeclaredSymbolList, bun_alloc::AllocError> {
let mut this = Self::init_capacity(entries.len())?;
// errdefer this.deinit() → Drop handles it
pub fn from_slice(entries: &[DeclaredSymbol]) -> DeclaredSymbolList {
let mut this = Self::init_capacity(entries.len());
for entry in entries {
this.append_assume_capacity(*entry);
}
Ok(this)
this
}
}

impl Clone for DeclaredSymbolList {
fn clone(&self) -> Self {
DeclaredSymbolList {
entries: self.entries.clone(),
}
}
}

Expand Down
16 changes: 6 additions & 10 deletions src/ast/server_component_boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,22 @@ impl List {
use_directive: UseDirective,
reference_source_index: IndexInt,
ssr_source_index: IndexInt,
) -> Result<(), bun_alloc::AllocError> {
) {
self.list.append(ServerComponentBoundary {
source_index,
use_directive,
reference_source_index,
ssr_source_index,
})?;
});
// For borrowck we hand the adapter just the `source_index` column
// it needs.
let gop = self.map.get_or_put_adapted(
&source_index,
&Adapter {
source_indices: self.list.items::<"source_index", IndexInt>(),
},
)?;
);
debug_assert!(!gop.found_existing);
Ok(())
}

/// Use this to improve speed of accessing fields at the cost of
Expand Down Expand Up @@ -122,15 +121,12 @@ impl<'a> Slice<'a> {
Some(self.list.items::<"reference_source_index", IndexInt>()[i])
}

pub fn bit_set(
&self,
input_file_count: usize,
) -> Result<DynamicBitSetUnmanaged, bun_alloc::AllocError> {
let mut scb_bitset = DynamicBitSetUnmanaged::init_empty(input_file_count)?;
pub fn bit_set(&self, input_file_count: usize) -> DynamicBitSetUnmanaged {
let mut scb_bitset = DynamicBitSetUnmanaged::init_empty(input_file_count);
for &source_index in self.list.items::<"source_index", IndexInt>() {
scb_bitset.set(source_index as usize);
}
Ok(scb_bitset)
scb_bitset
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/bun_bin/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ pub(crate) unsafe extern "C" fn main(argc: c_int, argv: *const *const c_char) ->
Some(bun_alloc::mimalloc::mi_free),
);
}
// `bun.handleOom(convertEnvToWTF8())` — converts the OS UTF-16 env
// block to WTF-8 and publishes it via `bun_core::os::set_environ()`.
// Converts the OS UTF-16 env block to WTF-8 and publishes it via
// `bun_core::os::set_environ()`.
// Without this, `Bun.env`/`process.env` see only `.env`-file vars.
bun_core::handle_oom(bun_sys::windows::env::convert_env_to_wtf8());
}
Expand Down
1 change: 0 additions & 1 deletion src/bun_core/string/StringJoiner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl<'a> StringJoiner<'a> {
if data.is_empty() {
return;
}
// bun.handleOom(this.allocator.dupe(u8, data)) → Box<[u8]> (aborts on OOM)
self.push_owned(Box::from(data));
}

Expand Down
22 changes: 11 additions & 11 deletions src/bundler/AstBuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
ref_,
is_top_level: self.scopes.is_empty()
|| core::ptr::eq(self.current_scope, self.scopes[0]),
})?;
});
Ok(ref_)
}

Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
// pretend that every symbol was used
symbol_uses: 'uses: {
let mut map = PartSymbolUseMap::default();
map.ensure_total_capacity(self.symbols.len())?;
map.ensure_total_capacity(self.symbols.len());
for i in 0..self.symbols.len() {
map.put_assume_capacity(
Ref::new(
Expand All @@ -287,7 +287,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
// SAFETY: module_scope is a live arena allocation (set in init, scopes stack is empty)
let module_scope_ref = unsafe { &*module_scope };
let generated_len = module_scope_ref.generated.len();
top_level_symbols_to_parts.ensure_total_capacity(generated_len)?;
top_level_symbols_to_parts.ensure_total_capacity(generated_len);
// `ArrayHashMap` keeps keys/values in private `Vec`s and rebuilds
// hashes on every `put_assume_capacity`, so a plain pre-reserved
// insert loop suffices (and `re_index` is a no-op here). `Vec` is
Expand All @@ -296,7 +296,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
top_level_symbols_to_parts
.put_assume_capacity(ref_, bun_alloc::AstAlloc::vec_from_slice(&[1]));
}
top_level_symbols_to_parts.re_index()?;
top_level_symbols_to_parts.re_index();

// For more details on this section, look at js_parser.toAST
// This is mimicking how it calls ImportScanner
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
is_exported: false,
local_parts_with_uses: bun_alloc::AstAlloc::vec(),
},
)?;
);
}
// convertStmt: `deduplicatedImport` is a no-op for
// AstBuilder (each generated file emits at most one
Expand Down Expand Up @@ -396,10 +396,10 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
parts[1].declared_symbols.append(DeclaredSymbol {
ref_: temp_id,
is_top_level: true,
})?;
});
parts[1]
.symbol_uses
.put(temp_id, symbol::Use { count_estimate: 1 })?;
.put(temp_id, symbol::Use { count_estimate: 1 });
VecExt::append(&mut self.current_scope_mut().generated, temp_id);
export_props.push(G::Property {
key: Some(Expr::init(E::String::init(b"default"), stmt.loc)),
Expand Down Expand Up @@ -456,11 +456,11 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
// mark a dependency on module_ref so it is renamed
parts[1]
.symbol_uses
.put(self.module_ref, symbol::Use { count_estimate: 1 })?;
.put(self.module_ref, symbol::Use { count_estimate: 1 });
parts[1].declared_symbols.append(DeclaredSymbol {
ref_: self.module_ref,
is_top_level: true,
})?;
});
}
// Head-part bookkeeping (only `parts[0]`, which is the empty
// namespace-export part): mark dead and depend on `parts[1]`.
Expand Down Expand Up @@ -500,7 +500,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
is_exported: false,
local_parts_with_uses: bun_alloc::AstAlloc::vec(),
},
)?;
);
}
}
bun_ast::StmtData::SLocal(st) if st.is_export => {
Expand Down Expand Up @@ -590,7 +590,7 @@ impl<'a, 'bump> AstBuilder<'a, 'bump> {
alias_loc: Loc::EMPTY,
ref_,
},
)?;
);
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/BundleThread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<C: CompletionStruct> BundleThread<C> {
// SAFETY: `transpiler.log` is the arena-allocated `*mut Log` set up by
// `configure_bundler`; valid for the lifetime of `heap`. Raw deref so the
// `&'a mut Transpiler` consumed by `init_and_run` above is not reborrowed.
let _ = unsafe { (*(*transpiler_ptr).log).append_to_with_recycled(&mut out_log, true) }; // logger OOM-only
unsafe { (*(*transpiler_ptr).log).append_to_with_recycled(&mut out_log, true) };
completion.set_log(out_log);

if run.is_ok() {
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/Chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl Default for Chunk {
Chunk {
unique_key: b"",
files_with_parts_in_chunk: ArrayHashMap::new(),
entry_bits: AutoBitSet::init_empty(0).expect("static AutoBitSet"),
entry_bits: AutoBitSet::init_empty(0),
final_rel_path: Box::default(),
template: PathTemplate::default(),
cross_chunk_imports: Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions src/bundler/HTMLImportManifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub(crate) fn write<W: Write + ?Sized>(
&*bun_core::from_field_ptr!(BundleV2<'static>, graph, std::ptr::from_ref::<Graph>(graph))
};
let options = &bv2.transpiler().options;
let mut entry_point_bits = AutoBitSet::init_empty(graph.entry_points.len())?;
let mut entry_point_bits = AutoBitSet::init_empty(graph.entry_points.len());

let root_dir: &[u8] = if !options.root_dir.is_empty() {
&options.root_dir[..]
Expand Down Expand Up @@ -233,7 +233,7 @@ pub(crate) fn write<W: Write + ?Sized>(

let additional_output_files = graph.additional_output_files.as_slice();
let file_entry_bits: &[AutoBitSet] = linker_graph.files.items_entry_bits();
let mut already_visited_output_file = AutoBitSet::init_empty(additional_output_files.len())?;
let mut already_visited_output_file = AutoBitSet::init_empty(additional_output_files.len());

// Write all chunks that have files associated with this entry point.
// Also include browser chunks from server builds (lazy-loaded chunks from dynamic imports).
Expand Down
6 changes: 2 additions & 4 deletions src/bundler/HTMLScanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ impl<'a> HTMLScanner<'a> {
}

fn on_html_parse_error(&mut self, message: &[u8]) {
// Vec/Box allocations abort on OOM; just call. `IntoText for
// Vec<u8>` → `Cow::Owned`, so the Log owns and drops the copy.
let _ = self
.log
// `IntoText for Vec<u8>` → `Cow::Owned`, so the Log owns and drops the copy.
self.log
.add_error(Some(self.source), Loc::EMPTY, message.to_vec());
}

Expand Down
Loading
Loading