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
6 changes: 0 additions & 6 deletions src/ast/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ impl Error {
}
}

impl bun_core::output::ErrName for Error {
fn name(&self) -> &[u8] {
(*self).name().as_bytes()
}
}

pub type Result<T, E = Error> = core::result::Result<T, E>;
6 changes: 0 additions & 6 deletions src/brotli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,4 @@ impl Error {
}
}

impl bun_core::output::ErrName for Error {
fn name(&self) -> &[u8] {
(*self).name().as_bytes()
}
}

pub type Result<T, E = Error> = core::result::Result<T, E>;
17 changes: 1 addition & 16 deletions src/bun_alloc/MaxHeapAllocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,11 @@ impl MaxHeapAllocator {
}
}

/// RAII guard returned by [`MaxHeapAllocator::scope`]. Derefs to the underlying
/// allocator so callers can hand out `&mut MaxHeapAllocator` (or a derived
/// `&dyn Allocator`) for the duration of the scope, and resets it on drop.
/// RAII guard returned by [`MaxHeapAllocator::scope`]; resets the allocator on drop.
pub struct MaxHeapScope<'a> {
inner: &'a mut MaxHeapAllocator,
}

impl core::ops::Deref for MaxHeapScope<'_> {
type Target = MaxHeapAllocator;
fn deref(&self) -> &Self::Target {
self.inner
}
}

impl core::ops::DerefMut for MaxHeapScope<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.inner
}
}

impl Drop for MaxHeapScope<'_> {
fn drop(&mut self) {
self.inner.reset();
Expand Down
20 changes: 0 additions & 20 deletions src/bun_alloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,26 +568,6 @@ unsafe impl core::alloc::GlobalAlloc for Mimalloc {
}
}

/// Resize a mimalloc-owned buffer, taking a raw pointer for callers that
/// cannot soundly materialize a `&mut [u8]` over their buffer (e.g. it contains
/// uninitialized or padding bytes). Returns the new base pointer;
/// `min(old_size, new_size)` prefix bytes are preserved.
///
/// # Safety
/// `ptr` must be a live allocation from the default (mimalloc) allocator with
/// alignment ≤ `MI_MAX_ALIGN_SIZE`. After return, `ptr` is invalidated.
pub unsafe fn realloc_raw(
ptr: *mut u8,
new_size: usize,
) -> core::result::Result<*mut u8, AllocError> {
// SAFETY: caller guarantees `ptr` is a mimalloc-owned block.
let new_ptr = unsafe { mimalloc::mi_realloc(ptr.cast(), new_size) };
if new_ptr.is_null() {
return Err(AllocError);
}
Ok(new_ptr.cast::<u8>())
}

// ──────────────────────────────────────────────────────────────────────────
// Symbols hoisted DOWN into T0 so higher tiers can re-import without cycles.
// ──────────────────────────────────────────────────────────────────────────
Expand Down
22 changes: 0 additions & 22 deletions src/bun_core/external_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,3 @@ impl<T: ExternalSharedDescriptor> Drop for ExternalShared<T> {
unsafe { T::ext_deref(self.ptr.as_ptr()) };
}
}

// ──────────────────────────────────────────────────────────────────────────
// `WTF::StringImpl` descriptor — lives here (not `bun_string`) because the
// struct is defined in `bun_alloc` and the trait here; orphan rule requires
// one of them to be local. `bun_ptr` already depends on `bun_alloc`.
// ──────────────────────────────────────────────────────────────────────────

// SAFETY: ref/deref delegate to JSC's WTF::StringImpl atomic refcount via FFI;
// the pointee remains valid while count > 0 (JSC contract).
unsafe impl ExternalSharedDescriptor for bun_alloc::WTFStringImplStruct {
unsafe fn ext_ref(this: *mut Self) {
// SAFETY: caller guarantees `this` is a live WTFStringImpl.
unsafe { (*this).r#ref() }
}
unsafe fn ext_deref(this: *mut Self) {
// SAFETY: caller guarantees `this` is a live WTFStringImpl.
unsafe { (*this).deref() }
}
}

/// Behaves like `WTF::Ref<WTF::StringImpl>`.
pub type WTFString = ExternalShared<bun_alloc::WTFStringImplStruct>;
2 changes: 1 addition & 1 deletion src/bun_core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub use string::{StringPointer, Tag, slice_to_nul};
// merge would otherwise cycle). The original crates re-export these.
// ──────────────────────────────────────────────────────────────────────────
pub mod external_shared;
pub use external_shared::{ExternalShared, ExternalSharedDescriptor, WTFString};
pub use external_shared::{ExternalShared, ExternalSharedDescriptor};
pub mod bounded_array;
pub use bounded_array::{BoundedArray, BoundedArrayAligned};

Expand Down
3 changes: 1 addition & 2 deletions src/bun_core/string/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,9 @@ impl StringOrTinyString {
}
}

