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 {...@@ -2042,7 +2042,8 @@ pub fn update(comp: *Compilation) !void {
2042 comp.c_object_work_queue.writeItemAssumeCapacity(key);2042 comp.c_object_work_queue.writeItemAssumeCapacity(key);
2043 }2043 }
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);
2046 if (comp.bin_file.options.module) |module| {2047 if (comp.bin_file.options.module) |module| {
2047 module.compile_log_text.shrinkAndFree(module.gpa, 0);2048 module.compile_log_text.shrinkAndFree(module.gpa, 0);
2048 module.generation += 1;2049 module.generation += 1;
...@@ -2198,7 +2199,8 @@ fn flush(comp: *Compilation) !void {...@@ -2198,7 +2199,8 @@ fn flush(comp: *Compilation) !void {
2198 try comp.bin_file.flush(comp); // This is needed before reading the error flags.2199 try comp.bin_file.flush(comp); // This is needed before reading the error flags.
2199 comp.link_error_flags = comp.bin_file.errorFlags();2200 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);
2202 if (!use_stage1) {2204 if (!use_stage1) {
2203 if (comp.bin_file.options.module) |module| {2205 if (comp.bin_file.options.module) |module| {
2204 try link.File.C.flushEmitH(module);2206 try link.File.C.flushEmitH(module);
src/Sema.zig+8
...@@ -89,6 +89,7 @@ const RangeSet = @import("RangeSet.zig");...@@ -89,6 +89,7 @@ const RangeSet = @import("RangeSet.zig");
89const target_util = @import("target.zig");89const target_util = @import("target.zig");
90const Package = @import("Package.zig");90const Package = @import("Package.zig");
91const crash_report = @import("crash_report.zig");91const crash_report = @import("crash_report.zig");
92const build_options = @import("build_options");
9293
93pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref);94pub const InstMap = std.AutoHashMapUnmanaged(Zir.Inst.Index, Air.Inst.Ref);
9495
...@@ -20808,6 +20809,9 @@ pub fn resolveTypeLayout(...@@ -20808,6 +20809,9 @@ pub fn resolveTypeLayout(
20808 src: LazySrcLoc,20809 src: LazySrcLoc,
20809 ty: Type,20810 ty: Type,
20810) CompileError!void {20811) 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
20811 switch (ty.zigTypeTag()) {20815 switch (ty.zigTypeTag()) {
20812 .Struct => return sema.resolveStructLayout(block, src, ty),20816 .Struct => return sema.resolveStructLayout(block, src, ty),
20813 .Union => return sema.resolveUnionLayout(block, src, ty),20817 .Union => return sema.resolveUnionLayout(block, src, ty),
...@@ -20974,6 +20978,8 @@ fn resolveUnionFully(...@@ -20974,6 +20978,8 @@ fn resolveUnionFully(
20974}20978}
2097520979
20976pub fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!Type {20980pub 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");
20977 switch (ty.tag()) {20983 switch (ty.tag()) {
20978 .@"struct" => {20984 .@"struct" => {
20979 const struct_obj = ty.castTag(.@"struct").?.data;20985 const struct_obj = ty.castTag(.@"struct").?.data;
...@@ -22256,6 +22262,8 @@ fn typePtrOrOptionalPtrTy(...@@ -22256,6 +22262,8 @@ fn typePtrOrOptionalPtrTy(
22256/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen22262/// TODO merge these implementations together with the "advanced"/sema_kit pattern seen
22257/// elsewhere in value.zig22263/// elsewhere in value.zig
22258pub fn typeRequiresComptime(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {22264pub 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");
22259 return switch (ty.tag()) {22267 return switch (ty.tag()) {
22260 .u1,22268 .u1,
22261 .u8,22269 .u8,