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
4 changes: 1 addition & 3 deletions mordant-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@
"unused_pub:src/bun_core/string/immutable.rs" = 6
"unused_pub:src/bun_core/string/mod.rs" = 2
"unused_pub:src/bun_core/util.rs" = 10
"unused_pub:src/collections/StaticHashMap.rs" = 4
"unused_pub:src/collections/vec_ext.rs" = 2
"unused_pub:src/dotenv/env_loader.rs" = 1
"unused_pub:src/errno/lib.rs" = 1
"unused_pub:src/event_loop/AnyEventLoop.rs" = 3
"unused_pub:src/event_loop/SpawnSyncEventLoop.rs" = 1
"unused_pub:src/glob/GlobWalker.rs" = 1
"unused_pub:src/io/ParentDeathWatchdog.rs" = 1
"unused_pub:src/io/PipeWriter.rs" = 2
"unused_pub:src/io/PipeWriter.rs" = 1
"unused_pub:src/jsc/bindgen.rs" = 6
"unused_pub:src/jsc/host_fn.rs" = 1
"unused_pub:src/jsc/lib.rs" = 1
Expand All @@ -154,7 +153,6 @@
"unused_pub:src/paths/string_paths.rs" = 7
"unused_pub:src/ptr/CowSlice.rs" = 1
"unused_pub:src/ptr/ref_count.rs" = 2
"unused_pub:src/react_compiler/hir/environment.rs" = 2
"unused_pub:src/runtime/api/bun/h2/connection.rs" = 5
"unused_pub:src/runtime/api/bun/h2/wire.rs" = 1
"unused_pub:src/runtime/ipc.rs" = 3
Expand Down
111 changes: 13 additions & 98 deletions src/collections/StaticHashMap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,6 @@ pub trait HashMapMixin<K: 'static, V: 'static, Ctx> {
fn len_mut(&mut self) -> &mut usize;
fn shift(&self) -> u8;

/// Full backing slice (capacity + overflow).
fn slice(&mut self) -> &mut [Entry<K, V>] {
// The storage carries its exact length; the assert checks it stays
// consistent with the `shift`-derived `capacity + overflow` size.
let capacity = 1u64 << (63 - self.shift() + 1);
let overflow = compute_overflow(capacity, self.shift());
debug_assert_eq!(
self.storage_mut().len(),
usize::try_from(capacity + overflow).expect("int cast")
);
self.storage_mut()
}

fn put_assume_capacity(&mut self, key: K, value: V)
where
K: Copy,
V: Copy + Default,
Ctx: HashContext<K>,
{
let result = self.get_or_put_assume_capacity(key);
if !result.found_existing {
*result.value_ptr = value;
}
}

fn get_or_put_assume_capacity(&mut self, key: K) -> GetOrPutResult<'_, V>
where
K: Copy,
Expand Down Expand Up @@ -232,26 +207,6 @@ pub trait HashMapMixin<K: 'static, V: 'static, Ctx> {
}
}

fn get(&self, key: K) -> Option<V>
where
K: Copy,
V: Copy,
Ctx: HashContext<K>,
{
let hash = Ctx::ctx_hash(&key);
debug_assert!(hash != EMPTY_HASH);

for entry in &self.storage()[to_idx(hash >> self.shift())..] {
if entry.hash >= hash {
if !Ctx::ctx_eql(&entry.key, &key) {
return None;
}
return Some(entry.value);
}
}
unreachable!()
}

fn has_with_hash(&self, key_hash: u64) -> bool {
debug_assert!(key_hash != EMPTY_HASH);

Expand All @@ -263,45 +218,6 @@ pub trait HashMapMixin<K: 'static, V: 'static, Ctx> {

false
}

fn delete(&mut self, key: K) -> Option<V>
where
K: Copy + Default,
V: Copy + Default,
Ctx: HashContext<K>,
{
let hash = Ctx::ctx_hash(&key);
debug_assert!(hash != EMPTY_HASH);

let shift = self.shift();
let mut i = to_idx(hash >> shift);
loop {
let entry = self.storage()[i];
if entry.hash >= hash {
if !Ctx::ctx_eql(&entry.key, &key) {
return None;
}
break;
}
i += 1;
}

let value = self.storage()[i].value;

loop {
let next = self.storage()[i + 1];
let j = to_idx(next.hash >> shift);
if i < j || next.is_empty() {
break;
}
self.storage_mut()[i] = next;
i += 1;
}
self.storage_mut()[i] = Entry::empty();
*self.len_mut() -= 1;

Some(value)
}
}