/// Trait for the `Appender` parameter on `StringOrTinyString::init*_append_if_needed`.
/// Trait for the `Appender` parameter on `StringOrTinyString::init_append_if_needed`.
pub trait Appender {
fn append(&mut self, s: &[u8]) -> Result<&[u8], AllocError>;
fn append_lower_case(&mut self, s: &[u8]) -> Result<&[u8], AllocError>;
}

pub use crate::strings_impl::{ascii_lowercase_buf, copy_lowercase};
Expand Down
6 changes: 0 additions & 6 deletions src/bun_core/string/wtf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ use crate::strings;
// The struct layout lives in `bun_alloc` (lowest-tier crate).
pub use bun_alloc::{WTFStringImpl, WTFStringImplPtr, WTFStringImplStruct};

/// Behaves like `WTF::Ref<WTF::StringImpl>`. The
/// [`crate::external_shared::ExternalSharedDescriptor`] impl lives alongside
/// the trait in `bun_core::external_shared` (orphan rule: trait owner gets
/// the impl since the type is foreign — defined in `bun_alloc`).
pub use crate::external_shared::WTFString;

/// Extension methods on [`WTFStringImplStruct`] that depend on
/// `bun_core` types ([`Utf8Bytes`], `crate::ZBox`) or
/// `crate::strings::*` transcoding. Kept as a trait because the struct is
Expand Down
2 changes: 1 addition & 1 deletion src/bun_core/wtf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ pub fn parse_es5_date(buf: &[u8]) -> Result<f64, InvalidDate> {
// `bun_core::wtf::parse_double` (formerly `bun_core::wtf::parse_double`)
// resolves unchanged.
pub use crate::string::wtf::{
InvalidCharacter, WTFString, WTFStringImpl, WTFStringImplExt, WTFStringImplStruct, parse_double,
InvalidCharacter, WTFStringImpl, WTFStringImplExt, WTFStringImplStruct, parse_double,
};
16 changes: 0 additions & 16 deletions src/bundler/HTMLImportManifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@ pub struct HTMLImportManifest<'a> {
pub(crate) linker_graph: &'a LinkerGraph<'a>,
}

impl<'a> fmt::Display for HTMLImportManifest<'a> {
fn fmt(&self, writer: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut adapter = FmtAdapter::new(writer);
match write(
self.index,
self.graph,
self.linker_graph,
self.chunks,
&mut adapter,
) {
Ok(()) => Ok(()),
Err(_) => Err(fmt::Error),
}
}
}

fn write_entry_item<W: Write + ?Sized>(
writer: &mut W,
input: &[u8],
Expand Down
6 changes: 0 additions & 6 deletions src/clap/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ impl Error {
}
}

impl bun_core::output::ErrName for Error {
fn name(&self) -> &[u8] {
(*self).name().as_bytes()
}
}

