authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-20 20:38:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:36-07:00
log996b4118097c747e65ef1127091f7e48a54bfafc
tree3ed4671d2652c99e823b216d0709b6ad932e5cf5
parent4cbc03dce31b63818da1fb47f959b70708683443

Configuration: more type safety for adding data

erased method still exists for when the result will be converted to an int anyway.

2 files changed, 83 insertions(+), 78 deletions(-)

lib/compiler/configurer.zig+63-68
...@@ -166,11 +166,11 @@ const Serialize = struct {...@@ -166,11 +166,11 @@ const Serialize = struct {
166 const wc = s.wc;166 const wc = s.wc;
167 const gop = try s.package_map.getOrPut(arena, b);167 const gop = try s.package_map.getOrPut(arena, b);
168 if (!gop.found_existing) {168 if (!gop.found_existing) {
169 gop.value_ptr.* = @enumFromInt(try wc.addExtra(@as(Configuration.Package, .{169 gop.value_ptr.* = try wc.addExtra(Configuration.Package, .{
170 .hash = try wc.addString(b.pkg_hash),170 .hash = try wc.addString(b.pkg_hash),
171 .dep_prefix = try wc.addString(b.dep_prefix),171 .dep_prefix = try wc.addString(b.dep_prefix),
172 .root_path = try wc.addString(try b.root.toString(arena)),172 .root_path = try wc.addString(try b.root.toString(arena)),
173 })));173 });
174 }174 }
175 return gop.value_ptr.*;175 return gop.value_ptr.*;
176 }176 }
...@@ -180,38 +180,38 @@ const Serialize = struct {...@@ -180,38 +180,38 @@ const Serialize = struct {
180 return @enumFromInt(switch (lp orelse return .none) {180 return @enumFromInt(switch (lp orelse return .none) {
181 .src_path => |src_path| i: {181 .src_path => |src_path| i: {
182 const sub_path = try wc.addString(src_path.sub_path);182 const sub_path = try wc.addString(src_path.sub_path);
183 break :i try wc.addExtra(@as(Configuration.LazyPath.SourcePath, .{183 break :i try wc.addExtraErased(Configuration.LazyPath.SourcePath, .{
184 .owner = try s.builderToPackage(src_path.owner),184 .owner = try s.builderToPackage(src_path.owner),
185 .sub_path = sub_path,185 .sub_path = sub_path,
186 }));186 });
187 },187 },
188 .generated => |generated| i: {188 .generated => |generated| i: {
189 const sub_path = try wc.addString(generated.sub_path);189 const sub_path = try wc.addString(generated.sub_path);
190 break :i try wc.addExtra(@as(Configuration.LazyPath.Generated, .{190 break :i try wc.addExtraErased(Configuration.LazyPath.Generated, .{
191 .flags = .{ .up = @intCast(generated.up) },191 .flags = .{ .up = @intCast(generated.up) },
192 .index = generated.index,192 .index = generated.index,
193 .sub_path = sub_path,193 .sub_path = sub_path,
194 }));194 });
195 },195 },
196 .cwd_relative => |cwd_relative_sub_path| i: {196 .cwd_relative => |cwd_relative_sub_path| i: {
197 const sub_path = try wc.addString(cwd_relative_sub_path);197 const sub_path = try wc.addString(cwd_relative_sub_path);
198 break :i try wc.addExtra(@as(Configuration.LazyPath.Relative, .{198 break :i try wc.addExtraErased(Configuration.LazyPath.Relative, .{
199 .flags = .{ .base = .cwd },199 .flags = .{ .base = .cwd },
200 .sub_path = sub_path,200 .sub_path = sub_path,
201 }));201 });
202 },202 },
203 .relative => |relative| i: {203 .relative => |relative| i: {
204 break :i try wc.addExtra(@as(Configuration.LazyPath.Relative, .{204 break :i try wc.addExtraErased(Configuration.LazyPath.Relative, .{
205 .flags = .{ .base = relative.base },205 .flags = .{ .base = relative.base },
206 .sub_path = relative.sub_path,206 .sub_path = relative.sub_path,
207 }));207 });
208 },208 },
209 .dependency => |dependency| i: {209 .dependency => |dependency| i: {
210 const sub_path = try wc.addString(dependency.sub_path);210 const sub_path = try wc.addString(dependency.sub_path);
211 break :i try wc.addExtra(@as(Configuration.LazyPath.SourcePath, .{211 break :i try wc.addExtraErased(Configuration.LazyPath.SourcePath, .{
212 .owner = try s.builderToPackage(dependency.dependency.builder),212 .owner = try s.builderToPackage(dependency.dependency.builder),
213 .sub_path = sub_path,213 .sub_path = sub_path,
214 }));214 });
215 },215 },
216 });216 });
217 }217 }
...@@ -249,21 +249,21 @@ const Serialize = struct {...@@ -249,21 +249,21 @@ const Serialize = struct {
249 fn addCSourceFile(s: *Serialize, csf: *const std.Build.Module.CSourceFile) !Configuration.CSourceFile.Index {249 fn addCSourceFile(s: *Serialize, csf: *const std.Build.Module.CSourceFile) !Configuration.CSourceFile.Index {
250 const wc = s.wc;250 const wc = s.wc;
251 const args = try initStringList(s, csf.flags);251 const args = try initStringList(s, csf.flags);
252 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFile, .{252 return try wc.addExtra(Configuration.CSourceFile, .{
253 .flags = .{253 .flags = .{
254 .args_len = @intCast(args.len),254 .args_len = @intCast(args.len),
255 .lang = .init(csf.language),255 .lang = .init(csf.language),
256 },256 },
257 .file = try addLazyPath(s, csf.file),257 .file = try addLazyPath(s, csf.file),
258 .args = .{ .slice = args },258 .args = .{ .slice = args },
259 })));259 });
260 }260 }
261261
262 fn addCSourceFiles(s: *Serialize, csf: *const std.Build.Module.CSourceFiles) !Configuration.CSourceFiles.Index {262 fn addCSourceFiles(s: *Serialize, csf: *const std.Build.Module.CSourceFiles) !Configuration.CSourceFiles.Index {
263 const wc = s.wc;263 const wc = s.wc;
264 const sub_paths = try initStringList(s, csf.files);264 const sub_paths = try initStringList(s, csf.files);
265 const args = try initStringList(s, csf.flags);265 const args = try initStringList(s, csf.flags);
266 return @enumFromInt(try wc.addExtra(@as(Configuration.CSourceFiles, .{266 return try wc.addExtra(Configuration.CSourceFiles, .{
267 .flags = .{267 .flags = .{
268 .args_len = @intCast(args.len),268 .args_len = @intCast(args.len),
269 .lang = .init(csf.language),269 .lang = .init(csf.language),
...@@ -271,14 +271,14 @@ const Serialize = struct {...@@ -271,14 +271,14 @@ const Serialize = struct {
271 .root = try addLazyPath(s, csf.root),271 .root = try addLazyPath(s, csf.root),
272 .sub_paths = .{ .slice = sub_paths },272 .sub_paths = .{ .slice = sub_paths },
273 .args = .{ .slice = args },273 .args = .{ .slice = args },
274 })));274 });
275 }275 }
276276
277 fn addRcSourceFile(s: *Serialize, rsf: *const std.Build.Module.RcSourceFile) !Configuration.RcSourceFile.Index {277 fn addRcSourceFile(s: *Serialize, rsf: *const std.Build.Module.RcSourceFile) !Configuration.RcSourceFile.Index {
278 const wc = s.wc;278 const wc = s.wc;
279 const include_paths = try initLazyPathList(s, rsf.include_paths);279 const include_paths = try initLazyPathList(s, rsf.include_paths);
280 const args = try initStringList(s, rsf.flags);280 const args = try initStringList(s, rsf.flags);
281 return @enumFromInt(try wc.addExtra(@as(Configuration.RcSourceFile, .{281 return try wc.addExtra(Configuration.RcSourceFile, .{
282 .flags = .{282 .flags = .{
283 .args_len = @intCast(args.len),283 .args_len = @intCast(args.len),
284 .include_paths = include_paths.len != 0,284 .include_paths = include_paths.len != 0,
...@@ -286,7 +286,7 @@ const Serialize = struct {...@@ -286,7 +286,7 @@ const Serialize = struct {
286 .file = try addLazyPath(s, rsf.file),286 .file = try addLazyPath(s, rsf.file),
287 .include_paths = .{ .slice = include_paths },287 .include_paths = .{ .slice = include_paths },
288 .args = .{ .slice = args },288 .args = .{ .slice = args },
289 })));289 });
290 }290 }
291291
292 fn addEnvironMap(s: *Serialize, opt_map: ?*std.process.Environ.Map) !?Configuration.EnvironMap.Index {292 fn addEnvironMap(s: *Serialize, opt_map: ?*std.process.Environ.Map) !?Configuration.EnvironMap.Index {
...@@ -302,7 +302,7 @@ const Serialize = struct {...@@ -302,7 +302,7 @@ const Serialize = struct {
302 const wc = s.wc;302 const wc = s.wc;
303 const result = try s.arena.alloc(Configuration.Step.Run.Arg.Index, args.len);303 const result = try s.arena.alloc(Configuration.Step.Run.Arg.Index, args.len);
304 for (result, args) |*dest, src| {304 for (result, args) |*dest, src| {
305 dest.* = @enumFromInt(try wc.addExtra(@as(Configuration.Step.Run.Arg, switch (src) {305 dest.* = try wc.addExtra(Configuration.Step.Run.Arg, switch (src) {
306 .artifact => |a| .{306 .artifact => |a| .{
307 .flags = .{307 .flags = .{
308 .tag = .artifact,308 .tag = .artifact,
...@@ -492,7 +492,7 @@ const Serialize = struct {...@@ -492,7 +492,7 @@ const Serialize = struct {
492 .generated = .{ .value = null },492 .generated = .{ .value = null },
493 .target_query = .{ .value = a.target_query.unwrap() },493 .target_query = .{ .value = a.target_query.unwrap() },
494 },494 },
495 })));495 });
496 }496 }
497 return result;497 return result;
498 }498 }
...@@ -580,7 +580,7 @@ const Serialize = struct {...@@ -580,7 +580,7 @@ const Serialize = struct {
580 const c_macros = try initStringList(s, m.c_macros.items);580 const c_macros = try initStringList(s, m.c_macros.items);
581 const export_symbol_names = try initStringList(s, m.export_symbol_names);581 const export_symbol_names = try initStringList(s, m.export_symbol_names);
582582
583 const module_index: Configuration.Module.Index = @enumFromInt(try wc.addExtra(@as(Configuration.Module, .{583 const module_index: Configuration.Module.Index = try wc.addExtra(Configuration.Module, .{
584 .flags = .{584 .flags = .{
585 .optimize = .init(m.optimize),585 .optimize = .init(m.optimize),
586 .strip = .init(m.strip),586 .strip = .init(m.strip),
...@@ -622,7 +622,7 @@ const Serialize = struct {...@@ -622,7 +622,7 @@ const Serialize = struct {
622 .rpaths = .init(rpaths),622 .rpaths = .init(rpaths),
623 .link_objects = .init(link_objects),623 .link_objects = .init(link_objects),
624 .frameworks = .{ .slice = frameworks },624 .frameworks = .{ .slice = frameworks },
625 })));625 });
626626
627 // The import table is the only place that modules can form dependency627 // The import table is the only place that modules can form dependency
628 // loops. Therefore, we populate the module indexes only after adding628 // loops. Therefore, we populate the module indexes only after adding
...@@ -699,12 +699,12 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -699,12 +699,12 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
699 .owner = try s.builderToPackage(step.owner),699 .owner = try s.builderToPackage(step.owner),
700 .deps = deps,700 .deps = deps,
701 .max_rss = .fromBytes(step.max_rss),701 .max_rss = .fromBytes(step.max_rss),
702 .extended = switch (step.tag) {702 .extended = @enumFromInt(switch (step.tag) {
703 .top_level => e: {703 .top_level => e: {
704 const top_level: *Step.TopLevel = @fieldParentPtr("step", step);704 const top_level: *Step.TopLevel = @fieldParentPtr("step", step);
705 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.TopLevel, .{705 break :e try wc.addExtraErased(Configuration.Step.TopLevel, .{
706 .description = try wc.addString(top_level.description),706 .description = try wc.addString(top_level.description),
707 })));707 });
708 },708 },
709 .compile => e: {709 .compile => e: {
710 const c: *Step.Compile = @fieldParentPtr("step", step);710 const c: *Step.Compile = @fieldParentPtr("step", step);
...@@ -712,14 +712,14 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -712,14 +712,14 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
712 const installed_headers: []u32 = try arena.alloc(u32, c.installed_headers.items.len);712 const installed_headers: []u32 = try arena.alloc(u32, c.installed_headers.items.len);
713 for (installed_headers, c.installed_headers.items) |*dst, src| switch (src) {713 for (installed_headers, c.installed_headers.items) |*dst, src| switch (src) {
714 .file => |file| {714 .file => |file| {
715 dst.* = try wc.addExtra(@as(Configuration.Step.Compile.InstalledHeader.File, .{715 dst.* = try wc.addExtraErased(Configuration.Step.Compile.InstalledHeader.File, .{
716 .source = try s.addLazyPath(file.source),716 .source = try s.addLazyPath(file.source),
717 .dest_sub_path = try wc.addString(file.dest_rel_path),717 .dest_sub_path = try wc.addString(file.dest_rel_path),
718 }));718 });
719 },719 },
720 .directory => |directory| {720 .directory => |directory| {
721 const include_extensions = directory.options.include_extensions orelse &.{};721 const include_extensions = directory.options.include_extensions orelse &.{};
722 dst.* = try wc.addExtra(@as(Configuration.Step.Compile.InstalledHeader.Directory, .{722 dst.* = try wc.addExtraErased(Configuration.Step.Compile.InstalledHeader.Directory, .{
723 .flags = .{723 .flags = .{
724 .include_extensions = include_extensions.len != 0,724 .include_extensions = include_extensions.len != 0,
725 .exclude_extensions = directory.options.exclude_extensions.len != 0,725 .exclude_extensions = directory.options.exclude_extensions.len != 0,
...@@ -728,11 +728,11 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -728,11 +728,11 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
728 .dest_sub_path = try wc.addString(directory.dest_rel_path),728 .dest_sub_path = try wc.addString(directory.dest_rel_path),
729 .exclude_extensions = .{ .slice = try s.initStringList(directory.options.exclude_extensions) },729 .exclude_extensions = .{ .slice = try s.initStringList(directory.options.exclude_extensions) },
730 .include_extensions = .{ .slice = try s.initStringList(include_extensions) },730 .include_extensions = .{ .slice = try s.initStringList(include_extensions) },
731 }));731 });
732 },732 },
733 };733 };
734734
735 const extra_index = try wc.addExtra(@as(Configuration.Step.Compile, .{735 break :e try wc.addExtraErased(Configuration.Step.Compile, .{
736 .flags = .{736 .flags = .{
737 .filters_len = c.filters.len != 0,737 .filters_len = c.filters.len != 0,
738 .exec_cmd_args_len = exec_cmd_args.len != 0,738 .exec_cmd_args_len = exec_cmd_args.len != 0,
...@@ -891,13 +891,11 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -891,13 +891,11 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
891 .generated_llvm_bc = .{ .value = c.generated_llvm_bc.unwrap() },891 .generated_llvm_bc = .{ .value = c.generated_llvm_bc.unwrap() },
892 .generated_llvm_ir = .{ .value = c.generated_llvm_ir.unwrap() },892 .generated_llvm_ir = .{ .value = c.generated_llvm_ir.unwrap() },
893 .generated_h = .{ .value = c.generated_h.unwrap() },893 .generated_h = .{ .value = c.generated_h.unwrap() },
894 }));894 });
895
896 break :e @enumFromInt(extra_index);
897 },895 },
898 .install_artifact => e: {896 .install_artifact => e: {
899 const ia: *Step.InstallArtifact = @fieldParentPtr("step", step);897 const ia: *Step.InstallArtifact = @fieldParentPtr("step", step);
900 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.InstallArtifact, .{898 break :e try wc.addExtraErased(Configuration.Step.InstallArtifact, .{
901 .flags = .{899 .flags = .{
902 .dylib_symlinks = ia.dylib_symlinks,900 .dylib_symlinks = ia.dylib_symlinks,
903 .bin_dir = ia.dest_dir != null,901 .bin_dir = ia.dest_dir != null,
...@@ -911,15 +909,15 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -911,15 +909,15 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
911 .pdb_dir = .{ .value = try addInstallDirDefaultNull(wc, ia.pdb_dir) },909 .pdb_dir = .{ .value = try addInstallDirDefaultNull(wc, ia.pdb_dir) },
912 .h_dir = .{ .value = try addInstallDirDefaultNull(wc, ia.h_dir) },910 .h_dir = .{ .value = try addInstallDirDefaultNull(wc, ia.h_dir) },
913 .bin_sub_path = .{ .value = try s.addOptionalString(ia.dest_sub_path) },911 .bin_sub_path = .{ .value = try s.addOptionalString(ia.dest_sub_path) },
914 })));912 });
915 },913 },
916 .install_file => e: {914 .install_file => e: {
917 const sif: *Step.InstallFile = @fieldParentPtr("step", step);915 const sif: *Step.InstallFile = @fieldParentPtr("step", step);
918 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.InstallFile, .{916 break :e try wc.addExtraErased(Configuration.Step.InstallFile, .{
919 .source = try s.addLazyPath(sif.source),917 .source = try s.addLazyPath(sif.source),
920 .dest_dir = try addInstallDir(wc, sif.dir),918 .dest_dir = try addInstallDir(wc, sif.dir),
921 .dest_sub_path = try wc.addString(sif.dest_rel_path),919 .dest_sub_path = try wc.addString(sif.dest_rel_path),
922 })));920 });
923 },921 },
924 .install_dir => e: {922 .install_dir => e: {
925 const sid: *Step.InstallDir = @fieldParentPtr("step", step);923 const sid: *Step.InstallDir = @fieldParentPtr("step", step);
...@@ -928,7 +926,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -928,7 +926,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
928 else926 else
929 null;927 null;
930 const include_extensions = sid.options.include_extensions orelse &.{};928 const include_extensions = sid.options.include_extensions orelse &.{};
931 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.InstallDir, .{929 break :e try wc.addExtraErased(Configuration.Step.InstallDir, .{
932 .flags = .{930 .flags = .{
933 .dest_sub_path = dest_sub_path != null,931 .dest_sub_path = dest_sub_path != null,
934 .exclude_extensions = sid.options.exclude_extensions.len != 0,932 .exclude_extensions = sid.options.exclude_extensions.len != 0,
...@@ -942,18 +940,18 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -942,18 +940,18 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
942 .exclude_extensions = .{ .slice = try s.initStringList(sid.options.exclude_extensions) },940 .exclude_extensions = .{ .slice = try s.initStringList(sid.options.exclude_extensions) },
943 .include_extensions = .{ .slice = try s.initStringList(include_extensions) },941 .include_extensions = .{ .slice = try s.initStringList(include_extensions) },
944 .blank_extensions = .{ .slice = try s.initStringList(sid.options.blank_extensions) },942 .blank_extensions = .{ .slice = try s.initStringList(sid.options.blank_extensions) },
945 })));943 });
946 },944 },
947 .fail => e: {945 .fail => e: {
948 const sf: *Step.Fail = @fieldParentPtr("step", step);946 const sf: *Step.Fail = @fieldParentPtr("step", step);
949 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.Fail, .{947 break :e try wc.addExtraErased(Configuration.Step.Fail, .{
950 .msg = sf.error_msg,948 .msg = sf.error_msg,
951 })));949 });
952 },950 },
953 .find_program => @panic("TODO"),951 .find_program => @panic("TODO"),
954 .fmt => e: {952 .fmt => e: {
955 const sf: *Step.Fmt = @fieldParentPtr("step", step);953 const sf: *Step.Fmt = @fieldParentPtr("step", step);
956 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.Fmt, .{954 break :e try wc.addExtraErased(Configuration.Step.Fmt, .{
957 .flags = .{955 .flags = .{
958 .paths = sf.paths.len != 0,956 .paths = sf.paths.len != 0,
959 .exclude_paths = sf.exclude_paths.len != 0,957 .exclude_paths = sf.exclude_paths.len != 0,
...@@ -961,7 +959,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -961,7 +959,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
961 },959 },
962 .paths = .{ .slice = try s.initLazyPathList(sf.paths) },960 .paths = .{ .slice = try s.initLazyPathList(sf.paths) },
963 .exclude_paths = .{ .slice = try s.initLazyPathList(sf.exclude_paths) },961 .exclude_paths = .{ .slice = try s.initLazyPathList(sf.exclude_paths) },
964 })));962 });
965 },963 },
966 .translate_c => e: {964 .translate_c => e: {
967 const tc: *Step.TranslateC = @fieldParentPtr("step", step);965 const tc: *Step.TranslateC = @fieldParentPtr("step", step);
...@@ -969,7 +967,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -969,7 +967,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
969 const system_libs = try arena.alloc(Configuration.SystemLib.Index, tc.system_libs.items.len);967 const system_libs = try arena.alloc(Configuration.SystemLib.Index, tc.system_libs.items.len);
970 for (system_libs, tc.system_libs.items) |*dest, *src| dest.* = try s.addSystemLib(src);968 for (system_libs, tc.system_libs.items) |*dest, *src| dest.* = try s.addSystemLib(src);
971969
972 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.TranslateC, .{970 break :e try wc.addExtraErased(Configuration.Step.TranslateC, .{
973 .flags = .{971 .flags = .{
974 .include_dirs = tc.include_dirs.items.len != 0,972 .include_dirs = tc.include_dirs.items.len != 0,
975 .system_libs = system_libs.len != 0,973 .system_libs = system_libs.len != 0,
...@@ -983,7 +981,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -983,7 +981,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
983 .system_libs = .{ .slice = system_libs },981 .system_libs = .{ .slice = system_libs },
984 .c_macros = .{ .slice = tc.c_macros.items },982 .c_macros = .{ .slice = tc.c_macros.items },
985 .target = try addOptionalResolvedTarget(wc, tc.target),983 .target = try addOptionalResolvedTarget(wc, tc.target),
986 })));984 });
987 },985 },
988 .write_file => e: {986 .write_file => e: {
989 const wf: *Step.WriteFile = @fieldParentPtr("step", step);987 const wf: *Step.WriteFile = @fieldParentPtr("step", step);
...@@ -999,7 +997,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -999,7 +997,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
999 .include_extensions = src.include_extensions,997 .include_extensions = src.include_extensions,
1000 };998 };
1001999
1002 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.WriteFile, .{1000 break :e try wc.addExtraErased(Configuration.Step.WriteFile, .{
1003 .flags = .{1001 .flags = .{
1004 .embeds = wf.embeds.items.len != 0,1002 .embeds = wf.embeds.items.len != 0,
1005 .copies = wf.copies.items.len != 0,1003 .copies = wf.copies.items.len != 0,
...@@ -1018,18 +1016,18 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1018,18 +1016,18 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1018 .mutate => |lp| try s.addLazyPath(lp),1016 .mutate => |lp| try s.addLazyPath(lp),
1019 .whole_cached, .tmp => null,1017 .whole_cached, .tmp => null,
1020 } },1018 } },
1021 })));1019 });
1022 },1020 },
1023 .update_source_files => e: {1021 .update_source_files => e: {
1024 const usf: *Step.UpdateSourceFiles = @fieldParentPtr("step", step);1022 const usf: *Step.UpdateSourceFiles = @fieldParentPtr("step", step);
1025 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.UpdateSourceFiles, .{1023 break :e try wc.addExtraErased(Configuration.Step.UpdateSourceFiles, .{
1026 .flags = .{1024 .flags = .{
1027 .embeds = usf.embeds.items.len != 0,1025 .embeds = usf.embeds.items.len != 0,
1028 .copies = usf.copies.items.len != 0,1026 .copies = usf.copies.items.len != 0,
1029 },1027 },
1030 .embeds = .{ .slice = usf.embeds.items },1028 .embeds = .{ .slice = usf.embeds.items },
1031 .copies = .{ .slice = try s.initCopyList(usf.copies.items) },1029 .copies = .{ .slice = try s.initCopyList(usf.copies.items) },
1032 })));1030 });
1033 },1031 },
1034 .run => e: {1032 .run => e: {
1035 const run: *Step.Run = @fieldParentPtr("step", step);1033 const run: *Step.Run = @fieldParentPtr("step", step);
...@@ -1061,7 +1059,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1061,7 +1059,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1061 else => {},1059 else => {},
1062 }1060 }
10631061
1064 const extra_index = try wc.addExtra(@as(Configuration.Step.Run, .{1062 break :e try wc.addExtraErased(Configuration.Step.Run, .{
1065 .flags = .{1063 .flags = .{
1066 .disable_zig_progress = run.disable_zig_progress,1064 .disable_zig_progress = run.disable_zig_progress,
1067 .skip_foreign_checks = run.skip_foreign_checks,1065 .skip_foreign_checks = run.skip_foreign_checks,
...@@ -1121,12 +1119,11 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1121,12 +1119,11 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1121 .bytes => |bytes| .{ .bytes = try wc.addBytes(bytes) },1119 .bytes => |bytes| .{ .bytes = try wc.addBytes(bytes) },
1122 .lazy_path => |lp| .{ .lazy_path = try s.addLazyPath(lp) },1120 .lazy_path => |lp| .{ .lazy_path = try s.addLazyPath(lp) },
1123 } },1121 } },
1124 }));1122 });
1125 break :e @enumFromInt(extra_index);
1126 },1123 },
1127 .check_file => e: {1124 .check_file => e: {
1128 const cf: *Step.CheckFile = @fieldParentPtr("step", step);1125 const cf: *Step.CheckFile = @fieldParentPtr("step", step);
1129 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.CheckFile, .{1126 break :e try wc.addExtraErased(Configuration.Step.CheckFile, .{
1130 .flags = .{1127 .flags = .{
1131 .expected_exact = cf.expected_exact != null,1128 .expected_exact = cf.expected_exact != null,
1132 .expected_matches = cf.expected_matches.len != 0,1129 .expected_matches = cf.expected_matches.len != 0,
...@@ -1136,7 +1133,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1136,7 +1133,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1136 .expected_exact = .{ .value = cf.expected_exact },1133 .expected_exact = .{ .value = cf.expected_exact },
1137 .expected_matches = .{ .slice = cf.expected_matches },1134 .expected_matches = .{ .slice = cf.expected_matches },
1138 .max_bytes = .{ .value = cf.max_bytes },1135 .max_bytes = .{ .value = cf.max_bytes },
1139 })));1136 });
1140 },1137 },
1141 .config_header => e: {1138 .config_header => e: {
1142 const ch: *Step.ConfigHeader = @fieldParentPtr("step", step);1139 const ch: *Step.ConfigHeader = @fieldParentPtr("step", step);
...@@ -1154,11 +1151,9 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1154,11 +1151,9 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1154 .int => |x| switch (x) {1151 .int => |x| switch (x) {
1155 0 => .int_0,1152 0 => .int_0,
1156 1 => .int_1,1153 1 => .int_1,
1157 else => @enumFromInt(try wc.addExtra(1154 else => try wc.addExtra(Configuration.Step.ConfigHeader.Value, .initSigned(x)),
1158 Configuration.Step.ConfigHeader.Value.initSigned(x),
1159 )),
1160 },1155 },
1161 .ident => |x| @enumFromInt(try wc.addExtra(@as(Configuration.Step.ConfigHeader.Value, .{1156 .ident => |x| try wc.addExtra(Configuration.Step.ConfigHeader.Value, .{
1162 .flags = .{1157 .flags = .{
1163 .tag = .ident,1158 .tag = .ident,
1164 .small = 0,1159 .small = 0,
...@@ -1167,8 +1162,8 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1167,8 +1162,8 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1167 .u64 = .{ .value = null },1162 .u64 = .{ .value = null },
1168 .ident = .{ .value = try wc.addString(x) },1163 .ident = .{ .value = try wc.addString(x) },
1169 .string = .{ .value = null },1164 .string = .{ .value = null },
1170 }))),1165 }),
1171 .string => |x| @enumFromInt(try wc.addExtra(@as(Configuration.Step.ConfigHeader.Value, .{1166 .string => |x| try wc.addExtra(Configuration.Step.ConfigHeader.Value, .{
1172 .flags = .{1167 .flags = .{
1173 .tag = .string,1168 .tag = .string,
1174 .small = 0,1169 .small = 0,
...@@ -1177,10 +1172,10 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1177,10 +1172,10 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1177 .u64 = .{ .value = null },1172 .u64 = .{ .value = null },
1178 .ident = .{ .value = null },1173 .ident = .{ .value = null },
1179 .string = .{ .value = try wc.addString(x) },1174 .string = .{ .value = try wc.addString(x) },
1180 }))),1175 }),
1181 },1176 },
1182 };1177 };
1183 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.ConfigHeader, .{1178 break :e try wc.addExtraErased(Configuration.Step.ConfigHeader, .{
1184 .flags = .{1179 .flags = .{
1185 .template_file = lazy_path != null,1180 .template_file = lazy_path != null,
1186 .style = .init(ch.style),1181 .style = .init(ch.style),
...@@ -1193,7 +1188,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1193,7 +1188,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1193 .include_path = try wc.addString(ch.include_path),1188 .include_path = try wc.addString(ch.include_path),
1194 .include_guard = .{ .value = ch.include_guard.unwrap() },1189 .include_guard = .{ .value = ch.include_guard.unwrap() },
1195 .values = .{ .slice = pairs },1190 .values = .{ .slice = pairs },
1196 })));1191 });
1197 },1192 },
1198 .obj_copy => e: {1193 .obj_copy => e: {
1199 const oc: *Step.ObjCopy = @fieldParentPtr("step", step);1194 const oc: *Step.ObjCopy = @fieldParentPtr("step", step);
...@@ -1217,7 +1212,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1217,7 +1212,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1217 .file_path = try s.addLazyPath(src.file_path),1212 .file_path = try s.addLazyPath(src.file_path),
1218 };1213 };
12191214
1220 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.ObjCopy, .{1215 break :e try wc.addExtraErased(Configuration.Step.ObjCopy, .{
1221 .flags = .{1216 .flags = .{
1222 .basename = oc.basename != .none,1217 .basename = oc.basename != .none,
1223 .debug_file = debug_file != null,1218 .debug_file = debug_file != null,
...@@ -1239,7 +1234,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1239,7 +1234,7 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1239 .pad_to = .{ .value = oc.pad_to },1234 .pad_to = .{ .value = oc.pad_to },
1240 .add_section = .{ .slice = add_sections },1235 .add_section = .{ .slice = add_sections },
1241 .update_section = .{ .slice = oc.update_sections.items },1236 .update_section = .{ .slice = oc.update_sections.items },
1242 })));1237 });
1243 },1238 },
1244 .options => e: {1239 .options => e: {
1245 const so: *Step.Options = @fieldParentPtr("step", step);1240 const so: *Step.Options = @fieldParentPtr("step", step);
...@@ -1250,16 +1245,16 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {...@@ -1250,16 +1245,16 @@ fn serialize(b: *std.Build, wc: *Configuration.Wip, writer: *Io.Writer) !void {
1250 .path = try s.addLazyPath(src.path),1245 .path = try s.addLazyPath(src.path),
1251 };1246 };
12521247
1253 break :e @enumFromInt(try wc.addExtra(@as(Configuration.Step.Options, .{1248 break :e try wc.addExtraErased(Configuration.Step.Options, .{
1254 .flags = .{1249 .flags = .{
1255 .args = so.args.items.len != 0,1250 .args = so.args.items.len != 0,
1256 },1251 },
1257 .generated_file = so.generated_file,1252 .generated_file = so.generated_file,
1258 .contents = try wc.addBytes(so.contents.items),1253 .contents = try wc.addBytes(so.contents.items),
1259 .args = .{ .slice = args },1254 .args = .{ .slice = args },
1260 })));1255 });
1261 },1256 },
1262 },1257 }),
1263 });1258 });
1264 }1259 }
1265 }1260 }
lib/std/Build/Configuration.zig+20-10
...@@ -254,7 +254,7 @@ pub const Wip = struct {...@@ -254,7 +254,7 @@ pub const Wip = struct {
254 null;254 null;
255 const cpu_features_add_empty = q.cpu_features_add.isEmpty();255 const cpu_features_add_empty = q.cpu_features_add.isEmpty();
256 const cpu_features_sub_empty = q.cpu_features_sub.isEmpty();256 const cpu_features_sub_empty = q.cpu_features_sub.isEmpty();
257 const result_index: TargetQuery.Index = @enumFromInt(try wip.addExtra(@as(TargetQuery, .{257 const result_index: TargetQuery.Index = try wip.addExtra(TargetQuery, .{
258 .flags = .{258 .flags = .{
259 .cpu_arch = .init(q.cpu_arch),259 .cpu_arch = .init(q.cpu_arch),
260 .cpu_model = .init(q.cpu_model),260 .cpu_model = .init(q.cpu_model),
...@@ -277,7 +277,7 @@ pub const Wip = struct {...@@ -277,7 +277,7 @@ pub const Wip = struct {
277 .cpu_name = .{ .value = cpu_name },277 .cpu_name = .{ .value = cpu_name },
278 .os_version_min = .{ .u = os_version_min },278 .os_version_min = .{ .u = os_version_min },
279 .os_version_max = .{ .u = os_version_max },279 .os_version_max = .{ .u = os_version_max },
280 })));280 });
281281
282 // Deduplicate.282 // Deduplicate.
283 const gop = try wip.targets_table.getOrPutContext(gpa, result_index, @as(TargetsTableContext, .{283 const gop = try wip.targets_table.getOrPutContext(gpa, result_index, @as(TargetsTableContext, .{
...@@ -329,7 +329,7 @@ pub const Wip = struct {...@@ -329,7 +329,7 @@ pub const Wip = struct {
329 };329 };
330 const dynamic_linker: ?String = if (t.dynamic_linker.get()) |dl| try wip.addString(dl) else null;330 const dynamic_linker: ?String = if (t.dynamic_linker.get()) |dl| try wip.addString(dl) else null;
331 const cpu_features_add_empty = t.cpu.features.isEmpty();331 const cpu_features_add_empty = t.cpu.features.isEmpty();
332 const result_index: TargetQuery.Index = @enumFromInt(try wip.addExtra(@as(TargetQuery, .{332 const result_index = try wip.addExtra(TargetQuery, .{
333 .flags = .{333 .flags = .{
334 .cpu_arch = .init(t.cpu.arch),334 .cpu_arch = .init(t.cpu.arch),
335 .cpu_model = .explicit,335 .cpu_model = .explicit,
...@@ -352,7 +352,7 @@ pub const Wip = struct {...@@ -352,7 +352,7 @@ pub const Wip = struct {
352 .cpu_name = .{ .value = cpu_name },352 .cpu_name = .{ .value = cpu_name },
353 .os_version_min = .{ .u = os_version_min },353 .os_version_min = .{ .u = os_version_min },
354 .os_version_max = .{ .u = os_version_max },354 .os_version_max = .{ .u = os_version_max },
355 })));355 });
356356
357 // Deduplicate.357 // Deduplicate.
358 const gop = try wip.targets_table.getOrPutContext(gpa, result_index, @as(TargetsTableContext, .{358 const gop = try wip.targets_table.getOrPutContext(gpa, result_index, @as(TargetsTableContext, .{
...@@ -366,10 +366,16 @@ pub const Wip = struct {...@@ -366,10 +366,16 @@ pub const Wip = struct {
366 }366 }
367 }367 }
368368
369 pub fn addExtra(wip: *Wip, extra: anytype) Allocator.Error!u32 {369 pub fn addExtra(wip: *Wip, comptime T: type, v: T) Allocator.Error!T.Index {
370 const extra_len = Storage.extraLen(extra);370 const extra_len = Storage.extraLen(v);
371 try wip.extra.ensureUnusedCapacity(wip.gpa, extra_len);371 try wip.extra.ensureUnusedCapacity(wip.gpa, extra_len);
372 return addExtraAssumeCapacity(wip, extra);372 return addExtraReserved(wip, T, v);
373 }
374
375 pub fn addExtraErased(wip: *Wip, comptime T: type, v: T) Allocator.Error!u32 {
376 const extra_len = Storage.extraLen(v);
377 try wip.extra.ensureUnusedCapacity(wip.gpa, extra_len);
378 return addExtraReservedErased(wip, T, v);
373 }379 }
374380
375 /// Same as `addExtra` but uses a hash map to possibly return an already381 /// Same as `addExtra` but uses a hash map to possibly return an already
...@@ -382,7 +388,7 @@ pub const Wip = struct {...@@ -382,7 +388,7 @@ pub const Wip = struct {
382 try wip.dedupe_table.ensureUnusedCapacityContext(gpa, 1, @as(ExtraSlice.Context, .{388 try wip.dedupe_table.ensureUnusedCapacityContext(gpa, 1, @as(ExtraSlice.Context, .{
383 .extra = wip.extra.items,389 .extra = wip.extra.items,
384 }));390 }));
385 const new_index = addExtraAssumeCapacity(wip, v);391 const new_index = addExtraReservedErased(wip, T, v);
386 const len: u32 = @intCast(wip.extra.items.len - new_index);392 const len: u32 = @intCast(wip.extra.items.len - new_index);
387 assert(len != 0);393 assert(len != 0);
388 const gop = wip.dedupe_table.getOrPutAssumeCapacityContext(.{394 const gop = wip.dedupe_table.getOrPutAssumeCapacityContext(.{
...@@ -398,9 +404,13 @@ pub const Wip = struct {...@@ -398,9 +404,13 @@ pub const Wip = struct {
398 return @enumFromInt(new_index);404 return @enumFromInt(new_index);
399 }405 }
400406
401 pub fn addExtraAssumeCapacity(wip: *Wip, extra: anytype) u32 {407 pub fn addExtraReserved(wip: *Wip, comptime T: type, v: T) T.Index {
408 return @enumFromInt(addExtraReservedErased(wip, T, v));
409 }
410
411 pub fn addExtraReservedErased(wip: *Wip, comptime T: type, v: T) u32 {
402 const result: u32 = @intCast(wip.extra.items.len);412 const result: u32 = @intCast(wip.extra.items.len);
403 wip.extra.items.len = Storage.setExtra(wip.extra.allocatedSlice(), result, extra);413 wip.extra.items.len = Storage.setExtra(wip.extra.allocatedSlice(), result, v);
404 return result;414 return result;
405 }415 }
406416