Skip to content

Commit 9176408

Browse files
committed
Target: pass and use locals by pointer instead of by value
This struct is larger than 256 bytes and code that copies it consistently shows up in profiles of the compiler.
1 parent 16d78bc commit 9176408

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+400
-401
lines changed

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn addCmakeCfgOptionsToExe(
759759
use_zig_libcxx: bool,
760760
) !void {
761761
const mod = exe.root_module;
762-
const target = mod.resolved_target.?.result;
762+
const target = &mod.resolved_target.?.result;
763763

764764
if (target.os.tag.isDarwin()) {
765765
// useful for package maintainers

lib/compiler/resinator/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
525525
};
526526
const target = std.zig.resolveTargetQueryOrFatal(target_query);
527527
const is_native_abi = target_query.isNativeAbi();
528-
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, target, is_native_abi, true, null) catch {
528+
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch {
529529
if (includes == .any) {
530530
// fall back to mingw
531531
includes = .gnu;
@@ -550,7 +550,7 @@ fn getIncludePaths(arena: std.mem.Allocator, auto_includes_option: cli.Options.A
550550
};
551551
const target = std.zig.resolveTargetQueryOrFatal(target_query);
552552
const is_native_abi = target_query.isNativeAbi();
553-
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, target, is_native_abi, true, null) catch |err| switch (err) {
553+
const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) {
554554
error.OutOfMemory => |e| return e,
555555
else => return error.MingwIncludesNotFound,
556556
};

lib/compiler_rt/divmodei4.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {
3535

3636
pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
3737
@setRuntimeSafety(builtin.is_test);
38-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
38+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
3939
const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
4040
const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
4141
const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
@@ -44,7 +44,7 @@ pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo
4444

4545
pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
4646
@setRuntimeSafety(builtin.is_test);
47-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
47+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
4848
const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
4949
const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
5050
const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));

lib/compiler_rt/fixdfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixhfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixsfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixtfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixunsdfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixunshfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixunssfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixunstfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixunsxfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.unsigned, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/fixxfei.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return bigIntFromFloat(.signed, @ptrCast(@alignCast(r[0..byte_size])), a);
1515
}

lib/compiler_rt/floateidf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f64, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floateihf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f16, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floateisf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f32, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floateitf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f128, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floateixf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f80, .signed, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floatuneidf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f64, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floatuneihf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f16, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floatuneisf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f32, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floatuneitf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f128, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/floatuneixf.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ comptime {
1010
}
1111

1212
pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 {
13-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
13+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
1414
return floatFromBigInt(f80, .unsigned, @ptrCast(@alignCast(a[0..byte_size])));
1515
}

lib/compiler_rt/udivmodei4.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void {
114114

115115
pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
116116
@setRuntimeSafety(builtin.is_test);
117-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
117+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
118118
const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
119119
const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
120120
const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
@@ -123,7 +123,7 @@ pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) ca
123123

124124
pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void {
125125
@setRuntimeSafety(builtin.is_test);
126-
const byte_size = std.zig.target.intByteSize(builtin.target, @intCast(bits));
126+
const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
127127
const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
128128
const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
129129
const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));

lib/std/Build/Fuzz/WebServer.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ fn serveWasm(
198198
const wasm_base_path = try buildWasmBinary(ws, arena, optimize_mode);
199199
const bin_name = try std.zig.binNameAlloc(arena, .{
200200
.root_name = fuzzer_bin_name,
201-
.target = std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
201+
.target = &(std.zig.system.resolveTargetQuery(std.Build.parseTargetQuery(.{
202202
.arch_os_abi = fuzzer_arch_os_abi,
203203
.cpu_features = fuzzer_cpu_features,
204-
}) catch unreachable) catch unreachable,
204+
}) catch unreachable) catch unreachable),
205205
.output_mode = .Exe,
206206
});
207207
// std.http.Server does not have a sendfile API yet.

lib/std/Build/Module.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,10 @@ fn linkLibraryOrObject(m: *Module, other: *Step.Compile) void {
655655
m.include_dirs.append(allocator, .{ .other_step = other }) catch @panic("OOM");
656656
}
657657

658-
fn requireKnownTarget(m: *Module) std.Target {
659-
const resolved_target = m.resolved_target orelse
660-
@panic("this API requires the Module to be created with a known 'target' field");
661-
return resolved_target.result;
658+
fn requireKnownTarget(m: *Module) *const std.Target {
659+
const resolved_target = &(m.resolved_target orelse
660+
@panic("this API requires the Module to be created with a known 'target' field"));
661+
return &resolved_target.result;
662662
}
663663

664664
/// Elements of `modules` and `names` are matched one-to-one.

lib/std/Build/Step/Compile.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
377377

378378
const resolved_target = options.root_module.resolved_target orelse
379379
@panic("the root Module of a Compile step must be created with a known 'target' field");
380-
const target = resolved_target.result;
380+
const target = &resolved_target.result;
381381

382382
const step_name = owner.fmt("compile {s} {s} {s}", .{
383383
// Avoid the common case of the step name looking like "compile test test".
@@ -1866,7 +1866,7 @@ fn outputPath(c: *Compile, out_dir: std.Build.Cache.Path, ea: std.zig.EmitArtifa
18661866
const arena = c.step.owner.graph.arena;
18671867
const name = ea.cacheName(arena, .{
18681868
.root_name = c.name,
1869-
.target = c.root_module.resolved_target.?.result,
1869+
.target = &c.root_module.resolved_target.?.result,
18701870
.output_mode = switch (c.kind) {
18711871
.lib => .Lib,
18721872
.obj, .test_obj => .Obj,

lib/std/Build/Step/Run.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ fn runCommand(
11081108
const need_cross_libc = exe.is_linking_libc and
11091109
(root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
11101110
const other_target = exe.root_module.resolved_target.?.result;
1111-
switch (std.zig.system.getExternalExecutor(b.graph.host.result, &other_target, .{
1111+
switch (std.zig.system.getExternalExecutor(&b.graph.host.result, &other_target, .{
11121112
.qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
11131113
.link_libc = exe.is_linking_libc,
11141114
})) {

0 commit comments

Comments
 (0)