impl From<crate::streaming::ArgError> for Error {
fn from(e: crate::streaming::ArgError) -> Self {
match e {
Expand Down
17 changes: 1 addition & 16 deletions src/codegen/bindgenv2/internal/any.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { CodeStyle, Type } from "./base";
import { Type } from "./base";

export const RawAny = new (class extends Type {
get idlType() {
return "::Bun::IDLRawAny";
}
get bindgenType() {
return "bindgen.BindgenRawAny";
}
zigType(style?: CodeStyle) {
return "bun.bun_js.jsc.JSValue";
}
toCpp(value: any): string {
throw RangeError("`RawAny` cannot have a default value");
}
Expand All @@ -19,15 +13,6 @@ export const StrongAny = new (class extends Type {
get idlType() {
return "::Bun::Bindgen::IDLStrongAny";
}
get bindgenType() {
return "bindgen.BindgenStrongAny";
}
zigType(style?: CodeStyle) {
return "bun.bun_js.jsc.Strong";
}
optionalZigType(style?: CodeStyle) {
return this.zigType(style) + ".Optional";
}
toCpp(value: any): string {
throw RangeError("`StrongAny` cannot have a default value");
}
Expand Down
8 changes: 1 addition & 7 deletions src/codegen/bindgenv2/internal/array.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hasRawAny } from "./any";
import { CodeStyle, Type } from "./base";
import { Type } from "./base";

export abstract class ArrayType extends Type {}

Expand All @@ -11,12 +11,6 @@ export function Array(elemType: Type): ArrayType {
get idlType() {
return `::Bun::IDLArray<${elemType.idlType}>`;
}
get bindgenType() {
return `bindgen.BindgenArray(${elemType.bindgenType})`;
}
zigType(style?: CodeStyle) {
return `bun.collections.ArrayListDefault(${elemType.zigType(style)})`;
}
toCpp(value: any[]): string {
const args = `${value.map(elem => elemType.toCpp(elem)).join(", ")}`;
return `${this.idlType}::ImplementationType { ${args} }`;
Expand Down
18 changes: 0 additions & 18 deletions src/codegen/bindgenv2/internal/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import util from "node:util";
import type { NullableType, OptionalType } from "./optional";

/** Default is "compact". */
export type CodeStyle = "compact" | "pretty";

export abstract class Type {
/** Treats `undefined` as a not-provided value. */
get optional(): OptionalType {
Expand All @@ -16,21 +13,6 @@ export abstract class Type {
}

abstract readonly idlType: string;
abstract readonly bindgenType: string;

/**
* This can be overridden to make the generated code clearer. If overridden, it must return an
* expression that evaluates to the same type as `${this.bindgenType}.ZigType`; it should not
* actually change the type.
*/
zigType(style?: CodeStyle): string {
return this.bindgenType + ".ZigType";
}

/** This must be overridden if a custom `OptionalZigType` is defined. */
optionalZigType(style?: CodeStyle): string {
return `?${this.zigType(style)}`;
}

/** Converts a JS value into a C++ expression. Used for default values. */
abstract toCpp(value: any): string;
Expand Down
7 changes: 0 additions & 7 deletions src/codegen/bindgenv2/internal/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { hasRawAny, isAny } from "./any";
import {
addIndent,
CodeStyle,
dedent,
headersForTypes,
joinIndented,
Expand Down Expand Up @@ -70,12 +69,6 @@ export function dictionary(
get idlType() {
return `::Bun::Bindgen::Generated::IDL${name}`;
}
get bindgenType() {
return `bindgen_generated.internal.${name}`;
}
zigType(style?: CodeStyle) {
return `bindgen_generated.${name}`;
}
get dependencies() {
return fullMembers.map(m => m.type);
}
Expand Down
15 changes: 1 addition & 14 deletions src/codegen/bindgenv2/internal/enumeration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import assert from "node:assert";
import util from "node:util";
import {
CodeStyle,
joinIndented,
NamedType,
reindent,
toASCIILiteral,
toQuotedLiteral,
} from "./base";
import { joinIndented, NamedType, reindent, toASCIILiteral, toQuotedLiteral } from "./base";

abstract class EnumType extends NamedType {}

Expand Down Expand Up @@ -61,12 +54,6 @@ export function enumeration(
get idlType() {
return `::Bun::Bindgen::Generated::IDL${name}`;
}
get bindgenType() {
return `bindgen_generated.internal.${name}`;
}
zigType(style?: CodeStyle) {
return `bindgen_generated.${name}`;
}
toCpp(value: string): string {
const index = valueMap.get(value);
if (index == null) {
Expand Down
20 changes: 1 addition & 19 deletions src/codegen/bindgenv2/internal/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { CodeStyle, Type } from "./base";
import { Type } from "./base";

export const ArrayBuffer = new (class extends Type {
get idlType() {
return `::Bun::IDLArrayBufferRef`;
}
get bindgenType() {
return `bindgen.BindgenArrayBuffer`;
}
zigType(style?: CodeStyle) {
return "bun.bun_js.jsc.JSCArrayBuffer.Ref";
}
optionalZigType(style?: CodeStyle) {
return this.zigType(style) + ".Optional";
}
toCpp(value: any): string {
throw RangeError("default values for `ArrayBuffer` are not supported");
}
Expand All @@ -22,15 +13,6 @@ export const Blob = new (class extends Type {
get idlType() {
return `::Bun::IDLBlobRef`;
}
get bindgenType() {
return `bindgen.BindgenBlob`;
}
zigType(style?: CodeStyle) {
return "bun.bun_js.webcore.Blob.Ref";
}
optionalZigType(style?: CodeStyle) {
return this.zigType(style) + ".Optional";
}
toCpp(value: any): string {
throw RangeError("default values for `Blob` are not supported");
}
Expand Down
Loading
Loading