Skip to content

Commit 6d4dbf0

Browse files
committed
Compilation: use std.Deque
And delete DeprecatedLinearFifo from the source tree.
1 parent 3e77317 commit 6d4dbf0

File tree

3 files changed

+22
-192
lines changed

3 files changed

+22
-192
lines changed

lib/std/deque.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn Deque(comptime T: type) type {
143143
deque.len += 1;
144144
}
145145

146-
/// Add one item to the front of the deque.
146+
/// Add one item to the back of the deque.
147147
///
148148
/// Invalidates element pointers if additional memory is needed.
149149
pub fn pushBack(deque: *Self, gpa: Allocator, item: T) error{OutOfMemory}!void {

src/Compilation.zig

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ const Builtin = @import("Builtin.zig");
4545
const LlvmObject = @import("codegen/llvm.zig").Object;
4646
const dev = @import("dev.zig");
4747

48-
const DeprecatedLinearFifo = @import("deprecated.zig").LinearFifo;
49-
5048
pub const Config = @import("Compilation/Config.zig");
5149

5250
/// General-purpose allocator. Used for both temporary and long-term storage.
@@ -124,20 +122,21 @@ work_queues: [
124122
}
125123
break :len len;
126124
}
127-
]DeprecatedLinearFifo(Job),
125+
]std.Deque(Job),
128126

129127
/// These jobs are to invoke the Clang compiler to create an object file, which
130128
/// gets linked with the Compilation.
131-
c_object_work_queue: DeprecatedLinearFifo(*CObject),
129+
c_object_work_queue: std.Deque(*CObject),
132130

