authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-23 13:02:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-23 13:24:55-07:00
log2f9264d8dcedba3a75dcf9d6a31b82447dfc57e8
treee99e6840d2b53f7bbbc20480eac2ec4bec0afe9e
parent2e0de0b4e20794c07fad76c657ad2c33f1928562

stage2: fix -Domit-stage2 regression

This flag is used when building stage1 to omit the stage2 backends from the compiler to save memory on the CI server. It regressed with the merging of e8813b296bc55a13b534bd9b2a03e1f6af366915 because Value functions started calling into Sema functions. The end goal for this build option is to eliminate it.

2 files changed, 12 insertions(+), 2 deletions(-)

src/Compilation.zig+4-2
......@@ -2042,7 +2042,8 @@ pub fn update(comp: *Compilation) !void {
20422042 comp.c_object_work_queue.writeItemAssumeCapacity(key);
20432043 }
20442044
2045 const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
2045 const use_stage1 = build_options.omit_stage2 or
2046 (build_options.is_stage1 and comp.bin_file.options.use_stage1);
20462047 if (comp.bin_file.options.module) |module| {
20472048 module.compile_log_text.shrinkAndFree(module.gpa, 0);
20482049 module.generation += 1;
......@@ -2198,7 +2199,8 @@ fn flush(comp: *Compilation) !void {
21982199 try comp.bin_file.flush(comp); // This is needed before reading the error flags.
21992200 comp.link_error_flags = comp.bin_file.errorFlags();
22002201
2201 const use_stage1 = build_options.is_stage1 and comp.bin_file.options.use_stage1;
2202 const use_stage1 = build_options.omit_stage2 or
2203 (build_options.is_stage1 and comp.bin_file.options.use_stage1);
22022204 if (!use_stage1) {
22032205 if (comp.bin_file.options.module) |module| {
22042206 try link.File.C.flushEmitH(module);
src/Sema.zig+8
......@@ -89,6 +89,7 @@ const RangeSet = @import("RangeSet.zig");
8989const target_util = @import("target.zig");
9090const Package = @import("Package.zig");
9191const crash_report = @import("crash_report.zig");
92const build_options = @import("build_options");
9293
9394pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref);
9495
......@@ -20808,6 +20809,9 @@ pub fn resolveTypeLayout(
2080820809 src: LazySrcLoc,
2080920810 ty: Type,
2081020811) CompileError!void {
20812 if (build_options.omit_stage2)
20813 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
20814
2081120815 switch (ty.zigTypeTag()) {
2081220816 .Struct => return sema.resolveStructLayout(block, src, ty),
2081320817 .Union => return sema.resolveUnionLayout(block, src, ty),
......@@ -20974,6 +20978,8 @@ fn resolveUnionFully(
2097420978}
2097520979
2097620980pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {
20981 if (build_options.omit_stage2)
20982 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
2097720983 switch (ty.tag()) {
2097820984 .@"struct" => {
2097920985 const struct_obj = ty.castTag(.@"struct").?.data;
......@@ -22256,6 +22262,8 @@ fn typePtrOrOptionalPtrTy(
2225622262/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
2225722263/// elsewhere in value.zig
2225822264pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
22265 if (build_options.omit_stage2)
22266 @panic("sadly stage2 is omitted from this build to save memory on the CI server");
2225922267 return switch (ty.tag()) {
2226022268 .u1,
2226122269 .u8,