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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/ast/ast_memory_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl ASTMemoryAllocator {
// The AstAlloc state follows the arena's retain-or-recycle
// decision: callers like `--define` hold `StoreRef`s across a
// retained reset, so only clear it when the heap is recycled.
if !self.arena.reset_retain_with_limit(limit) {
if self.arena.reset_retain_with_limit(limit) == bun_alloc::ResetOutcome::Recycled {
self.reset_ast_state();
}
self.arena_dirty = false;
Expand Down
59 changes: 39 additions & 20 deletions src/ast/e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,19 @@ impl Default for ImportIdentifier {
Self { ref_: Ref::NONE }
}
}
bun_core::bool_enum!(pub WasOriginallyIdentifier);

impl ImportIdentifier {
#[inline]
pub const fn new(ref_: Ref, was_originally_identifier: bool) -> Self {
pub const fn new(ref_: Ref, was_originally_identifier: WasOriginallyIdentifier) -> Self {
// Strip any incoming user bits (the caller may pass an
// `E::Identifier.ref_` carrying its own flags in bits 1/2) before
// applying ours, so foreign flags can't leak into this node.
Self {
ref_: ref_
.without_user_bits()
.with_user_bit(0, was_originally_identifier),
ref_: ref_.without_user_bits().with_user_bit(
0,
matches!(was_originally_identifier, WasOriginallyIdentifier::Yes),
),
}
}

Expand Down Expand Up @@ -1123,6 +1126,8 @@ impl JsonTape {
}
}

bun_core::bool_enum!(pub IsSingleLine);

/// `Data::EObjectJSON`: a `(first, count)` span of the document's property-row tape.
#[repr(C)]
pub struct ObjectJSON {
Expand Down Expand Up @@ -1158,15 +1163,15 @@ impl ObjectJSON {
tape: core::ptr::NonNull<JsonTape>,
first: u32,
count: u32,
is_single_line: bool,
is_single_line: IsSingleLine,
close_brace_loc: crate::Loc,
) -> Self {
ObjectJSON {
tape,
first,
count,
close_brace_loc,
is_single_line,
is_single_line: is_single_line == IsSingleLine::Yes,
}
}

Expand Down Expand Up @@ -1230,15 +1235,15 @@ impl ArrayJSON {
tape: core::ptr::NonNull<JsonTape>,
first: u32,
count: u32,
is_single_line: bool,
is_single_line: IsSingleLine,
close_bracket_loc: crate::Loc,
) -> Self {
ArrayJSON {
tape,
first,
count,
close_bracket_loc,
is_single_line,
is_single_line: is_single_line == IsSingleLine::Yes,
}
}

Expand Down Expand Up @@ -1810,7 +1815,11 @@ impl EString {
// PERF: transcodes to a heap Vec then copies into the bump
// arena — profile.
// `fail_if_invalid = false` means the only possible error is `OutOfMemory`.
let utf16 = bun_core::handle_oom(strings::to_utf16_alloc_for_real(utf8, false, false));
let utf16 = bun_core::handle_oom(strings::to_utf16_alloc_for_real(
utf8,
strings::FailIfInvalid::No,
strings::Sentinel::No,
));
let arena_slice: &mut [u16] = bump.alloc_slice_copy(&utf16);
Self::init_utf16(arena_slice)
}
Expand Down Expand Up @@ -1860,7 +1869,7 @@ impl EString {

pub fn eql_bytes(&self, other: &[u8]) -> bool {
if self.is_utf8() {
strings::eql_long(&self.data, other, true)
strings::eql_long(&self.data, other, strings::CheckLen::Yes)
} else {
strings::utf16_eql_string(self.slice16(), other)
}
Expand All @@ -1885,7 +1894,11 @@ impl EString {
let mut i = 0usize;
let mut next: Option<&EString> = Some(self);
while let Some(cur) = next {
if !strings::eql_long(&cur.data, &value[i..i + cur.data.len()], false) {
if !strings::eql_long(
&cur.data,
&value[i..i + cur.data.len()],
strings::CheckLen::No,
) {
return false;
}
i += cur.data.len();
Expand Down Expand Up @@ -1985,7 +1998,7 @@ impl EString {
pub fn eql_string(&self, other: &EString) -> bool {
if self.is_utf8() {
if other.is_utf8() {
strings::eql_long(&self.data, &other.data, true)
strings::eql_long(&self.data, &other.data, strings::CheckLen::Yes)
} else {
strings::utf16_eql_string(other.slice16(), &self.data)
}
Expand Down Expand Up @@ -2543,13 +2556,15 @@ mod json_tape_tests {
let kb = tape.get().alloc_str(b"b");
let (first, count) = tape.get().append_props(&[prop(kb, JsonValue::Null)], &[]);
// SAFETY: the tape's own pointer, as `Parser` passes it.
let inner = unsafe { ObjectJSON::new(tape.ptr(), first, count, true, Loc::EMPTY) };
let inner =
unsafe { ObjectJSON::new(tape.ptr(), first, count, IsSingleLine::Yes, Loc::EMPTY) };

// The parse continues: another string, then the outer object's rows.
let ka = tape.get().alloc_str(b"a");
let (first, count) = tape.get().append_props(&[prop(ka, JsonValue::Null)], &[]);
// SAFETY: as above.
let outer = unsafe { ObjectJSON::new(tape.ptr(), first, count, true, Loc::EMPTY) };
let outer =
unsafe { ObjectJSON::new(tape.ptr(), first, count, IsSingleLine::Yes, Loc::EMPTY) };

// Post-parse reads, after every one of those writes.
assert_eq!(inner.properties().len(), 1);
Expand All @@ -2566,11 +2581,13 @@ mod json_tape_tests {

let (first, count) = tape.get().append_items(&[JsonValue::Null], &[]);
// SAFETY: the tape's own pointer, as `Parser` passes it.
let inner = unsafe { ArrayJSON::new(tape.ptr(), first, count, true, Loc::EMPTY) };
let inner =
unsafe { ArrayJSON::new(tape.ptr(), first, count, IsSingleLine::Yes, Loc::EMPTY) };

let (first, count) = tape.get().append_items(&[JsonValue::Boolean(true)], &[]);
// SAFETY: as above.
let outer = unsafe { ArrayJSON::new(tape.ptr(), first, count, true, Loc::EMPTY) };
let outer =
unsafe { ArrayJSON::new(tape.ptr(), first, count, IsSingleLine::Yes, Loc::EMPTY) };

assert_eq!(inner.items().len(), 1);
assert!(matches!(inner.items()[0], JsonValue::Null));
Expand All @@ -2583,9 +2600,9 @@ mod json_tape_tests {
fn zero_count_spans_do_not_read_the_tape() {
let tape = TapeOwner::new();
// SAFETY: the tape's own pointer.
let o = unsafe { ObjectJSON::new(tape.ptr(), 0, 0, true, Loc::EMPTY) };
let o = unsafe { ObjectJSON::new(tape.ptr(), 0, 0, IsSingleLine::Yes, Loc::EMPTY) };
// SAFETY: as above.
let a = unsafe { ArrayJSON::new(tape.ptr(), 0, 0, true, Loc::EMPTY) };
let a = unsafe { ArrayJSON::new(tape.ptr(), 0, 0, IsSingleLine::Yes, Loc::EMPTY) };
assert!(o.properties().is_empty());
assert_eq!(o.value_locs(), Some(&[][..]));
assert!(a.items().is_empty());
Expand Down Expand Up @@ -2624,13 +2641,15 @@ mod json_tape_tests {
let kb = tape(tape_ptr).alloc_str(b"b");
let (first, count) = tape(tape_ptr).append_props(&[prop(kb, JsonValue::Null)], &[]);
// SAFETY: the tape's own pointer.
let inner = unsafe { ObjectJSON::new(tape_ptr, first, count, true, Loc::EMPTY) };
let inner =
unsafe { ObjectJSON::new(tape_ptr, first, count, IsSingleLine::Yes, Loc::EMPTY) };

// The parse keeps appending after the node is built.
let ka = tape(tape_ptr).alloc_str(b"a");
let (first, count) = tape(tape_ptr).append_props(&[prop(ka, JsonValue::Null)], &[]);
// SAFETY: as above.
let outer = unsafe { ObjectJSON::new(tape_ptr, first, count, true, Loc::EMPTY) };
let outer =
unsafe { ObjectJSON::new(tape_ptr, first, count, IsSingleLine::Yes, Loc::EMPTY) };

assert_eq!(inner.properties()[0].key.slice(), b"b");
assert_eq!(outer.properties()[0].key.slice(), b"a");
Expand Down
50 changes: 31 additions & 19 deletions src/ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ pub enum RefTag {
Symbol = 3,
}

bun_core::bool_enum!(pub IsSourceContentsSlice);

/// Packed-u64 symbol reference: `{inner_index: u28, user: u3, tag: u2, source_index: u31}`.
///
/// LSB-first packing for the `tag`/`source_index` fields, with 3 bits stolen
Expand Down Expand Up @@ -273,11 +275,14 @@ impl Ref {
i == Self::INNER_MASK as u32 // maxInt(u31)
}

pub fn init(inner_index: u32, source_index: u32, is_source_contents_slice: bool) -> Ref {
let tag = if is_source_contents_slice {
RefTag::SourceContentsSlice
} else {
RefTag::AllocatedName
pub fn init(
inner_index: u32,
source_index: u32,
is_source_contents_slice: IsSourceContentsSlice,
) -> Ref {
let tag = match is_source_contents_slice {
IsSourceContentsSlice::Yes => RefTag::SourceContentsSlice,
IsSourceContentsSlice::No => RefTag::AllocatedName,
};
Self::pack(inner_index, tag, source_index)
}
Expand Down Expand Up @@ -1350,6 +1355,13 @@ impl Range {
// Log
// ───────────────────────────────────────────────────────────────────────────

bun_core::bool_enum!(
/// Whether the source contents backing the messages are recycled (so line
/// text must be deep-copied when cloning into another `Log`).
pub Recycled
);
bun_core::bool_enum!(pub Redact);

pub struct Log {
pub warnings: u32,
pub errors: u32,
Expand Down Expand Up @@ -1536,19 +1548,19 @@ impl Log {
},
text,
Box::default(),
false,
Redact::No,
)
}

// `to_js`/`to_js_aggregate_error`/`to_js_array` live in `bun_logger_jsc`.

pub fn clone_to_with_recycled(&mut self, other: &mut Log, recycled: bool) {
pub fn clone_to_with_recycled(&mut self, other: &mut Log, recycled: Recycled) {
let dest_start = other.msgs.len();
other.msgs.extend(self.msgs.iter().map(Msg::clone));
other.warnings += self.warnings;
other.errors += self.errors;

if recycled {
if recycled == Recycled::Yes {
let mut string_builder = StringBuilder;
let mut notes_count: usize = 0;
for msg in &self.msgs {
Expand All @@ -1571,7 +1583,7 @@ impl Log {
}
}

pub fn append_to_with_recycled(&mut self, other: &mut Log, recycled: bool) {
pub fn append_to_with_recycled(&mut self, other: &mut Log, recycled: Recycled) {
self.clone_to_with_recycled(other, recycled);
self.msgs.clear();
self.msgs.shrink_to_fit();
Expand All @@ -1582,7 +1594,7 @@ impl Log {
}

pub fn append_to_maybe_recycled(&mut self, other: &mut Log, source: &Source) {
self.append_to_with_recycled(other, source.contents_is_recycled)
self.append_to_with_recycled(other, Recycled::from_bool(source.contents_is_recycled))
}

// TODO: remove `deinit` because it does not de-initialize the log; it clears it
Expand Down Expand Up @@ -1614,7 +1626,7 @@ impl Log {
r: Range,
text: Cow<'static, [u8]>,
notes: Box<[Data]>,
redact_sensitive_information: bool,
redact_sensitive_information: Redact,
) {
match kind {
Kind::Err => self.errors += 1,
Expand All @@ -1628,7 +1640,7 @@ impl Log {
kind,
data,
notes,
redact_sensitive_information,
redact_sensitive_information: redact_sensitive_information == Redact::Yes,
..Default::default()
})
}
Expand Down Expand Up @@ -1742,7 +1754,7 @@ impl Log {
args: fmt::Arguments<'_>,
) {
let text = alloc_print(args);
self.add_formatted_msg(Kind::Err, source, r, text, Box::default(), false)
self.add_formatted_msg(Kind::Err, source, r, text, Box::default(), Redact::No)
}

#[inline]
Expand All @@ -1754,7 +1766,7 @@ impl Log {
args: fmt::Arguments<'_>,
) {
let text = alloc_print(args);
self.add_formatted_msg(Kind::Err, source, r, text, notes, false)
self.add_formatted_msg(Kind::Err, source, r, text, notes, Redact::No)
}

#[inline]
Expand All @@ -1774,7 +1786,7 @@ impl Log {
},
text,
Box::default(),
false,
Redact::No,
)
}

Expand All @@ -1791,7 +1803,7 @@ impl Log {
},
text,
Box::default(),
opts.redact_sensitive_information,
Redact::from_bool(opts.redact_sensitive_information),
)
}

Expand Down Expand Up @@ -1854,7 +1866,7 @@ impl Log {
},
text,
Box::default(),
false,
Redact::No,
)
}

Expand Down Expand Up @@ -1917,7 +1929,7 @@ impl Log {
return;
}
let text = alloc_print(args);
self.add_formatted_msg(Kind::Warn, source, r, text, Box::default(), false)
self.add_formatted_msg(Kind::Warn, source, r, text, Box::default(), Redact::No)
}

#[cold]
Expand Down Expand Up @@ -1955,7 +1967,7 @@ impl Log {
args: fmt::Arguments<'_>,
) {
let text = alloc_print(args);
self.add_formatted_msg(Kind::Warn, source, r, text, notes, false)
self.add_formatted_msg(Kind::Warn, source, r, text, notes, Redact::No)
}

#[cold]
Expand Down
Loading
Loading