// ──────────────────────────────────────────────────────────────────────────
Expand All @@ -315,9 +231,7 @@ mod tests {
/// xoshiro256++ with the state seeded by splitmix64. `AutoHashContext`
/// routes through `bun_wyhash::auto_hash` (mum-mix). The 100%-load probe
/// bound of the static test was validated for this hash by exact
/// simulation of all 128 seeds: max slot index touched (incl. delete's
/// `i + 1` backshift read) is 548 of 632, with no 64-bit hash collisions
/// among any seed's 512 keys.
/// simulation of all 128 seeds: max slot 548 of 632, no 64-bit hash collisions.
struct Xoshiro256PlusPlus {
s: [u64; 4],
}
Expand Down Expand Up @@ -354,41 +268,42 @@ mod tests {
}

#[test]
fn static_hash_map_put_get_delete_grow() {
fn static_hash_map_put_get_grow() {
const CAP: usize = 512;
const SLOTS: usize = static_slots(CAP);
// Boxed: ~15 KB of entries is fine on the heap, gratuitous on the stack.
let mut map: Box<StaticHashMap<usize, usize, AutoContext, CAP, SLOTS>> =
Box::new(Default::default());

// Miri is ~100× slower; 2 seeds still cover the put/get/delete cycle.
// Miri is ~100× slower; 2 seeds still cover the put/get cycle.
const SEEDS: u64 = if cfg!(miri) { 2 } else { 128 };
for seed in 0..SEEDS {
// Boxed: ~15 KB of entries is fine on the heap, gratuitous on the stack.
let mut map: Box<StaticHashMap<usize, usize, AutoContext, CAP, SLOTS>> =
Box::new(Default::default());
let mut rng = Xoshiro256PlusPlus::init(seed);

let keys: Vec<usize> = (0..512).map(|_| rng.next() as usize).collect();

assert_eq!(map.shift, 55);

for (i, &key) in keys.iter().enumerate() {
map.put_assume_capacity(key, i);
*map.get_or_put_assume_capacity(key).value_ptr = i;
}
assert_eq!(map.len, keys.len());

let mut it: u64 = 0;
for entry in map.slice().iter() {
for entry in map.entries.iter() {
if !entry.is_empty() {
assert!(it <= entry.hash, "Unsorted");
it = entry.hash;
}
}

for (i, &key) in keys.iter().enumerate() {
assert_eq!(map.get(key).unwrap(), i);
}
for (i, &key) in keys.iter().enumerate() {
assert_eq!(map.delete(key).unwrap(), i);
let existing = map.get_or_put_assume_capacity(key);
assert!(existing.found_existing);
assert_eq!(*existing.value_ptr, i);
assert!(map.has_with_hash(<AutoContext as HashContext<usize>>::ctx_hash(&key)));
}
assert_eq!(map.len, keys.len());
}
}
}
9 changes: 0 additions & 9 deletions src/io/PipeWriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,6 @@ pub trait PosixStreamingWriterParent {
unsafe fn on_error(this: *mut Self, err: sys::Error);
/// # Safety
/// `this` must point to a live `Self`.
unsafe fn on_ready(_this: *mut Self) {}
/// # Safety
/// `this` must point to a live `Self`.
unsafe fn on_close(this: *mut Self);
/// # Safety
/// `this` must point to a live `Self`.
Expand Down Expand Up @@ -2646,11 +2643,6 @@ macro_rules! impl_streaming_writer_parent {
unsafe { $crate::impl_streaming_writer_parent!(@call $borrow this; $on_error(err)) }
}
#[inline]
unsafe fn on_ready(this: *mut Self) {
// SAFETY: see on_write.
unsafe { $crate::impl_streaming_writer_parent!(@call $borrow this; $on_ready()) }
}
#[inline]
unsafe fn on_close(this: *mut Self) {
// SAFETY: see on_write.
unsafe { $crate::impl_streaming_writer_parent!(@call $borrow this; $on_close()) }
Expand Down Expand Up @@ -2698,7 +2690,6 @@ macro_rules! impl_streaming_writer_parent {

#[cfg(windows)]
impl $($gen)* $crate::pipe_writer::WindowsStreamingWriterParent for $Ty {
// Same body as POSIX `on_ready`.
const HAS_ON_WRITABLE: bool = true;
#[inline]
unsafe fn on_write(this: *mut Self, amount: usize, status: $crate::WriteStatus) {
Expand Down
64 changes: 12 additions & 52 deletions src/react_compiler/hir/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ pub struct OutlinedFunctionEntry {
}

impl Environment {
pub fn new() -> Self {
Self::with_config(EnvironmentConfig::default())
}

/// Create a new Environment with the given configuration.
///
/// Initializes the shape and global registries, registers custom hooks,
Expand Down Expand Up @@ -557,45 +553,6 @@ impl Environment {
None
}

/// Get the type of a named property on a receiver type.
/// Ported from TS `getPropertyType`.
pub fn get_property_type(
&mut self,
receiver: &Type,
property: &[u8],
) -> Result<Option<Type>, CompilerDiagnostic> {
let shape_id = match receiver {
Type::Object { shape_id } | Type::Function { shape_id, .. } => shape_id.as_deref(),
_ => None,
};
if let Some(shape_id) = shape_id {
let shape = self
.shapes
.get(shape_id)
.ok_or_else(|| shape_not_found(shape_id))?;
if let Some(ty) = core::str::from_utf8(property)
.ok()
.and_then(|k| shape.properties.get(k))
{
return Ok(Some(ty.clone()));
}
// Fall through to wildcard
if let Some(ty) = shape.properties.get("*") {
return Ok(Some(ty.clone()));
}
// If property name looks like a hook, return custom hook type
if is_hook_name(property) {
return Ok(Some(self.get_custom_hook_type()));
}
return Ok(None);
}
// No shape ID — if property looks like a hook, return custom hook type
if is_hook_name(property) {
return Ok(Some(self.get_custom_hook_type()));
}
Ok(None)
}

/// Get the function signature for a function type.
/// Ported from TS `getFunctionSignature`.
pub fn get_function_signature(
Expand Down Expand Up @@ -911,7 +868,7 @@ mod tests {

#[test]
fn test_environment_has_globals() {
let env = Environment::new();
let env = Environment::with_config(EnvironmentConfig::default());
assert!(env.globals().contains_key("useState"));
assert!(env.globals().contains_key("useEffect"));
assert!(env.globals().contains_key("useRef"));
Expand All @@ -923,23 +880,26 @@ mod tests {

#[test]
fn test_get_property_type_array() {
let mut env = Environment::new();
let env = Environment::with_config(EnvironmentConfig::default());
let array_type = Type::Object {
shape_id: Some("BuiltInArray"),
};
let map_type = env.get_property_type(&array_type, b"map").unwrap();
let map_type = Environment::get_property_type_from_shapes(&env.shapes, &array_type, b"map");
assert!(map_type.is_some());
let push_type = env.get_property_type(&array_type, b"push").unwrap();
let push_type =
Environment::get_property_type_from_shapes(&env.shapes, &array_type, b"push");
assert!(push_type.is_some());
let nonexistent = env
.get_property_type(&array_type, b"nonExistentMethod")
.unwrap();
let nonexistent = Environment::get_property_type_from_shapes(
&env.shapes,
&array_type,
b"nonExistentMethod",
);
assert!(nonexistent.is_none());
}

#[test]
fn test_get_function_signature() {
let env = Environment::new();
let env = Environment::with_config(EnvironmentConfig::default());
let use_state_type = env.globals().get("useState").unwrap();
let sig = env.get_function_signature(use_state_type).unwrap();
assert!(sig.is_some());
Expand All @@ -950,7 +910,7 @@ mod tests {

#[test]
fn test_get_global_declaration() {
let mut env = Environment::new();
let mut env = Environment::with_config(EnvironmentConfig::default());
// Global binding
let binding = NonLocalBinding {
ref_: bun_ast::Ref::NONE,
Expand Down
5 changes: 1 addition & 4 deletions src/runtime/api/bun/Terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ impl Terminal {
fn on_write(&self, amount: usize, status: WriteStatus) {
bun_output::scoped_log!(Terminal, "onWrite: {} bytes", amount);
let _ = amount;
// POSIX: `PosixStreamingWriter` never dispatches `on_ready`; detect the
// POSIX: `PosixStreamingWriter` has no writable callback; detect the
Comment thread
robobun marked this conversation as resolved.
Resolved
// buffered→drained transition here instead. Windows fires the drain
// callback from `on_writable`, so only record the drained state (a
// stale flag would block `maybe_downgrade_after_eof` forever).
Expand Down Expand Up @@ -2009,9 +2009,6 @@ impl bun_io::pipe_writer::PosixStreamingWriterParent for Terminal {
unsafe fn on_error(this: *mut Self, err: sys::Error) {
Self::from_parent_ptr(this).on_writer_error(&err);
}
unsafe fn on_ready(this: *mut Self) {
Self::from_parent_ptr(this).on_writer_ready();
}
unsafe fn on_close(this: *mut Self) {
Self::from_parent_ptr(this).on_writer_close();
}
Expand Down
Loading
Loading