Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions cmake/sources/ZigSources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ src/bundler/linker_context/writeOutputFilesToDisk.zig
src/bundler/LinkerContext.zig
src/bundler/LinkerGraph.zig
src/bundler/ParseTask.zig
src/bundler/PathToSourceIndexMap.zig
src/bundler/ServerComponentParseTask.zig
src/bundler/ThreadPool.zig
src/bunfig.zig
Expand Down
3 changes: 1 addition & 2 deletions src/bake/DevServer/IncrementalGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,8 @@ pub fn IncrementalGraph(comptime side: bake.Side) type {

// Additionally, clear the cached entry of the file from the path to
// source index map.
const hash = bun.hash(abs_path);
for (&bv2.graph.build_graphs.values) |*map| {
_ = map.remove(hash);
_ = map.remove(abs_path);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/bundler/Graph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pending_items: u32 = 0,
deferred_pending: u32 = 0,

/// A map of build targets to their corresponding module graphs.
build_graphs: std.EnumArray(options.Target, PathToSourceIndexMap) = .initFill(.{}),
build_graphs: std.EnumArray(options.Target, PathToSourceIndexMap),

/// When Server Components is enabled, this holds a list of all boundary
/// files. This happens for all files with a "use <side>" directive.
Expand Down Expand Up @@ -62,8 +62,14 @@ additional_output_files: std.ArrayListUnmanaged(options.OutputFile) = .{},
kit_referenced_server_data: bool,
kit_referenced_client_data: bool,

/// Do any input_files have a secondary_path.len > 0?
///
/// Helps skip a loop.
has_any_secondary_paths: bool = false,

pub const InputFile = struct {
source: Logger.Source,
secondary_path: []const u8 = "",
loader: options.Loader = options.Loader.file,
side_effects: _resolver.SideEffects,
allocator: std.mem.Allocator = bun.default_allocator,
Expand Down
2 changes: 1 addition & 1 deletion src/bundler/LinkerContext.zig
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub const LinkerContext = struct {

for (server_source_indices.slice()) |html_import| {
const source = &input_files[html_import];
const source_index = map.get(source.path.hashKey()) orelse {
const source_index = map.get(source.path.text) orelse {
@panic("Assertion failed: HTML import file not found in pathToSourceIndexMap");
};

Expand Down
13 changes: 6 additions & 7 deletions src/bundler/LinkerGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,12 @@ pub fn load(
for (this.reachable_files) |source_id| {
for (import_records_list[source_id.get()].slice()) |*import_record| {
if (import_record.source_index.isValid() and this.is_scb_bitset.isSet(import_record.source_index.get())) {
import_record.source_index = Index.init(
scb.getReferenceSourceIndex(import_record.source_index.get()) orelse
// If this gets hit, might be fine to switch this to `orelse continue`
// not confident in this assertion
Output.panic("Missing SCB boundary for file #{d}", .{import_record.source_index.get()}),
);
bun.assert(import_record.source_index.isValid()); // did not generate
// Only rewrite if this is an original SCB file, not a reference file
if (scb.getReferenceSourceIndex(import_record.source_index.get())) |ref_index| {
import_record.source_index = Index.init(ref_index);
bun.assert(import_record.source_index.isValid()); // did not generate
}
// If it's already a reference file, leave it as-is
}
}
}
Expand Down
46 changes: 46 additions & 0 deletions src/bundler/PathToSourceIndexMap.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const PathToSourceIndexMap = @This();

/// The lifetime of the keys are not owned by this map.
///
/// We assume it's arena allocated.
map: Map = .{},

const Map = bun.StringHashMapUnmanaged(Index.Int);

pub fn getPath(this: *const PathToSourceIndexMap, path: *const Fs.Path) ?Index.Int {
return this.get(path.text);
}

pub fn get(this: *const PathToSourceIndexMap, text: []const u8) ?Index.Int {
return this.map.get(text);
}

pub fn putPath(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, path: *const Fs.Path, value: Index.Int) bun.OOM!void {
try this.map.put(allocator, path.text, value);
}

pub fn put(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, text: []const u8, value: Index.Int) bun.OOM!void {
try this.map.put(allocator, text, value);
}

pub fn getOrPutPath(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, path: *const Fs.Path) bun.OOM!Map.GetOrPutResult {
return this.getOrPut(allocator, path.text);
}

pub fn getOrPut(this: *PathToSourceIndexMap, allocator: std.mem.Allocator, text: []const u8) bun.OOM!Map.GetOrPutResult {
return try this.map.getOrPut(allocator, text);
}

pub fn remove(this: *PathToSourceIndexMap, text: []const u8) bool {
return this.map.remove(text);
}

pub fn removePath(this: *PathToSourceIndexMap, path: *const Fs.Path) bool {
return this.remove(path.text);
}

const std = @import("std");

const bun = @import("bun");
const Fs = bun.fs;
const Index = bun.ast.Index;
Loading