aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--src/allocators/mimalloc.zig560
-rw-r--r--src/cli/bun_command.zig4
-rw-r--r--src/env_loader.zig26
-rw-r--r--src/exports.zig4
-rw-r--r--src/feature_flags.zig2
-rw-r--r--src/global.zig2
-rw-r--r--src/http.zig20
-rw-r--r--src/javascript/jsc/base.zig2
-rw-r--r--src/javascript/jsc/bindings/bindings-generator.zig1
-rw-r--r--src/javascript/jsc/bindings/header-gen.zig24
-rw-r--r--src/javascript/jsc/typescript.zig2
-rw-r--r--src/js_lexer.zig2
-rw-r--r--src/json_parser.zig2
-rw-r--r--src/main.zig6
-rw-r--r--src/main_api.zig2
-rw-r--r--src/main_javascript.zig8
-rw-r--r--src/memory_allocator.zig129
-rw-r--r--src/query_string_map.zig6
-rw-r--r--src/resolver/resolve_path.zig69
-rw-r--r--src/resolver/resolver.zig148
-rw-r--r--src/resolver/tsconfig_json.zig2
-rw-r--r--src/runtime.zig8
-rw-r--r--src/tagged_pointer.zig11
24 files changed, 890 insertions, 155 deletions
diff --git a/Makefile b/Makefile
index 20aea1dbe..5bf8204e0 100644
--- a/Makefile
+++ b/Makefile
@@ -86,9 +86,12 @@ bun-link-lld-debug:
bun-link-lld-release:
clang++ $(BUN_LLD_FLAGS) \
build/macos-x86_64/bun.o \
+ /usr/local/lib/mimalloc-1.7/libmimalloc.a \
-o build/macos-x86_64/bun \
-Wl,-dead_strip \
- -flto
+ -ftls-model=local-exec \
+ -flto \
+ -O3
# We do this outside of build.zig for performance reasons
# The C compilation stuff with build.zig is really slow and we don't need to run this as often as the rest
diff --git a/src/allocators/mimalloc.zig b/src/allocators/mimalloc.zig
new file mode 100644
index 000000000..ed0a64907
--- /dev/null
+++ b/src/allocators/mimalloc.zig
@@ -0,0 +1,560 @@
+pub usingnamespace @import("std").zig.c_builtins;
+pub const ptrdiff_t = c_long;
+pub const wchar_t = c_int;
+pub const max_align_t = c_longdouble;
+pub extern fn mi_malloc(size: usize) ?*c_void;
+pub extern fn mi_calloc(count: usize, size: usize) ?*c_void;
+pub extern fn mi_realloc(p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_expand(p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_free(p: ?*c_void) void;
+pub extern fn mi_strdup(s: [*c]const u8) [*c]u8;
+pub extern fn mi_strndup(s: [*c]const u8, n: usize) [*c]u8;
+pub extern fn mi_realpath(fname: [*c]const u8, resolved_name: [*c]u8) [*c]u8;
+pub extern fn mi_malloc_small(size: usize) ?*c_void;
+pub extern fn mi_zalloc_small(size: usize) ?*c_void;
+pub extern fn mi_zalloc(size: usize) ?*c_void;
+pub extern fn mi_mallocn(count: usize, size: usize) ?*c_void;
+pub extern fn mi_reallocn(p: ?*c_void, count: usize, size: usize) ?*c_void;
+pub extern fn mi_reallocf(p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_usable_size(p: ?*const c_void) usize;
+pub extern fn mi_good_size(size: usize) usize;
+pub const mi_deferred_free_fun = fn (bool, c_ulonglong, ?*c_void) callconv(.C) void;
+pub extern fn mi_register_deferred_free(deferred_free: ?mi_deferred_free_fun, arg: ?*c_void) void;
+pub const mi_output_fun = fn ([*c]const u8, ?*c_void) callconv(.C) void;
+pub extern fn mi_register_output(out: ?mi_output_fun, arg: ?*c_void) void;
+pub const mi_error_fun = fn (c_int, ?*c_void) callconv(.C) void;
+pub extern fn mi_register_error(fun: ?mi_error_fun, arg: ?*c_void) void;
+pub extern fn mi_collect(force: bool) void;
+pub extern fn mi_version() c_int;
+pub extern fn mi_stats_reset() void;
+pub extern fn mi_stats_merge() void;
+pub extern fn mi_stats_print(out: ?*c_void) void;
+pub extern fn mi_stats_print_out(out: ?mi_output_fun, arg: ?*c_void) void;
+pub extern fn mi_process_init() void;
+pub extern fn mi_thread_init() void;
+pub extern fn mi_thread_done() void;
+pub extern fn mi_thread_stats_print_out(out: ?mi_output_fun, arg: ?*c_void) void;
+pub extern fn mi_process_info(elapsed_msecs: [*c]usize, user_msecs: [*c]usize, system_msecs: [*c]usize, current_rss: [*c]usize, peak_rss: [*c]usize, current_commit: [*c]usize, peak_commit: [*c]usize, page_faults: [*c]usize) void;
+pub extern fn mi_malloc_aligned(size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_malloc_aligned_at(size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_zalloc_aligned(size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_zalloc_aligned_at(size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_calloc_aligned(count: usize, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_calloc_aligned_at(count: usize, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_realloc_aligned(p: ?*c_void, newsize: usize, alignment: usize) ?*c_void;
+pub extern fn mi_realloc_aligned_at(p: ?*c_void, newsize: usize, alignment: usize, offset: usize) ?*c_void;
+pub const struct_mi_heap_s = opaque {};
+pub const mi_heap_t = struct_mi_heap_s;
+pub extern fn mi_heap_new() ?*mi_heap_t;
+pub extern fn mi_heap_delete(heap: ?*mi_heap_t) void;
+pub extern fn mi_heap_destroy(heap: ?*mi_heap_t) void;
+pub extern fn mi_heap_set_default(heap: ?*mi_heap_t) ?*mi_heap_t;
+pub extern fn mi_heap_get_default() ?*mi_heap_t;
+pub extern fn mi_heap_get_backing() ?*mi_heap_t;
+pub extern fn mi_heap_collect(heap: ?*mi_heap_t, force: bool) void;
+pub extern fn mi_heap_malloc(heap: ?*mi_heap_t, size: usize) ?*c_void;
+pub extern fn mi_heap_zalloc(heap: ?*mi_heap_t, size: usize) ?*c_void;
+pub extern fn mi_heap_calloc(heap: ?*mi_heap_t, count: usize, size: usize) ?*c_void;
+pub extern fn mi_heap_mallocn(heap: ?*mi_heap_t, count: usize, size: usize) ?*c_void;
+pub extern fn mi_heap_malloc_small(heap: ?*mi_heap_t, size: usize) ?*c_void;
+pub extern fn mi_heap_realloc(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_heap_reallocn(heap: ?*mi_heap_t, p: ?*c_void, count: usize, size: usize) ?*c_void;
+pub extern fn mi_heap_reallocf(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_heap_strdup(heap: ?*mi_heap_t, s: [*c]const u8) [*c]u8;
+pub extern fn mi_heap_strndup(heap: ?*mi_heap_t, s: [*c]const u8, n: usize) [*c]u8;
+pub extern fn mi_heap_realpath(heap: ?*mi_heap_t, fname: [*c]const u8, resolved_name: [*c]u8) [*c]u8;
+pub extern fn mi_heap_malloc_aligned(heap: ?*mi_heap_t, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_heap_malloc_aligned_at(heap: ?*mi_heap_t, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_heap_zalloc_aligned(heap: ?*mi_heap_t, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_heap_zalloc_aligned_at(heap: ?*mi_heap_t, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_heap_calloc_aligned(heap: ?*mi_heap_t, count: usize, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_heap_calloc_aligned_at(heap: ?*mi_heap_t, count: usize, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_heap_realloc_aligned(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize, alignment: usize) ?*c_void;
+pub extern fn mi_heap_realloc_aligned_at(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_rezalloc(p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_recalloc(p: ?*c_void, newcount: usize, size: usize) ?*c_void;
+pub extern fn mi_rezalloc_aligned(p: ?*c_void, newsize: usize, alignment: usize) ?*c_void;
+pub extern fn mi_rezalloc_aligned_at(p: ?*c_void, newsize: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_recalloc_aligned(p: ?*c_void, newcount: usize, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_recalloc_aligned_at(p: ?*c_void, newcount: usize, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_heap_rezalloc(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_heap_recalloc(heap: ?*mi_heap_t, p: ?*c_void, newcount: usize, size: usize) ?*c_void;
+pub extern fn mi_heap_rezalloc_aligned(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize, alignment: usize) ?*c_void;
+pub extern fn mi_heap_rezalloc_aligned_at(heap: ?*mi_heap_t, p: ?*c_void, newsize: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_heap_recalloc_aligned(heap: ?*mi_heap_t, p: ?*c_void, newcount: usize, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_heap_recalloc_aligned_at(heap: ?*mi_heap_t, p: ?*c_void, newcount: usize, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_heap_contains_block(heap: ?*mi_heap_t, p: ?*const c_void) bool;
+pub extern fn mi_heap_check_owned(heap: ?*mi_heap_t, p: ?*const c_void) bool;
+pub extern fn mi_check_owned(p: ?*const c_void) bool;
+pub const struct_mi_heap_area_s = extern struct {
+ blocks: ?*c_void,
+ reserved: usize,
+ committed: usize,
+ used: usize,
+ block_size: usize,
+};
+pub const mi_heap_area_t = struct_mi_heap_area_s;
+pub const mi_block_visit_fun = fn (?*const mi_heap_t, [*c]const mi_heap_area_t, ?*c_void, usize, ?*c_void) callconv(.C) bool;
+pub extern fn mi_heap_visit_blocks(heap: ?*const mi_heap_t, visit_all_blocks: bool, visitor: ?mi_block_visit_fun, arg: ?*c_void) bool;
+pub extern fn mi_is_in_heap_region(p: ?*const c_void) bool;
+pub extern fn mi_is_redirected() bool;
+pub extern fn mi_reserve_huge_os_pages_interleave(pages: usize, numa_nodes: usize, timeout_msecs: usize) c_int;
+pub extern fn mi_reserve_huge_os_pages_at(pages: usize, numa_node: c_int, timeout_msecs: usize) c_int;
+pub extern fn mi_reserve_os_memory(size: usize, commit: bool, allow_large: bool) c_int;
+pub extern fn mi_manage_os_memory(start: ?*c_void, size: usize, is_committed: bool, is_large: bool, is_zero: bool, numa_node: c_int) bool;
+pub extern fn mi_reserve_huge_os_pages(pages: usize, max_secs: f64, pages_reserved: [*c]usize) c_int;
+pub const mi_option_show_errors: c_int = 0;
+pub const mi_option_show_stats: c_int = 1;
+pub const mi_option_verbose: c_int = 2;
+pub const mi_option_eager_commit: c_int = 3;
+pub const mi_option_eager_region_commit: c_int = 4;
+pub const mi_option_reset_decommits: c_int = 5;
+pub const mi_option_large_os_pages: c_int = 6;
+pub const mi_option_reserve_huge_os_pages: c_int = 7;
+pub const mi_option_reserve_os_memory: c_int = 8;
+pub const mi_option_segment_cache: c_int = 9;
+pub const mi_option_page_reset: c_int = 10;
+pub const mi_option_abandoned_page_reset: c_int = 11;
+pub const mi_option_segment_reset: c_int = 12;
+pub const mi_option_eager_commit_delay: c_int = 13;
+pub const mi_option_reset_delay: c_int = 14;
+pub const mi_option_use_numa_nodes: c_int = 15;
+pub const mi_option_limit_os_alloc: c_int = 16;
+pub const mi_option_os_tag: c_int = 17;
+pub const mi_option_max_errors: c_int = 18;
+pub const mi_option_max_warnings: c_int = 19;
+pub const _mi_option_last: c_int = 20;
+pub const enum_mi_option_e = c_uint;
+pub const mi_option_t = enum_mi_option_e;
+pub extern fn mi_option_is_enabled(option: mi_option_t) bool;
+pub extern fn mi_option_enable(option: mi_option_t) void;
+pub extern fn mi_option_disable(option: mi_option_t) void;
+pub extern fn mi_option_set_enabled(option: mi_option_t, enable: bool) void;
+pub extern fn mi_option_set_enabled_default(option: mi_option_t, enable: bool) void;
+pub extern fn mi_option_get(option: mi_option_t) c_long;
+pub extern fn mi_option_set(option: mi_option_t, value: c_long) void;
+pub extern fn mi_option_set_default(option: mi_option_t, value: c_long) void;
+pub extern fn mi_cfree(p: ?*c_void) void;
+pub extern fn mi__expand(p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_malloc_size(p: ?*const c_void) usize;
+pub extern fn mi_malloc_usable_size(p: ?*const c_void) usize;
+pub extern fn mi_posix_memalign(p: [*c]?*c_void, alignment: usize, size: usize) c_int;
+pub extern fn mi_memalign(alignment: usize, size: usize) ?*c_void;
+pub extern fn mi_valloc(size: usize) ?*c_void;
+pub extern fn mi_pvalloc(size: usize) ?*c_void;
+pub extern fn mi_aligned_alloc(alignment: usize, size: usize) ?*c_void;
+pub extern fn mi_reallocarray(p: ?*c_void, count: usize, size: usize) ?*c_void;
+pub extern fn mi_aligned_recalloc(p: ?*c_void, newcount: usize, size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_aligned_offset_recalloc(p: ?*c_void, newcount: usize, size: usize, alignment: usize, offset: usize) ?*c_void;
+pub extern fn mi_wcsdup(s: [*c]const c_ushort) [*c]c_ushort;
+pub extern fn mi_mbsdup(s: [*c]const u8) [*c]u8;
+pub extern fn mi_dupenv_s(buf: [*c][*c]u8, size: [*c]usize, name: [*c]const u8) c_int;
+pub extern fn mi_wdupenv_s(buf: [*c][*c]c_ushort, size: [*c]usize, name: [*c]const c_ushort) c_int;
+pub extern fn mi_free_size(p: ?*c_void, size: usize) void;
+pub extern fn mi_free_size_aligned(p: ?*c_void, size: usize, alignment: usize) void;
+pub extern fn mi_free_aligned(p: ?*c_void, alignment: usize) void;
+pub extern fn mi_new(size: usize) ?*c_void;
+pub extern fn mi_new_aligned(size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_new_nothrow(size: usize) ?*c_void;
+pub extern fn mi_new_aligned_nothrow(size: usize, alignment: usize) ?*c_void;
+pub extern fn mi_new_n(count: usize, size: usize) ?*c_void;
+pub extern fn mi_new_realloc(p: ?*c_void, newsize: usize) ?*c_void;
+pub extern fn mi_new_reallocn(p: ?*c_void, newcount: usize, size: usize) ?*c_void;
+pub const mi_attr_alloc_size = @compileError("unable to translate C expr: unexpected token .Eof"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:66:13
+pub const mi_attr_alloc_size2 = @compileError("unable to translate C expr: unexpected token .Eof"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:67:13
+pub const mi_attr_alloc_align = @compileError("unable to translate C expr: unexpected token .Eof"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:68:13
+pub const offsetof = @compileError("TODO implement function '__builtin_offsetof' in std.zig.c_builtins"); // /Users/jarred/Build/zig/lib/include/stddef.h:104:9
+pub const mi_malloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:279:9
+pub const mi_zalloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:280:9
+pub const mi_calloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:281:9
+pub const mi_mallocn_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:282:9
+pub const mi_reallocn_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:283:9
+pub const mi_recalloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:284:9
+pub const mi_heap_malloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:286:9
+pub const mi_heap_zalloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:287:9
+pub const mi_heap_calloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:288:9
+pub const mi_heap_mallocn_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:289:9
+pub const mi_heap_reallocn_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:290:9
+pub const mi_heap_recalloc_tp = @compileError("unable to translate C expr: unexpected token .RParen"); // /Users/jarred/Downloads/mimalloc-1.7.2/include/mimalloc.h:291:9
+pub const __llvm__ = @as(c_int, 1);
+pub const __clang__ = @as(c_int, 1);
+pub const __clang_major__ = @as(c_int, 12);
+pub const __clang_minor__ = @as(c_int, 0);
+pub const __clang_patchlevel__ = @as(c_int, 1);
+pub const __clang_version__ = "12.0.1 ";
+pub const __GNUC__ = @as(c_int, 4);
+pub const __GNUC_MINOR__ = @as(c_int, 2);
+pub const __GNUC_PATCHLEVEL__ = @as(c_int, 1);
+pub const __GXX_ABI_VERSION = @as(c_int, 1002);
+pub const __ATOMIC_RELAXED = @as(c_int, 0);
+pub const __ATOMIC_CONSUME = @as(c_int, 1);
+pub const __ATOMIC_ACQUIRE = @as(c_int, 2);
+pub const __ATOMIC_RELEASE = @as(c_int, 3);
+pub const __ATOMIC_ACQ_REL = @as(c_int, 4);
+pub const __ATOMIC_SEQ_CST = @as(c_int, 5);
+pub const __OPENCL_MEMORY_SCOPE_WORK_ITEM = @as(c_int, 0);
+pub const __OPENCL_MEMORY_SCOPE_WORK_GROUP = @as(c_int, 1);
+pub const __OPENCL_MEMORY_SCOPE_DEVICE = @as(c_int, 2);
+pub const __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES = @as(c_int, 3);
+pub const __OPENCL_MEMORY_SCOPE_SUB_GROUP = @as(c_int, 4);
+pub const __PRAGMA_REDEFINE_EXTNAME = @as(c_int, 1);
+pub const __VERSION__ = "Homebrew Clang 12.0.1";
+pub const __OBJC_BOOL_IS_BOOL = @as(c_int, 0);
+pub const __CONSTANT_CFSTRINGS__ = @as(c_int, 1);
+pub const __block = __attribute__(__blocks__(byref));
+pub const __BLOCKS__ = @as(c_int, 1);
+pub const __OPTIMIZE__ = @as(c_int, 1);
+pub const __ORDER_LITTLE_ENDIAN__ = @as(c_int, 1234);
+pub const __ORDER_BIG_ENDIAN__ = @as(c_int, 4321);
+pub const __ORDER_PDP_ENDIAN__ = @as(c_int, 3412);
+pub const __BYTE_ORDER__ = __ORDER_LITTLE_ENDIAN__;
+pub const __LITTLE_ENDIAN__ = @as(c_int, 1);
+pub const _LP64 = @as(c_int, 1);
+pub const __LP64__ = @as(c_int, 1);
+pub const __CHAR_BIT__ = @as(c_int, 8);
+pub const __SCHAR_MAX__ = @as(c_int, 127);
+pub const __SHRT_MAX__ = @as(c_int, 32767);
+pub const __INT_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __LONG_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_long, 9223372036854775807, .decimal);
+pub const __LONG_LONG_MAX__ = @as(c_longlong, 9223372036854775807);
+pub const __WCHAR_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __WINT_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __INTMAX_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_long, 9223372036854775807, .decimal);
+pub const __SIZE_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_ulong, 18446744073709551615, .decimal);
+pub const __UINTMAX_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_ulong, 18446744073709551615, .decimal);
+pub const __PTRDIFF_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_long, 9223372036854775807, .decimal);
+pub const __INTPTR_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_long, 9223372036854775807, .decimal);
+pub const __UINTPTR_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_ulong, 18446744073709551615, .decimal);
+pub const __SIZEOF_DOUBLE__ = @as(c_int, 8);
+pub const __SIZEOF_FLOAT__ = @as(c_int, 4);
+pub const __SIZEOF_INT__ = @as(c_int, 4);
+pub const __SIZEOF_LONG__ = @as(c_int, 8);
+pub const __SIZEOF_LONG_DOUBLE__ = @as(c_int, 16);
+pub const __SIZEOF_LONG_LONG__ = @as(c_int, 8);
+pub const __SIZEOF_POINTER__ = @as(c_int, 8);
+pub const __SIZEOF_SHORT__ = @as(c_int, 2);
+pub const __SIZEOF_PTRDIFF_T__ = @as(c_int, 8);
+pub const __SIZEOF_SIZE_T__ = @as(c_int, 8);
+pub const __SIZEOF_WCHAR_T__ = @as(c_int, 4);
+pub const __SIZEOF_WINT_T__ = @as(c_int, 4);
+pub const __SIZEOF_INT128__ = @as(c_int, 16);
+pub const __INTMAX_TYPE__ = c_long;
+pub const __INTMAX_FMTd__ = "ld";
+pub const __INTMAX_FMTi__ = "li";
+pub const __INTMAX_C_SUFFIX__ = L;
+pub const __UINTMAX_TYPE__ = c_ulong;
+pub const __UINTMAX_FMTo__ = "lo";
+pub const __UINTMAX_FMTu__ = "lu";
+pub const __UINTMAX_FMTx__ = "lx";
+pub const __UINTMAX_FMTX__ = "lX";
+pub const __UINTMAX_C_SUFFIX__ = UL;
+pub const __INTMAX_WIDTH__ = @as(c_int, 64);
+pub const __PTRDIFF_TYPE__ = c_long;
+pub const __PTRDIFF_FMTd__ = "ld";
+pub const __PTRDIFF_FMTi__ = "li";
+pub const __PTRDIFF_WIDTH__ = @as(c_int, 64);
+pub const __INTPTR_TYPE__ = c_long;
+pub const __INTPTR_FMTd__ = "ld";
+pub const __INTPTR_FMTi__ = "li";
+pub const __INTPTR_WIDTH__ = @as(c_int, 64);
+pub const __SIZE_TYPE__ = c_ulong;
+pub const __SIZE_FMTo__ = "lo";
+pub const __SIZE_FMTu__ = "lu";
+pub const __SIZE_FMTx__ = "lx";
+pub const __SIZE_FMTX__ = "lX";
+pub const __SIZE_WIDTH__ = @as(c_int, 64);
+pub const __WCHAR_TYPE__ = c_int;
+pub const __WCHAR_WIDTH__ = @as(c_int, 32);
+pub const __WINT_TYPE__ = c_int;
+pub const __WINT_WIDTH__ = @as(c_int, 32);
+pub const __SIG_ATOMIC_WIDTH__ = @as(c_int, 32);
+pub const __SIG_ATOMIC_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __CHAR16_TYPE__ = c_ushort;
+pub const __CHAR32_TYPE__ = c_uint;
+pub const __UINTMAX_WIDTH__ = @as(c_int, 64);
+pub const __UINTPTR_TYPE__ = c_ulong;
+pub const __UINTPTR_FMTo__ = "lo";
+pub const __UINTPTR_FMTu__ = "lu";
+pub const __UINTPTR_FMTx__ = "lx";
+pub const __UINTPTR_FMTX__ = "lX";
+pub const __UINTPTR_WIDTH__ = @as(c_int, 64);
+pub const __FLT_DENORM_MIN__ = @as(f32, 1.40129846e-45);
+pub const __FLT_HAS_DENORM__ = @as(c_int, 1);
+pub const __FLT_DIG__ = @as(c_int, 6);
+pub const __FLT_DECIMAL_DIG__ = @as(c_int, 9);
+pub const __FLT_EPSILON__ = @as(f32, 1.19209290e-7);
+pub const __FLT_HAS_INFINITY__ = @as(c_int, 1);
+pub const __FLT_HAS_QUIET_NAN__ = @as(c_int, 1);
+pub const __FLT_MANT_DIG__ = @as(c_int, 24);
+pub const __FLT_MAX_10_EXP__ = @as(c_int, 38);
+pub const __FLT_MAX_EXP__ = @as(c_int, 128);
+pub const __FLT_MAX__ = @as(f32, 3.40282347e+38);
+pub const __FLT_MIN_10_EXP__ = -@as(c_int, 37);
+pub const __FLT_MIN_EXP__ = -@as(c_int, 125);
+pub const __FLT_MIN__ = @as(f32, 1.17549435e-38);
+pub const __DBL_DENORM_MIN__ = 4.9406564584124654e-324;
+pub const __DBL_HAS_DENORM__ = @as(c_int, 1);
+pub const __DBL_DIG__ = @as(c_int, 15);
+pub const __DBL_DECIMAL_DIG__ = @as(c_int, 17);
+pub const __DBL_EPSILON__ = 2.2204460492503131e-16;
+pub const __DBL_HAS_INFINITY__ = @as(c_int, 1);
+pub const __DBL_HAS_QUIET_NAN__ = @as(c_int, 1);
+pub const __DBL_MANT_DIG__ = @as(c_int, 53);
+pub const __DBL_MAX_10_EXP__ = @as(c_int, 308);
+pub const __DBL_MAX_EXP__ = @as(c_int, 1024);
+pub const __DBL_MAX__ = 1.7976931348623157e+308;
+pub const __DBL_MIN_10_EXP__ = -@as(c_int, 307);
+pub const __DBL_MIN_EXP__ = -@as(c_int, 1021);
+pub const __DBL_MIN__ = 2.2250738585072014e-308;
+pub const __LDBL_DENORM_MIN__ = @as(c_longdouble, 3.64519953188247460253e-4951);
+pub const __LDBL_HAS_DENORM__ = @as(c_int, 1);
+pub const __LDBL_DIG__ = @as(c_int, 18);
+pub const __LDBL_DECIMAL_DIG__ = @as(c_int, 21);
+pub const __LDBL_EPSILON__ = @as(c_longdouble, 1.08420217248550443401e-19);
+pub const __LDBL_HAS_INFINITY__ = @as(c_int, 1);
+pub const __LDBL_HAS_QUIET_NAN__ = @as(c_int, 1);
+pub const __LDBL_MANT_DIG__ = @as(c_int, 64);
+pub const __LDBL_MAX_10_EXP__ = @as(c_int, 4932);
+pub const __LDBL_MAX_EXP__ = @as(c_int, 16384);
+pub const __LDBL_MAX__ = @as(c_longdouble, 1.18973149535723176502e+4932);
+pub const __LDBL_MIN_10_EXP__ = -@as(c_int, 4931);
+pub const __LDBL_MIN_EXP__ = -@as(c_int, 16381);
+pub const __LDBL_MIN__ = @as(c_longdouble, 3.36210314311209350626e-4932);
+pub const __POINTER_WIDTH__ = @as(c_int, 64);
+pub const __BIGGEST_ALIGNMENT__ = @as(c_int, 16);
+pub const __INT8_TYPE__ = i8;
+pub const __INT8_FMTd__ = "hhd";
+pub const __INT8_FMTi__ = "hhi";
+pub const __INT16_TYPE__ = c_short;
+pub const __INT16_FMTd__ = "hd";
+pub const __INT16_FMTi__ = "hi";
+pub const __INT32_TYPE__ = c_int;
+pub const __INT32_FMTd__ = "d";
+pub const __INT32_FMTi__ = "i";
+pub const __INT64_TYPE__ = c_longlong;
+pub const __INT64_FMTd__ = "lld";
+pub const __INT64_FMTi__ = "lli";
+pub const __INT64_C_SUFFIX__ = LL;
+pub const __UINT8_TYPE__ = u8;
+pub const __UINT8_FMTo__ = "hho";
+pub const __UINT8_FMTu__ = "hhu";
+pub const __UINT8_FMTx__ = "hhx";
+pub const __UINT8_FMTX__ = "hhX";
+pub const __UINT8_MAX__ = @as(c_int, 255);
+pub const __INT8_MAX__ = @as(c_int, 127);
+pub const __UINT16_TYPE__ = c_ushort;
+pub const __UINT16_FMTo__ = "ho";
+pub const __UINT16_FMTu__ = "hu";
+pub const __UINT16_FMTx__ = "hx";
+pub const __UINT16_FMTX__ = "hX";
+pub const __UINT16_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 65535, .decimal);
+pub const __INT16_MAX__ = @as(c_int, 32767);
+pub const __UINT32_TYPE__ = c_uint;
+pub const __UINT32_FMTo__ = "o";
+pub const __UINT32_FMTu__ = "u";
+pub const __UINT32_FMTx__ = "x";
+pub const __UINT32_FMTX__ = "X";
+pub const __UINT32_C_SUFFIX__ = U;
+pub const __UINT32_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_uint, 4294967295, .decimal);
+pub const __INT32_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __UINT64_TYPE__ = c_ulonglong;
+pub const __UINT64_FMTo__ = "llo";
+pub const __UINT64_FMTu__ = "llu";
+pub const __UINT64_FMTx__ = "llx";
+pub const __UINT64_FMTX__ = "llX";
+pub const __UINT64_C_SUFFIX__ = ULL;
+pub const __UINT64_MAX__ = @as(c_ulonglong, 18446744073709551615);
+pub const __INT64_MAX__ = @as(c_longlong, 9223372036854775807);
+pub const __INT_LEAST8_TYPE__ = i8;
+pub const __INT_LEAST8_MAX__ = @as(c_int, 127);
+pub const __INT_LEAST8_FMTd__ = "hhd";
+pub const __INT_LEAST8_FMTi__ = "hhi";
+pub const __UINT_LEAST8_TYPE__ = u8;
+pub const __UINT_LEAST8_MAX__ = @as(c_int, 255);
+pub const __UINT_LEAST8_FMTo__ = "hho";
+pub const __UINT_LEAST8_FMTu__ = "hhu";
+pub const __UINT_LEAST8_FMTx__ = "hhx";
+pub const __UINT_LEAST8_FMTX__ = "hhX";
+pub const __INT_LEAST16_TYPE__ = c_short;
+pub const __INT_LEAST16_MAX__ = @as(c_int, 32767);
+pub const __INT_LEAST16_FMTd__ = "hd";
+pub const __INT_LEAST16_FMTi__ = "hi";
+pub const __UINT_LEAST16_TYPE__ = c_ushort;
+pub const __UINT_LEAST16_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 65535, .decimal);
+pub const __UINT_LEAST16_FMTo__ = "ho";
+pub const __UINT_LEAST16_FMTu__ = "hu";
+pub const __UINT_LEAST16_FMTx__ = "hx";
+pub const __UINT_LEAST16_FMTX__ = "hX";
+pub const __INT_LEAST32_TYPE__ = c_int;
+pub const __INT_LEAST32_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __INT_LEAST32_FMTd__ = "d";
+pub const __INT_LEAST32_FMTi__ = "i";
+pub const __UINT_LEAST32_TYPE__ = c_uint;
+pub const __UINT_LEAST32_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_uint, 4294967295, .decimal);
+pub const __UINT_LEAST32_FMTo__ = "o";
+pub const __UINT_LEAST32_FMTu__ = "u";
+pub const __UINT_LEAST32_FMTx__ = "x";
+pub const __UINT_LEAST32_FMTX__ = "X";
+pub const __INT_LEAST64_TYPE__ = c_longlong;
+pub const __INT_LEAST64_MAX__ = @as(c_longlong, 9223372036854775807);
+pub const __INT_LEAST64_FMTd__ = "lld";
+pub const __INT_LEAST64_FMTi__ = "lli";
+pub const __UINT_LEAST64_TYPE__ = c_ulonglong;
+pub const __UINT_LEAST64_MAX__ = @as(c_ulonglong, 18446744073709551615);
+pub const __UINT_LEAST64_FMTo__ = "llo";
+pub const __UINT_LEAST64_FMTu__ = "llu";
+pub const __UINT_LEAST64_FMTx__ = "llx";
+pub const __UINT_LEAST64_FMTX__ = "llX";
+pub const __INT_FAST8_TYPE__ = i8;
+pub const __INT_FAST8_MAX__ = @as(c_int, 127);
+pub const __INT_FAST8_FMTd__ = "hhd";
+pub const __INT_FAST8_FMTi__ = "hhi";
+pub const __UINT_FAST8_TYPE__ = u8;
+pub const __UINT_FAST8_MAX__ = @as(c_int, 255);
+pub const __UINT_FAST8_FMTo__ = "hho";
+pub const __UINT_FAST8_FMTu__ = "hhu";
+pub const __UINT_FAST8_FMTx__ = "hhx";
+pub const __UINT_FAST8_FMTX__ = "hhX";
+pub const __INT_FAST16_TYPE__ = c_short;
+pub const __INT_FAST16_MAX__ = @as(c_int, 32767);
+pub const __INT_FAST16_FMTd__ = "hd";
+pub const __INT_FAST16_FMTi__ = "hi";
+pub const __UINT_FAST16_TYPE__ = c_ushort;
+pub const __UINT_FAST16_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 65535, .decimal);
+pub const __UINT_FAST16_FMTo__ = "ho";
+pub const __UINT_FAST16_FMTu__ = "hu";
+pub const __UINT_FAST16_FMTx__ = "hx";
+pub const __UINT_FAST16_FMTX__ = "hX";
+pub const __INT_FAST32_TYPE__ = c_int;
+pub const __INT_FAST32_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 2147483647, .decimal);
+pub const __INT_FAST32_FMTd__ = "d";
+pub const __INT_FAST32_FMTi__ = "i";
+pub const __UINT_FAST32_TYPE__ = c_uint;
+pub const __UINT_FAST32_MAX__ = @import("std").zig.c_translation.promoteIntLiteral(c_uint, 4294967295, .decimal);
+pub const __UINT_FAST32_FMTo__ = "o";
+pub const __UINT_FAST32_FMTu__ = "u";
+pub const __UINT_FAST32_FMTx__ = "x";
+pub const __UINT_FAST32_FMTX__ = "X";
+pub const __INT_FAST64_TYPE__ = c_longlong;
+pub const __INT_FAST64_MAX__ = @as(c_longlong, 9223372036854775807);
+pub const __INT_FAST64_FMTd__ = "lld";
+pub const __INT_FAST64_FMTi__ = "lli";
+pub const __UINT_FAST64_TYPE__ = c_ulonglong;
+pub const __UINT_FAST64_MAX__ = @as(c_ulonglong, 18446744073709551615);
+pub const __UINT_FAST64_FMTo__ = "llo";
+pub const __UINT_FAST64_FMTu__ = "llu";
+pub const __UINT_FAST64_FMTx__ = "llx";
+pub const __UINT_FAST64_FMTX__ = "llX";
+pub const __USER_LABEL_PREFIX__ = @"_";
+pub const __FINITE_MATH_ONLY__ = @as(c_int, 0);
+pub const __GNUC_STDC_INLINE__ = @as(c_int, 1);
+pub const __GCC_ATOMIC_TEST_AND_SET_TRUEVAL = @as(c_int, 1);
+pub const __CLANG_ATOMIC_BOOL_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_CHAR_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_CHAR16_T_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_CHAR32_T_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_WCHAR_T_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_SHORT_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_INT_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_LONG_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_LLONG_LOCK_FREE = @as(c_int, 2);
+pub const __CLANG_ATOMIC_POINTER_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_BOOL_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_CHAR_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_CHAR16_T_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_CHAR32_T_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_WCHAR_T_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_SHORT_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_INT_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_LONG_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_LLONG_LOCK_FREE = @as(c_int, 2);
+pub const __GCC_ATOMIC_POINTER_LOCK_FREE = @as(c_int, 2);
+pub const __PIC__ = @as(c_int, 2);
+pub const __pic__ = @as(c_int, 2);
+pub const __FLT_EVAL_METHOD__ = @as(c_int, 0);
+pub const __FLT_RADIX__ = @as(c_int, 2);
+pub const __DECIMAL_DIG__ = __LDBL_DECIMAL_DIG__;
+pub const __SSP_STRONG__ = @as(c_int, 2);
+pub const __nonnull = _Nonnull;
+pub const __null_unspecified = _Null_unspecified;
+pub const __nullable = _Nullable;
+pub const __GCC_ASM_FLAG_OUTPUTS__ = @as(c_int, 1);
+pub const __code_model_small__ = @as(c_int, 1);
+pub const __amd64__ = @as(c_int, 1);
+pub const __amd64 = @as(c_int, 1);
+pub const __x86_64 = @as(c_int, 1);
+pub const __x86_64__ = @as(c_int, 1);
+pub const __SEG_GS = @as(c_int, 1);
+pub const __SEG_FS = @as(c_int, 1);
+pub const __seg_gs = __attribute__(address_space(@as(c_int, 256)));
+pub const __seg_fs = __attribute__(address_space(@as(c_int, 257)));
+pub const __corei7 = @as(c_int, 1);
+pub const __corei7__ = @as(c_int, 1);
+pub const __tune_corei7__ = @as(c_int, 1);
+pub const __NO_MATH_INLINES = @as(c_int, 1);
+pub const __AES__ = @as(c_int, 1);
+pub const __PCLMUL__ = @as(c_int, 1);
+pub const __LAHF_SAHF__ = @as(c_int, 1);
+pub const __LZCNT__ = @as(c_int, 1);
+pub const __RDRND__ = @as(c_int, 1);
+pub const __FSGSBASE__ = @as(c_int, 1);
+pub const __BMI__ = @as(c_int, 1);
+pub const __BMI2__ = @as(c_int, 1);
+pub const __POPCNT__ = @as(c_int, 1);
+pub const __PRFCHW__ = @as(c_int, 1);
+pub const __RDSEED__ = @as(c_int, 1);
+pub const __ADX__ = @as(c_int, 1);
+pub const __MOVBE__ = @as(c_int, 1);
+pub const __FMA__ = @as(c_int, 1);
+pub const __F16C__ = @as(c_int, 1);
+pub const __FXSR__ = @as(c_int, 1);
+pub const __XSAVE__ = @as(c_int, 1);
+pub const __XSAVEOPT__ = @as(c_int, 1);
+pub const __XSAVEC__ = @as(c_int, 1);
+pub const __XSAVES__ = @as(c_int, 1);
+pub const __CLFLUSHOPT__ = @as(c_int, 1);
+pub const __SGX__ = @as(c_int, 1);
+pub const __INVPCID__ = @as(c_int, 1);
+pub const __AVX2__ = @as(c_int, 1);
+pub const __AVX__ = @as(c_int, 1);
+pub const __SSE4_2__ = @as(c_int, 1);
+pub const __SSE4_1__ = @as(c_int, 1);
+pub const __SSSE3__ = @as(c_int, 1);
+pub const __SSE3__ = @as(c_int, 1);
+pub const __SSE2__ = @as(c_int, 1);
+pub const __SSE2_MATH__ = @as(c_int, 1);
+pub const __SSE__ = @as(c_int, 1);
+pub const __SSE_MATH__ = @as(c_int, 1);
+pub const __MMX__ = @as(c_int, 1);
+pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 = @as(c_int, 1);
+pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 = @as(c_int, 1);
+pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 = @as(c_int, 1);
+pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 = @as(c_int, 1);
+pub const __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 = @as(c_int, 1);
+pub const __APPLE_CC__ = @as(c_int, 6000);
+pub const __APPLE__ = @as(c_int, 1);
+pub const __STDC_NO_THREADS__ = @as(c_int, 1);
+pub const __weak = __attribute__(objc_gc(weak));
+pub const __DYNAMIC__ = @as(c_int, 1);
+pub const __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ = @import("std").zig.c_translation.promoteIntLiteral(c_int, 110502, .decimal);
+pub const __MACH__ = @as(c_int, 1);
+pub const __STDC__ = @as(c_int, 1);
+pub const __STDC_HOSTED__ = @as(c_int, 1);
+pub const __STDC_VERSION__ = @as(c_long, 201710);
+pub const __STDC_UTF_16__ = @as(c_int, 1);
+pub const __STDC_UTF_32__ = @as(c_int, 1);
+pub const _DEBUG = @as(c_int, 1);
+pub const MI_MALLOC_VERSION = @as(c_int, 171);
+pub const mi_decl_nodiscard = __attribute__(warn_unused_result);
+pub const mi_decl_export = __attribute__(visibility("default"));
+pub const mi_attr_malloc = __attribute__(malloc);
+pub const NULL = @import("std").zig.c_translation.cast(?*c_void, @as(c_int, 0));
+pub const bool_1 = bool;
+pub const true_2 = @as(c_int, 1);
+pub const false_3 = @as(c_int, 0);
+pub const __bool_true_false_are_defined = @as(c_int, 1);
+pub const MI_SMALL_WSIZE_MAX = @as(c_int, 128);
+pub const MI_SMALL_SIZE_MAX = MI_SMALL_WSIZE_MAX * @import("std").zig.c_translation.sizeof(?*c_void);
+pub const mi_heap_s = struct_mi_heap_s;
+pub const mi_heap_area_s = struct_mi_heap_area_s;
+pub const mi_option_e = enum_mi_option_e;
diff --git a/src/cli/bun_command.zig b/src/cli/bun_command.zig
index 858e8fc70..169d0ab44 100644
--- a/src/cli/bun_command.zig
+++ b/src/cli/bun_command.zig
@@ -66,7 +66,7 @@ const ServerBundleGeneratorThread = struct {
router: ?Router,
) void {
if (FeatureFlags.parallel_bun) {
- try alloc.setup(std.heap.c_allocator);
+ try alloc.setup(default_allocator);
var stdout_ = std.io.getStdOut();
var stderr_ = std.io.getStdErr();
var output_source = Output.Source.init(stdout_, stderr_);
@@ -80,7 +80,7 @@ const ServerBundleGeneratorThread = struct {
}
}
- _generate(logs, env_loader_, std.heap.c_allocator, transform_args, _filepath, server_conf, route_conf_, router) catch return;
+ _generate(logs, env_loader_, default_allocator, transform_args, _filepath, server_conf, route_conf_, router) catch return;
}
};
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 1a0556455..67e76c224 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -703,10 +703,10 @@ test "DotEnv Loader" {
\\
;
const source = logger.Source.initPathString(".env", VALID_ENV);
- var map = Map.init(std.heap.c_allocator);
+ var map = Map.init(default_allocator);
Parser.parse(
&source,
- std.heap.c_allocator,
+ default_allocator,
&map,
true,
);
@@ -729,9 +729,9 @@ test "DotEnv Loader" {
}
test "DotEnv Process" {
- var map = Map.init(std.heap.c_allocator);
- var process = try std.process.getEnvMap(std.heap.c_allocator);
- var loader = Loader.init(&map, std.heap.c_allocator);
+ var map = Map.init(default_allocator);
+ var process = try std.process.getEnvMap(default_allocator);
+ var loader = Loader.init(&map, default_allocator);
loader.loadProcess();
try expectString(loader.map.get("TMPDIR").?, process.get("TMPDIR").?);
@@ -744,8 +744,8 @@ test "DotEnv Process" {
test "DotEnv Loader.copyForDefine" {
const UserDefine = std.StringArrayHashMap(string);
- var map = Map.init(std.heap.c_allocator);
- var loader = Loader.init(&map, std.heap.c_allocator);
+ var map = Map.init(default_allocator);
+ var loader = Loader.init(&map, default_allocator);
const framework_keys = [_]string{ "process.env.BACON", "process.env.HOSTNAME" };
const framework_values = [_]string{ "true", "\"localhost\"" };
const framework = Api.StringMap{
@@ -767,12 +767,12 @@ test "DotEnv Loader.copyForDefine" {
loader.loadFromString(skip_user_overrides, false);
- var user_defines = UserDefine.init(std.heap.c_allocator);
- var buf = try loader.copyForDefine(UserDefine, &user_defines, framework, .disable, "", std.heap.c_allocator);
+ var user_defines = UserDefine.init(default_allocator);
+ var buf = try loader.copyForDefine(UserDefine, &user_defines, framework, .disable, "", default_allocator);
try expect(user_defines.get("process.env.THIS_SHOULDNT_BE_IN_DEFINES_MAP") == null);
- user_defines = UserDefine.init(std.heap.c_allocator);
+ user_defines = UserDefine.init(default_allocator);
loader.loadFromString(user_overrides, true);
@@ -782,7 +782,7 @@ test "DotEnv Loader.copyForDefine" {
framework,
Api.DotEnvBehavior.load_all,
"",
- std.heap.c_allocator,
+ default_allocator,
);
try expect(user_defines.get("process.env.BACON") != null);
@@ -790,9 +790,9 @@ test "DotEnv Loader.copyForDefine" {
try expectString(user_defines.get("process.env.HOSTNAME").?, "example.com");
try expect(user_defines.get("process.env.THIS_SHOULDNT_BE_IN_DEFINES_MAP") != null);
- user_defines = UserDefine.init(std.heap.c_allocator);
+ user_defines = UserDefine.init(default_allocator);
- buf = try loader.copyForDefine(UserDefine, &user_defines, framework, .prefix, "HO", std.heap.c_allocator);
+ buf = try loader.copyForDefine(UserDefine, &user_defines, framework, .prefix, "HO", default_allocator);
try expectString(user_defines.get("process.env.HOSTNAME").?, "example.com");
try expect(user_defines.get("process.env.THIS_SHOULDNT_BE_IN_DEFINES_MAP") == null);
diff --git a/src/exports.zig b/src/exports.zig
index cf37e8a38..132b52a84 100644
--- a/src/exports.zig
+++ b/src/exports.zig
@@ -5,8 +5,8 @@ usingnamespace @import("global.zig");
const Root = @import("main_wasm.zig").Root;
pub extern fn init() void {
- alloc.dynamic = std.heap.c_allocator;
- alloc.static = std.heap.c_allocator;
+ alloc.dynamic = default_allocator;
+ alloc.static = default_allocator;
}
/// Convert a slice into known memory representation -- enables C ABI
diff --git a/src/feature_flags.zig b/src/feature_flags.zig
index a773213ef..1efb55a10 100644
--- a/src/feature_flags.zig
+++ b/src/feature_flags.zig
@@ -34,6 +34,8 @@ pub const css_supports_fence = true;
pub const enable_entry_cache = true;
pub const enable_bytecode_caching = false;
+pub const verbose_fs = true;
+
pub const watch_directories = true;
// This feature flag exists so when you have defines inside package.json, you can use single quotes in nested strings.
diff --git a/src/global.zig b/src/global.zig
index 7e51ef6ee..780df0f3e 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -1,6 +1,8 @@
const std = @import("std");
pub usingnamespace @import("strings.zig");
+pub const default_allocator = @import("./memory_allocator.zig").c_allocator;
+
pub const C = @import("c.zig");
pub usingnamespace @import("env.zig");
diff --git a/src/http.zig b/src/http.zig
index 9f19d930f..4e08af858 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -721,12 +721,12 @@ pub const RequestContext = struct {
// defer stderr.flush() catch {};
Output.Source.set(&output_source);
- js_ast.Stmt.Data.Store.create(std.heap.c_allocator);
- js_ast.Expr.Data.Store.create(std.heap.c_allocator);
+ js_ast.Stmt.Data.Store.create(default_allocator);
+ js_ast.Expr.Data.Store.create(default_allocator);
defer Output.flush();
var vm = JavaScript.VirtualMachine.init(
- std.heap.c_allocator,
+ default_allocator,
handler.args,
handler.existing_bundle,
handler.log,
@@ -1338,7 +1338,7 @@ pub const RequestContext = struct {
pub fn init(rctx: *RequestContext, _loader: Options.Loader) SocketPrinterInternal {
if (!has_loaded_buffer) {
- buffer = MutableString.init(std.heap.c_allocator, 0) catch unreachable;
+ buffer = MutableString.init(default_allocator, 0) catch unreachable;
has_loaded_buffer = true;
}
@@ -1717,9 +1717,17 @@ pub const Server = struct {
watchlist: watcher.Watchlist,
) void {
if (ctx.javascript_enabled) {
- _onFileUpdate(ctx, events, watchlist, true);
+ if (Output.isEmojiEnabled()) {
+ _onFileUpdate(ctx, events, watchlist, true, true);
+ } else {
+ _onFileUpdate(ctx, events, watchlist, true, false);
+ }
} else {
- _onFileUpdate(ctx, events, watchlist, false);
+ if (Output.isEmojiEnabled()) {
+ _onFileUpdate(ctx, events, watchlist, false, true);
+ } else {
+ _onFileUpdate(ctx, events, watchlist, false, false);
+ }
}
}
diff --git a/src/javascript/jsc/base.zig b/src/javascript/jsc/base.zig
index e17d4c7ab..277dc1a53 100644
--- a/src/javascript/jsc/base.zig
+++ b/src/javascript/jsc/base.zig
@@ -1416,7 +1416,7 @@ pub fn JSError(
}
pub fn getAllocator(ctx: js.JSContextRef) *std.mem.Allocator {
- return std.heap.c_allocator;
+ return default_allocator;
}
pub const JSStringList = std.ArrayList(js.JSStringRef);
diff --git a/src/javascript/jsc/bindings/bindings-generator.zig b/src/javascript/jsc/bindings/bindings-generator.zig
index 71ece7a59..7e23ab636 100644
--- a/src/javascript/jsc/bindings/bindings-generator.zig
+++ b/src/javascript/jsc/bindings/bindings-generator.zig
@@ -1,6 +1,5 @@
const Bindings = @import("bindings.zig");
const HeaderGen = @import("./header-gen.zig").HeaderGen;
-
const std = @import("std");
const builtin = std.builtin;
const io = std.io;
diff --git a/src/javascript/jsc/bindings/header-gen.zig b/src/javascript/jsc/bindings/header-gen.zig
index 8b9bb504e..692f60130 100644
--- a/src/javascript/jsc/bindings/header-gen.zig
+++ b/src/javascript/jsc/bindings/header-gen.zig
@@ -67,15 +67,15 @@ pub fn cTypeLabel(comptime Type: type) ?[]const u8 {
};
}
-var buffer = std.ArrayList(u8).init(std.heap.c_allocator);
+var buffer = std.ArrayList(u8).init(default_allocator);
var writer = buffer.writer();
-var impl_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
+var impl_buffer = std.ArrayList(u8).init(default_allocator);
var impl_writer = impl_buffer.writer();
-var bufset = std.BufSet.init(std.heap.c_allocator);
-var type_names = TypeNameMap.init(std.heap.c_allocator);
-var opaque_types = std.BufSet.init(std.heap.c_allocator);
-var size_map = std.StringHashMap(u32).init(std.heap.c_allocator);
-var align_map = std.StringHashMap(u29).init(std.heap.c_allocator);
+var bufset = std.BufSet.init(default_allocator);
+var type_names = TypeNameMap.init(default_allocator);
+var opaque_types = std.BufSet.init(default_allocator);
+var size_map = std.StringHashMap(u32).init(default_allocator);
+var align_map = std.StringHashMap(u29).init(default_allocator);
pub const C_Generator = struct {
filebase: []const u8,
@@ -618,13 +618,13 @@ pub fn HeaderGen(comptime import: type, comptime fname: []const u8) type {
\\
) catch {};
- var impl_second_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
+ var impl_second_buffer = std.ArrayList(u8).init(default_allocator);
var impl_second_writer = impl_second_buffer.writer();
- var impl_third_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
+ var impl_third_buffer = std.ArrayList(u8).init(default_allocator);
var impl_third_writer = impl_third_buffer.writer();
- var impl_fourth_buffer = std.ArrayList(u8).init(std.heap.c_allocator);
+ var impl_fourth_buffer = std.ArrayList(u8).init(default_allocator);
var impl_fourth_writer = impl_fourth_buffer.writer();
// inline for (import.all_static_externs) |static_extern, i| {
@@ -770,7 +770,7 @@ pub fn HeaderGen(comptime import: type, comptime fname: []const u8) type {
var iter = type_names.iterator();
const NamespaceMap = std.StringArrayHashMap(std.BufMap);
- var namespaces = NamespaceMap.init(std.heap.c_allocator);
+ var namespaces = NamespaceMap.init(default_allocator);
var size_iter = size_map.iterator();
while (size_iter.next()) |size| {
@@ -808,7 +808,7 @@ pub fn HeaderGen(comptime import: type, comptime fname: []const u8) type {
}
if (!namespaces.contains(namespace)) {
- namespaces.put(namespace, std.BufMap.init(std.heap.c_allocator)) catch unreachable;
+ namespaces.put(namespace, std.BufMap.init(default_allocator)) catch unreachable;
}
const class = key[namespace_start + 2 ..];
namespaces.getPtr(namespace).?.put(class, value) catch unreachable;
diff --git a/src/javascript/jsc/typescript.zig b/src/javascript/jsc/typescript.zig
index b2273cfd9..23c0f037e 100644
--- a/src/javascript/jsc/typescript.zig
+++ b/src/javascript/jsc/typescript.zig
@@ -27,7 +27,7 @@ const hidden_globals = [_]d.ts.decl{
const global = JavaScript.GlobalObject.GlobalClass.typescriptDeclaration();
pub fn main() anyerror!void {
- var allocator = std.heap.c_allocator;
+ var allocator = default_allocator;
var argv = std.mem.span(std.os.argv);
var dest = [_]string{ std.mem.span(argv[argv.len - 2]), std.mem.span(argv[argv.len - 1]) };
var stdout = std.io.getStdOut();
diff --git a/src/js_lexer.zig b/src/js_lexer.zig
index 2ddd25f61..507cf7aed 100644
--- a/src/js_lexer.zig
+++ b/src/js_lexer.zig
@@ -2748,7 +2748,7 @@ inline fn float64(num: anytype) f64 {
}
fn test_lexer(contents: []const u8) Lexer {
- alloc.setup(std.heap.c_allocator) catch unreachable;
+ alloc.setup(default_allocator) catch unreachable;
var log = alloc.dynamic.create(logger.Log) catch unreachable;
log.* = logger.Log.init(alloc.dynamic);
var _source = logger.Source.initPathString(
diff --git a/src/json_parser.zig b/src/json_parser.zig
index acd368ab0..0704d1aaa 100644
--- a/src/json_parser.zig
+++ b/src/json_parser.zig
@@ -273,7 +273,7 @@ fn expectPrintedJSON(_contents: string, expected: string) !void {
}
test "ParseJSON" {
- try alloc.setup(std.heap.c_allocator);
+ try alloc.setup(default_allocator);
try expectPrintedJSON("true", "true");
try expectPrintedJSON("false", "false");
try expectPrintedJSON("1", "1");
diff --git a/src/main.zig b/src/main.zig
index 50c22a499..22631e58d 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -27,11 +27,11 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) nore
pub fn main() anyerror!void {
// The memory allocator makes a massive difference.
- // std.heap.raw_c_allocator and std.heap.c_allocator perform similarly.
+ // std.heap.raw_c_allocator and default_allocator perform similarly.
// std.heap.GeneralPurposeAllocator makes this about 3x _slower_ than esbuild.
// var root_alloc = std.heap.ArenaAllocator.init(std.heap.raw_c_allocator);
// var root_alloc_ = &root_alloc.allocator;
- try alloc.setup(std.heap.c_allocator);
+ try alloc.setup(default_allocator);
var stdout = std.io.getStdOut();
// var stdout = std.io.bufferedWriter(stdout_file.writer());
var stderr = std.io.getStdErr();
@@ -39,7 +39,7 @@ pub fn main() anyerror!void {
Output.Source.set(&output_source);
defer Output.flush();
- try cli.Cli.start(std.heap.c_allocator, stdout, stderr, MainPanicHandler);
+ try cli.Cli.start(default_allocator, stdout, stderr, MainPanicHandler);
std.mem.doNotOptimizeAway(JavaScriptVirtualMachine.fetch);
std.mem.doNotOptimizeAway(JavaScriptVirtualMachine.init);
diff --git a/src/main_api.zig b/src/main_api.zig
index 04a93c3b8..ac908b671 100644
--- a/src/main_api.zig
+++ b/src/main_api.zig
@@ -8,7 +8,7 @@ export fn init() void {
return;
}
- alloc.setup(std.heap.c_allocator);
+ alloc.setup(default_allocator);
}
export fn setOptions(options_ptr: [*c]u8, options_len: c_int) void {}
diff --git a/src/main_javascript.zig b/src/main_javascript.zig
index 15eac1467..3258c4c6c 100644
--- a/src/main_javascript.zig
+++ b/src/main_javascript.zig
@@ -33,11 +33,11 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) nore
const constStrToU8 = allocators.constStrToU8;
pub fn main() anyerror!void {
// The memory allocator makes a massive difference.
- // std.heap.raw_c_allocator and std.heap.c_allocator perform similarly.
+ // std.heap.raw_c_allocator and default_allocator perform similarly.
// std.heap.GeneralPurposeAllocator makes this about 3x _slower_ than esbuild.
// var root_alloc = std.heap.ArenaAllocator.init(std.heap.raw_c_allocator);
// var root_alloc_ = &root_alloc.allocator;
- try alloc.setup(std.heap.c_allocator);
+ try alloc.setup(default_allocator);
var stdout = std.io.getStdOut();
// var stdout = std.io.bufferedWriter(stdout_file.writer());
var stderr = std.io.getStdErr();
@@ -49,7 +49,7 @@ pub fn main() anyerror!void {
defer Output.flush();
try Cli.start(
- std.heap.c_allocator,
+ default_allocator,
stdout,
stderr,
);
@@ -371,7 +371,7 @@ pub const Cli = struct {
stderr: Stderr,
args: Api.TransformOptions,
pub fn spawn(this: @This()) !void {
- try alloc.setup(std.heap.c_allocator);
+ try alloc.setup(default_allocator);
var stdout = std.io.getStdOut();
// var stdout = std.io.bufferedWriter(stdout_file.writer());
var stderr = std.io.getStdErr();
diff --git a/src/memory_allocator.zig b/src/memory_allocator.zig
new file mode 100644
index 000000000..3f5a7897c
--- /dev/null
+++ b/src/memory_allocator.zig
@@ -0,0 +1,129 @@
+const mem = @import("std").mem;
+const builtin = @import("std").builtin;
+const std = @import("std");
+
+const mimalloc = @import("./allocators/mimalloc.zig");
+const Allocator = mem.Allocator;
+const assert = std.debug.assert;
+
+const CAllocator = struct {
+ comptime {
+ if (!builtin.link_libc) {
+ @compileError("C allocator is only available when linking against libc");
+ }
+ }
+ pub const supports_malloc_size = true;
+ pub const malloc_size = mimalloc.mi_malloc_size;
+ pub const supports_posix_memalign = true;
+
+ fn getHeader(ptr: [*]u8) *[*]u8 {
+ return @intToPtr(*[*]u8, @ptrToInt(ptr) - @sizeOf(usize));
+ }
+
+ fn alignedAlloc(len: usize, alignment: usize) ?[*]u8 {
+ if (supports_posix_memalign) {
+ // The posix_memalign only accepts alignment values that are a
+ // multiple of the pointer size
+ const eff_alignment = std.math.max(alignment, @sizeOf(usize));
+
+ var aligned_ptr: ?*c_void = undefined;
+ if (mimalloc.mi_posix_memalign(&aligned_ptr, eff_alignment, len) != 0)
+ return null;
+
+ return @ptrCast([*]u8, aligned_ptr);
+ }
+
+ // Thin wrapper around regular malloc, overallocate to account for
+ // alignment padding and store the orignal malloc()'ed pointer before
+ // the aligned address.
+ var unaligned_ptr = @ptrCast([*]u8, mimalloc.mi_malloc(len + alignment - 1 + @sizeOf(usize)) orelse return null);
+ const unaligned_addr = @ptrToInt(unaligned_ptr);
+ const aligned_addr = mem.alignForward(unaligned_addr + @sizeOf(usize), alignment);
+ var aligned_ptr = unaligned_ptr + (aligned_addr - unaligned_addr);
+ getHeader(aligned_ptr).* = unaligned_ptr;
+
+ return aligned_ptr;
+ }
+
+ fn alignedFree(ptr: [*]u8) void {
+ if (supports_posix_memalign) {
+ return mimalloc.mi_free(ptr);
+ }
+
+ const unaligned_ptr = getHeader(ptr).*;
+ mimalloc.mi_free(unaligned_ptr);
+ }
+
+ fn alignedAllocSize(ptr: [*]u8) usize {
+ if (supports_posix_memalign) {
+ return malloc_size(ptr);
+ }
+
+ const unaligned_ptr = getHeader(ptr).*;
+ const delta = @ptrToInt(ptr) - @ptrToInt(unaligned_ptr);
+ return malloc_size(unaligned_ptr) - delta;
+ }
+
+ fn alloc(
+ allocator: *Allocator,
+ len: usize,
+ alignment: u29,
+ len_align: u29,
+ return_address: usize,
+ ) error{OutOfMemory}![]u8 {
+ _ = allocator;
+ _ = return_address;
+ assert(len > 0);
+ assert(std.math.isPowerOfTwo(alignment));
+
+ var ptr = alignedAlloc(len, alignment) orelse return error.OutOfMemory;
+ if (len_align == 0) {
+ return ptr[0..len];
+ }
+ const full_len = init: {
+ if (supports_malloc_size) {
+ const s = alignedAllocSize(ptr);
+ assert(s >= len);
+ break :init s;
+ }
+ break :init len;
+ };
+ return ptr[0..mem.alignBackwardAnyAlign(full_len, len_align)];
+ }
+
+ fn resize(
+ allocator: *Allocator,
+ buf: []u8,
+ buf_align: u29,
+ new_len: usize,
+ len_align: u29,
+ return_address: usize,
+ ) Allocator.Error!usize {
+ _ = allocator;
+ _ = buf_align;
+ _ = return_address;
+ if (new_len == 0) {
+ alignedFree(buf.ptr);
+ return 0;
+ }
+ if (new_len <= buf.len) {
+ return mem.alignAllocLen(buf.len, new_len, len_align);
+ }
+ if (supports_malloc_size) {
+ const full_len = alignedAllocSize(buf.ptr);
+ if (new_len <= full_len) {
+ return mem.alignAllocLen(full_len, new_len, len_align);
+ }
+ }
+ return error.OutOfMemory;
+ }
+};
+
+/// Supports the full Allocator interface, including alignment, and exploiting
+/// `malloc_usable_size` if available. For an allocator that directly calls
+/// `malloc`/`free`, see `raw_c_allocator`.
+pub const c_allocator = &c_allocator_state;
+var c_allocator_state = Allocator{
+ .allocFn = CAllocator.alloc,
+ .resizeFn = CAllocator.resize,
+};
diff --git a/src/query_string_map.zig b/src/query_string_map.zig
index 00b451e9a..c5acd5777 100644
--- a/src/query_string_map.zig
+++ b/src/query_string_map.zig
@@ -1233,12 +1233,12 @@ test "URL - parse" {
test "URL - joinAlloc" {
var url = URL.parse("http://localhost:3000");
- var absolute_url = try url.joinAlloc(std.heap.c_allocator, "/_next/", "src/components", "button", ".js");
+ var absolute_url = try url.joinAlloc(default_allocator, "/_next/", "src/components", "button", ".js");
try expectString("http://localhost:3000/_next/src/components/button.js", absolute_url);
- absolute_url = try url.joinAlloc(std.heap.c_allocator, "compiled-", "src/components", "button", ".js");
+ absolute_url = try url.joinAlloc(default_allocator, "compiled-", "src/components", "button", ".js");
try expectString("http://localhost:3000/compiled-src/components/button.js", absolute_url);
- absolute_url = try url.joinAlloc(std.heap.c_allocator, "compiled-", "", "button", ".js");
+ absolute_url = try url.joinAlloc(default_allocator, "compiled-", "", "button", ".js");
try expectString("http://localhost:3000/compiled-button.js", absolute_url);
}
diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig
index e451db36f..62d951f22 100644
--- a/src/resolver/resolve_path.zig
+++ b/src/resolver/resolve_path.zig
@@ -1,6 +1,7 @@
const tester = @import("../test/tester.zig");
const FeatureFlags = @import("../feature_flags.zig");
+const default_allocator = @import("../memory_allocator.zig").c_allocator;
const std = @import("std");
threadlocal var parser_join_input_buffer: [1024]u8 = undefined;
@@ -352,7 +353,7 @@ pub fn relativeAlloc(allocator: *std.mem.Allocator, from: []const u8, to: []cons
}
test "relative" {
- var t = tester.Tester.t(std.heap.c_allocator);
+ var t = tester.Tester.t(default_allocator);
defer t.report(@src());
const strs = [_][]const u8{
@@ -364,14 +365,14 @@ test "relative" {
"/bar/not-related",
"/bar/file.txt",
};
- _ = t.expect("var/foo", try relativeAlloc(std.heap.c_allocator, "/", "/var/foo/"), @src());
- _ = t.expect("index.js", try relativeAlloc(std.heap.c_allocator, "/app/public/", "/app/public/index.js"), @src());
- _ = t.expect("..", try relativeAlloc(std.heap.c_allocator, "/app/public/index.js", "/app/public/"), @src());
- _ = t.expect("../../src/bacon.ts", try relativeAlloc(std.heap.c_allocator, "/app/public/index.html", "/app/src/bacon.ts"), @src());
+ _ = t.expect("var/foo", try relativeAlloc(default_allocator, "/", "/var/foo/"), @src());
+ _ = t.expect("index.js", try relativeAlloc(default_allocator, "/app/public/", "/app/public/index.js"), @src());
+ _ = t.expect("..", try relativeAlloc(default_allocator, "/app/public/index.js", "/app/public/"), @src());
+ _ = t.expect("../../src/bacon.ts", try relativeAlloc(default_allocator, "/app/public/index.html", "/app/src/bacon.ts"), @src());
}
test "longestCommonPath" {
- var t = tester.Tester.t(std.heap.c_allocator);
+ var t = tester.Tester.t(default_allocator);
defer t.report(@src());
const strs = [_][]const u8{
@@ -909,7 +910,7 @@ pub fn normalizeStringLooseBuf(str: []const u8, buf: []u8, comptime allow_above_
}
test "joinAbsStringPosix" {
- var t = tester.Tester.t(std.heap.c_allocator);
+ var t = tester.Tester.t(default_allocator);
defer t.report(@src());
const string = []const u8;
const cwd = "/Users/jarredsumner/Code/app/";
@@ -961,7 +962,7 @@ test "joinAbsStringPosix" {
}
test "joinAbsStringLoose" {
- var t = tester.Tester.t(std.heap.c_allocator);
+ var t = tester.Tester.t(default_allocator);
defer t.report(@src());
const string = []const u8;
const cwd = "/Users/jarredsumner/Code/app";
@@ -1048,39 +1049,39 @@ test "joinAbsStringLoose" {
}
test "normalizeStringPosix" {
- var t = tester.Tester.t(std.heap.c_allocator);
+ var t = tester.Tester.t(default_allocator);
defer t.report(@src());
// Don't mess up strings that
- _ = t.expect("foo/bar.txt", try normalizeStringAlloc(std.heap.c_allocator, "/foo/bar.txt", true, .posix), @src());
- _ = t.expect("foo/bar.txt", try normalizeStringAlloc(std.heap.c_allocator, "/foo/bar.txt", false, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/foo/bar", true, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/foo/bar", false, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/././foo/././././././bar/../bar/../bar", true, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/foo/bar", false, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/foo/bar//////", false, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/////foo/bar//////", false, .posix), @src());
- _ = t.expect("foo/bar", try normalizeStringAlloc(std.heap.c_allocator, "/////foo/bar", false, .posix), @src());
- _ = t.expect("", try normalizeStringAlloc(std.heap.c_allocator, "/////", false, .posix), @src());
- _ = t.expect("..", try normalizeStringAlloc(std.heap.c_allocator, "../boom/../", true, .posix), @src());
- _ = t.expect("", try normalizeStringAlloc(std.heap.c_allocator, "./", true, .posix), @src());
+ _ = t.expect("foo/bar.txt", try normalizeStringAlloc(default_allocator, "/foo/bar.txt", true, .posix), @src());
+ _ = t.expect("foo/bar.txt", try normalizeStringAlloc(default_allocator, "/foo/bar.txt", false, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar", true, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar", false, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/././foo/././././././bar/../bar/../bar", true, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar", false, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/foo/bar//////", false, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/////foo/bar//////", false, .posix), @src());
+ _ = t.expect("foo/bar", try normalizeStringAlloc(default_allocator, "/////foo/bar", false, .posix), @src());
+ _ = t.expect("", try normalizeStringAlloc(default_allocator, "/////", false, .posix), @src());
+ _ = t.expect("..", try normalizeStringAlloc(default_allocator, "../boom/../", true, .posix), @src());
+ _ = t.expect("", try normalizeStringAlloc(default_allocator, "./", true, .posix), @src());
}
test "normalizeStringWindows" {
- var t = tester.Tester.t(std.heap.c_allocator);
+ var t = tester.Tester.t(default_allocator);
defer t.report(@src());
// Don't mess up strings that
- _ = t.expect("foo\\bar.txt", try normalizeStringAlloc(std.heap.c_allocator, "\\foo\\bar.txt", true, .windows), @src());
- _ = t.expect("foo\\bar.txt", try normalizeStringAlloc(std.heap.c_allocator, "\\foo\\bar.txt", false, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\foo\\bar", true, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\foo\\bar", false, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\.\\.\\foo\\.\\.\\.\\.\\.\\.\\bar\\..\\bar\\..\\bar", true, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\foo\\bar", false, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\foo\\bar\\\\\\\\\\\\", false, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\\\\\\\\\foo\\bar\\\\\\\\\\\\", false, .windows), @src());
- _ = t.expect("foo\\bar", try normalizeStringAlloc(std.heap.c_allocator, "\\\\\\\\\\foo\\bar", false, .windows), @src());
- _ = t.expect("", try normalizeStringAlloc(std.heap.c_allocator, "\\\\\\\\\\", false, .windows), @src());
- _ = t.expect("..", try normalizeStringAlloc(std.heap.c_allocator, "..\\boom\\..\\", true, .windows), @src());
- _ = t.expect("", try normalizeStringAlloc(std.heap.c_allocator, ".\\", true, .windows), @src());
+ _ = t.expect("foo\\bar.txt", try normalizeStringAlloc(default_allocator, "\\foo\\bar.txt", true, .windows), @src());
+ _ = t.expect("foo\\bar.txt", try normalizeStringAlloc(default_allocator, "\\foo\\bar.txt", false, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar", true, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar", false, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\.\\.\\foo\\.\\.\\.\\.\\.\\.\\bar\\..\\bar\\..\\bar", true, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar", false, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\foo\\bar\\\\\\\\\\\\", false, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\\\\\\\\\foo\\bar\\\\\\\\\\\\", false, .windows), @src());
+ _ = t.expect("foo\\bar", try normalizeStringAlloc(default_allocator, "\\\\\\\\\\foo\\bar", false, .windows), @src());
+ _ = t.expect("", try normalizeStringAlloc(default_allocator, "\\\\\\\\\\", false, .windows), @src());
+ _ = t.expect("..", try normalizeStringAlloc(default_allocator, "..\\boom\\..\\", true, .windows), @src());
+ _ = t.expect("", try normalizeStringAlloc(default_allocator, ".\\", true, .windows), @src());
}
diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig
index 8dfcd939a..b104823b0 100644
--- a/src/resolver/resolver.zig
+++ b/src/resolver/resolver.zig
@@ -150,7 +150,12 @@ pub const Result = struct {
};
};
-pub const DirEntryResolveQueueItem = struct { result: allocators.Result, unsafe_path: string };
+pub const DirEntryResolveQueueItem = struct {
+ result: allocators.Result,
+ unsafe_path: string,
+ safe_path: string = "",
+ fd: StoredFileDescriptorType = 0,
+};
threadlocal var _dir_entry_paths_to_resolve: [256]DirEntryResolveQueueItem = undefined;
threadlocal var _open_dirs: [256]std.fs.Dir = undefined;
threadlocal var resolve_without_remapping_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
@@ -903,7 +908,7 @@ pub fn NewResolver(cache_files: bool) type {
return res;
}
- pub fn _loadNodeModules(r: *ThisResolver, import_path: string, kind: ast.ImportKind, _dir_info: *DirInfo) ?MatchResult {
+ inline fn _loadNodeModules(r: *ThisResolver, import_path: string, kind: ast.ImportKind, _dir_info: *DirInfo) ?MatchResult {
var dir_info = _dir_info;
if (r.debug_logs) |*debug| {
debug.addNoteFmt("Searching for {s} in \"node_modules\" directories starting from \"{s}\"", .{ import_path, dir_info.abs_path }) catch {};
@@ -1067,30 +1072,40 @@ pub fn NewResolver(cache_files: bool) type {
}
var i: i32 = 1;
- _dir_entry_paths_to_resolve[0] = (DirEntryResolveQueueItem{ .result = top_result, .unsafe_path = path });
- var top = path;
+ _dir_entry_paths_to_resolve[0] = (DirEntryResolveQueueItem{ .result = top_result, .unsafe_path = path, .safe_path = "" });
+ var top = Dirname.dirname(path);
+
var top_parent: allocators.Result = allocators.Result{
.index = allocators.NotFound,
.hash = 0,
.status = .not_found,
};
const root_path = if (isWindows) std.fs.path.diskDesignator(path) else "/";
+ var rfs: *Fs.FileSystem.RealFS = &r.fs.fs;
+
+ rfs.entries_mutex.lock();
+ defer rfs.entries_mutex.unlock();
- while (std.fs.path.dirname(top)) |_top| {
- var result = try r.dir_cache.getOrPut(_top);
+ while (!strings.eql(top, root_path)) : (top = Dirname.dirname(top)) {
+ var result = try r.dir_cache.getOrPut(top);
if (result.status != .unknown) {
top_parent = result;
break;
}
_dir_entry_paths_to_resolve[@intCast(usize, i)] = DirEntryResolveQueueItem{
- .unsafe_path = _top,
+ .unsafe_path = top,
.result = result,
+ .fd = 0,
};
+
+ if (rfs.entries.get(top)) |top_entry| {
+ _dir_entry_paths_to_resolve[@intCast(usize, i)].safe_path = top_entry.entries.dir;
+ _dir_entry_paths_to_resolve[@intCast(usize, i)].fd = top_entry.entries.fd;
+ }
i += 1;
- top = _top;
}
- if (std.fs.path.dirname(top) == null and !strings.eql(top, root_path)) {
+ if (strings.eql(top, root_path)) {
var result = try r.dir_cache.getOrPut(root_path);
if (result.status != .unknown) {
top_parent = result;
@@ -1098,9 +1113,14 @@ pub fn NewResolver(cache_files: bool) type {
_dir_entry_paths_to_resolve[@intCast(usize, i)] = DirEntryResolveQueueItem{
.unsafe_path = root_path,
.result = result,
+ .fd = 0,
};
+ if (rfs.entries.get(top)) |top_entry| {
+ _dir_entry_paths_to_resolve[@intCast(usize, i)].safe_path = top_entry.entries.dir;
+ _dir_entry_paths_to_resolve[@intCast(usize, i)].fd = top_entry.entries.fd;
+ }
+
i += 1;
- top = root_path;
}
}
@@ -1120,11 +1140,6 @@ pub fn NewResolver(cache_files: bool) type {
}
}
- var rfs: *Fs.FileSystem.RealFS = &r.fs.fs;
-
- rfs.entries_mutex.lock();
- defer rfs.entries_mutex.unlock();
-
// We want to walk in a straight line from the topmost directory to the desired directory
// For each directory we visit, we get the entries, but not traverse into child directories
// (unless those child directores are in the queue)
@@ -1147,22 +1162,24 @@ pub fn NewResolver(cache_files: bool) type {
queue_slice.len -= 1;
var _open_dir: anyerror!std.fs.Dir = undefined;
- if (open_dir_count > 0) {
- _open_dir = _open_dirs[open_dir_count - 1].openDir(
- std.fs.path.basename(queue_top.unsafe_path),
- .{ .iterate = true, .no_follow = !follow_symlinks },
- );
- } else {
- _open_dir = std.fs.openDirAbsolute(
- queue_top.unsafe_path,
- .{
- .iterate = true,
- .no_follow = !follow_symlinks,
- },
- );
+ if (queue_top.fd == 0) {
+ if (open_dir_count > 0) {
+ _open_dir = _open_dirs[open_dir_count - 1].openDir(
+ std.fs.path.basename(queue_top.unsafe_path),
+ .{ .iterate = true, .no_follow = !follow_symlinks },
+ );
+ } else {
+ _open_dir = std.fs.openDirAbsolute(
+ queue_top.unsafe_path,
+ .{
+ .iterate = true,
+ .no_follow = !follow_symlinks,
+ },
+ );
+ }
}
- const open_dir = _open_dir catch |err| {
+ const open_dir = if (queue_top.fd != 0) std.fs.Dir{ .fd = queue_top.fd } else (_open_dir catch |err| {
switch (err) {
error.EACCESS => {},
@@ -1204,41 +1221,53 @@ pub fn NewResolver(cache_files: bool) type {
}
return null;
- };
- Fs.FileSystem.setMaxFd(open_dir.fd);
- // these objects mostly just wrap the file descriptor, so it's fine to keep it.
- _open_dirs[open_dir_count] = open_dir;
- open_dir_count += 1;
-
- // ensure trailing slash
- if (_safe_path == null) {
- // Now that we've opened the topmost directory successfully, it's reasonable to store the slice.
- if (path[path.len - 1] != '/') {
- var parts = [_]string{ path, "/" };
- _safe_path = try r.fs.dirname_store.append(@TypeOf(parts), parts);
- } else {
- _safe_path = try r.fs.dirname_store.append(string, path);
- }
+ });
+
+ if (queue_top.fd == 0) {
+ Fs.FileSystem.setMaxFd(open_dir.fd);
+ // these objects mostly just wrap the file descriptor, so it's fine to keep it.
+ _open_dirs[open_dir_count] = open_dir;
+ open_dir_count += 1;
}
- const safe_path = _safe_path.?;
- var dir_path_i = std.mem.indexOf(u8, safe_path, queue_top.unsafe_path) orelse unreachable;
- const dir_path = safe_path[dir_path_i .. dir_path_i + queue_top.unsafe_path.len];
+ const dir_path = if (queue_top.safe_path.len > 0) queue_top.safe_path else brk: {
+
+ // ensure trailing slash
+ if (_safe_path == null) {
+ // Now that we've opened the topmost directory successfully, it's reasonable to store the slice.
+ if (path[path.len - 1] != std.fs.path.sep) {
+ var parts = [_]string{ path, std.fs.path.sep_str };
+ _safe_path = try r.fs.dirname_store.append(@TypeOf(parts), parts);
+ } else {
+ _safe_path = try r.fs.dirname_store.append(string, path);
+ }
+ }
- var dir_iterator = open_dir.iterate();
+ const safe_path = _safe_path.?;
+
+ var dir_path_i = std.mem.indexOf(u8, safe_path, queue_top.unsafe_path) orelse unreachable;
+ var end = dir_path_i +
+ queue_top.unsafe_path.len;
+
+ // Directories must always end in a trailing slash or else various bugs can occur.
+ // This covers "what happens when the trailing"
+ end += @intCast(usize, @boolToInt(safe_path.len > end and end > 0 and safe_path[end - 1] != std.fs.path.sep and safe_path[end] == std.fs.path.sep));
+ break :brk safe_path[dir_path_i..end];
+ };
var cached_dir_entry_result = rfs.entries.getOrPut(dir_path) catch unreachable;
var dir_entries_option: *Fs.FileSystem.RealFS.EntriesOption = undefined;
- var has_dir_entry_result: bool = false;
+ var needs_iter: bool = true;
if (rfs.entries.atIndex(cached_dir_entry_result.index)) |cached_entry| {
- if (std.meta.activeTag(cached_entry.*) == .entries) {
+ if (cached_entry.* == .entries) {
dir_entries_option = cached_entry;
+ needs_iter = false;
}
}
- if (!has_dir_entry_result) {
+ if (needs_iter) {
dir_entries_option = try rfs.entries.put(&cached_dir_entry_result, .{
.entries = Fs.FileSystem.DirEntry.init(dir_path, r.fs.allocator),
});
@@ -1247,13 +1276,10 @@ pub fn NewResolver(cache_files: bool) type {
Fs.FileSystem.setMaxFd(open_dir.fd);
dir_entries_option.entries.fd = open_dir.fd;
}
-
- has_dir_entry_result = true;
- }
-
- while (try dir_iterator.next()) |_value| {
- const value: std.fs.Dir.Entry = _value;
- dir_entries_option.entries.addEntry(value) catch unreachable;
+ var dir_iterator = open_dir.iterate();
+ while (try dir_iterator.next()) |_value| {
+ dir_entries_option.entries.addEntry(_value) catch unreachable;
+ }
}
const dir_info = try r.dirInfoUncached(
@@ -1779,7 +1805,7 @@ pub fn NewResolver(cache_files: bool) type {
}
}
- const dir_path = std.fs.path.dirname(path) orelse "/";
+ const dir_path = Dirname.dirname(path);
const dir_entry: *Fs.FileSystem.RealFS.EntriesOption = rfs.readDirectory(
dir_path,
@@ -1942,6 +1968,10 @@ pub fn NewResolver(cache_files: bool) type {
// A "node_modules" directory isn't allowed to directly contain another "node_modules" directory
var base = std.fs.path.basename(path);
+
+ // base must
+ if (base.len > 1 and base[base.len - 1] == std.fs.path.sep) base = base[0 .. base.len - 1];
+
// if (entries != null) {
if (!strings.eqlComptime(base, "node_modules")) {
if (entries.getComptimeQuery("node_modules")) |entry| {
diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig
index 33e53e77a..11ecd4c24 100644
--- a/src/resolver/tsconfig_json.zig
+++ b/src/resolver/tsconfig_json.zig
@@ -340,5 +340,5 @@ pub const TSConfigJSON = struct {
};
test "tsconfig.json" {
- try alloc.setup(std.heap.c_allocator);
+ try alloc.setup(default_allocator);
}
diff --git a/src/runtime.zig b/src/runtime.zig
index 7ea59f430..72b97154c 100644
--- a/src/runtime.zig
+++ b/src/runtime.zig
@@ -10,19 +10,19 @@ pub const Runtime = struct {
pub fn sourceContent() string {
if (comptime isDebug) {
var dirpath = std.fs.path.dirname(@src().file).?;
- var env = std.process.getEnvMap(std.heap.c_allocator) catch unreachable;
+ var env = std.process.getEnvMap(default_allocator) catch unreachable;
const dir = std.mem.replaceOwned(
u8,
- std.heap.c_allocator,
+ default_allocator,
dirpath,
"jarred",
env.get("USER").?,
) catch unreachable;
- var runtime_path = std.fs.path.join(std.heap.c_allocator, &[_]string{ dir, "runtime.out.js" }) catch unreachable;
+ var runtime_path = std.fs.path.join(default_allocator, &[_]string{ dir, "runtime.out.js" }) catch unreachable;
const file = std.fs.openFileAbsolute(runtime_path, .{}) catch unreachable;
defer file.close();
- return file.readToEndAlloc(std.heap.c_allocator, (file.stat() catch unreachable).size) catch unreachable;
+ return file.readToEndAlloc(default_allocator, (file.stat() catch unreachable).size) catch unreachable;
} else {
return ProdSourceContent;
}
diff --git a/src/tagged_pointer.zig b/src/tagged_pointer.zig
index c917bcea5..ee1af487f 100644
--- a/src/tagged_pointer.zig
+++ b/src/tagged_pointer.zig
@@ -1,4 +1,5 @@
const std = @import("std");
+usingnamespace @import("./global.zig");
const TagSize = u15;
const AddressableSize = u49;
@@ -133,13 +134,13 @@ test "TaggedPointerUnion" {
// wrong: bool = true,
// };
const Union = TaggedPointerUnion(.{ IntPrimtiive, StringPrimitive, Object });
- var str = try std.heap.c_allocator.create(StringPrimitive);
+ var str = try default_allocator.create(StringPrimitive);
str.* = StringPrimitive{ .val = "hello!" };
var un = Union.init(str);
try std.testing.expect(un.is(StringPrimitive));
try std.testing.expectEqualStrings(un.as(StringPrimitive).val, "hello!");
try std.testing.expect(!un.is(IntPrimtiive));
- const num = try std.heap.c_allocator.create(IntPrimtiive);
+ const num = try default_allocator.create(IntPrimtiive);
num.val = 9999;
var un2 = Union.init(num);
@@ -160,7 +161,7 @@ test "TaggedPointer" {
what: []const u8,
};
- var hello_struct_ptr = try std.heap.c_allocator.create(Hello);
+ var hello_struct_ptr = try default_allocator.create(Hello);
hello_struct_ptr.* = Hello{ .what = "hiiii" };
var tagged = TaggedPointer.init(hello_struct_ptr, 0);
try std.testing.expectEqual(tagged.get(Hello), hello_struct_ptr);
@@ -175,8 +176,8 @@ test "TaggedPointer" {
var i: TagSize = 0;
while (i < std.math.maxInt(TagSize) - 1) : (i += 1) {
- hello_struct_ptr = try std.heap.c_allocator.create(Hello);
- const what = try std.fmt.allocPrint(std.heap.c_allocator, "hiiii {d}", .{i});
+ hello_struct_ptr = try default_allocator.create(Hello);
+ const what = try std.fmt.allocPrint(default_allocator, "hiiii {d}", .{i});
hello_struct_ptr.* = Hello{ .what = what };
try std.testing.expectEqualStrings(TaggedPointer.from(TaggedPointer.init(hello_struct_ptr, i).to()).get(Hello).what, what);
var this = TaggedPointer.from(TaggedPointer.init(hello_struct_ptr, i).to());