133131
/// These jobs are to invoke the RC compiler to create a compiled resource file (.res), which
134132
/// gets linked with the Compilation.
135-
win32_resource_work_queue: if (dev.env.supports(.win32_resource)) DeprecatedLinearFifo(*Win32Resource) else struct {
136-
pub fn ensureUnusedCapacity(_: @This(), _: u0) error{}!void {}
137-
pub fn readItem(_: @This()) ?noreturn {
133+
win32_resource_work_queue: if (dev.env.supports(.win32_resource)) std.Deque(*Win32Resource) else struct {
134+
pub const empty: @This() = .{};
135+
pub fn ensureUnusedCapacity(_: @This(), _: Allocator, _: u0) error{}!void {}
136+
pub fn popFront(_: @This()) ?noreturn {
138137
return null;
139138
}
140-
pub fn deinit(_: @This()) void {}
139+
pub fn deinit(_: @This(), _: Allocator) void {}
141140
},
142141

143142
/// The ErrorMsg memory is owned by the `CObject`, using Compilation's general purpose allocator.
@@ -2231,9 +2230,9 @@ pub fn create(gpa: Allocator, arena: Allocator, diag: *CreateDiagnostic, options
22312230
.root_mod = options.root_mod,
22322231
.config = options.config,
22332232
.dirs = options.dirs,
2234-
.work_queues = @splat(.init(gpa)),
2235-
.c_object_work_queue = .init(gpa),
2236-
.win32_resource_work_queue = if (dev.env.supports(.win32_resource)) .init(gpa) else .{},
2233+
.work_queues = @splat(.empty),
2234+
.c_object_work_queue = .empty,
2235+
.win32_resource_work_queue = .empty,
22372236
.c_source_files = options.c_source_files,
22382237
.rc_source_files = options.rc_source_files,
22392238
.cache_parent = cache,
@@ -2699,9 +2698,9 @@ pub fn destroy(comp: *Compilation) void {
26992698
if (comp.zcu) |zcu| zcu.deinit();
27002699
comp.cache_use.deinit();
27012700

2702-
for (&comp.work_queues) |*work_queue| work_queue.deinit();
2703-
comp.c_object_work_queue.deinit();
2704-
comp.win32_resource_work_queue.deinit();
2701+
for (&comp.work_queues) |*work_queue| work_queue.deinit(gpa);
2702+
comp.c_object_work_queue.deinit(gpa);
2703+
comp.win32_resource_work_queue.deinit(gpa);
27052704

27062705
for (comp.windows_libs.keys()) |windows_lib| gpa.free(windows_lib);
27072706
comp.windows_libs.deinit(gpa);
@@ -3016,17 +3015,17 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) UpdateE
30163015

30173016
// For compiling C objects, we rely on the cache hash system to avoid duplicating work.
30183017
// Add a Job for each C object.
3019-
try comp.c_object_work_queue.ensureUnusedCapacity(comp.c_object_table.count());
3018+
try comp.c_object_work_queue.ensureUnusedCapacity(gpa, comp.c_object_table.count());
30203019
for (comp.c_object_table.keys()) |c_object| {
3021-
comp.c_object_work_queue.writeItemAssumeCapacity(c_object);
3020+
comp.c_object_work_queue.pushBackAssumeCapacity(c_object);
30223021
try comp.appendFileSystemInput(try .fromUnresolved(arena, comp.dirs, &.{c_object.src.src_path}));
30233022
}
30243023

30253024
// For compiling Win32 resources, we rely on the cache hash system to avoid duplicating work.
30263025
// Add a Job for each Win32 resource file.
3027-
try comp.win32_resource_work_queue.ensureUnusedCapacity(comp.win32_resource_table.count());
3026+
try comp.win32_resource_work_queue.ensureUnusedCapacity(gpa, comp.win32_resource_table.count());
30283027
for (comp.win32_resource_table.keys()) |win32_resource| {
3029-
comp.win32_resource_work_queue.writeItemAssumeCapacity(win32_resource);
3028+
comp.win32_resource_work_queue.pushBackAssumeCapacity(win32_resource);
30303029
switch (win32_resource.src) {
30313030
.rc => |f| {
30323031
try comp.appendFileSystemInput(try .fromUnresolved(arena, comp.dirs, &.{f.src_path}));
@@ -4869,14 +4868,14 @@ fn performAllTheWork(
48694868
}
48704869
}
48714870

4872-
while (comp.c_object_work_queue.readItem()) |c_object| {
4871+
while (comp.c_object_work_queue.popFront()) |c_object| {
48734872
comp.link_task_queue.startPrelinkItem();
48744873
comp.thread_pool.spawnWg(&comp.link_task_wait_group, workerUpdateCObject, .{
48754874
comp, c_object, main_progress_node,
48764875
});
48774876
}
48784877

4879-
while (comp.win32_resource_work_queue.readItem()) |win32_resource| {
4878+
while (comp.win32_resource_work_queue.popFront()) |win32_resource| {
48804879
comp.link_task_queue.startPrelinkItem();
48814880
comp.thread_pool.spawnWg(&comp.link_task_wait_group, workerUpdateWin32Resource, .{
48824881
comp, win32_resource, main_progress_node,
@@ -4996,7 +4995,7 @@ fn performAllTheWork(
49964995
}
49974996

49984997
work: while (true) {
4999-
for (&comp.work_queues) |*work_queue| if (work_queue.readItem()) |job| {
4998+
for (&comp.work_queues) |*work_queue| if (work_queue.popFront()) |job| {
50004999
try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job);
50015000
continue :work;
50025001
};
@@ -5025,7 +5024,7 @@ fn performAllTheWork(
50255024
const JobError = Allocator.Error;
50265025

50275026
pub fn queueJob(comp: *Compilation, job: Job) !void {
5028-
try comp.work_queues[Job.stage(job)].writeItem(job);
5027+
try comp.work_queues[Job.stage(job)].pushBack(comp.gpa, job);
50295028
}
50305029

50315030
pub fn queueJobs(comp: *Compilation, jobs: []const Job) !void {

src/deprecated.zig

Lines changed: 0 additions & 169 deletions
This file was deleted.

0 commit comments

Comments
 (0)