Skip to content

Commit

Permalink
Reports errors to sema instead of failed files when appropriate, stop…
Browse files Browse the repository at this point in the history
…s resolving types fully
  • Loading branch information
MasonRemaley committed Jan 8, 2025
1 parent 0320026 commit 959c977
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
9 changes: 7 additions & 2 deletions src/Zcu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,16 @@ pub const File = struct {
return &file.tree;
}

pub fn getZoir(file: *File, gpa: Allocator) !*const Zoir {
pub fn getZoir(file: *File, zcu: *Zcu) !*const Zoir {
if (file.zoir) |*zoir| return zoir;

assert(file.tree_loaded);
assert(file.tree.mode == .zon);
file.zoir = try ZonGen.generate(gpa, file.tree, .{});
file.zoir = try ZonGen.generate(zcu.gpa, file.tree, .{});
if (file.zoir.?.hasCompileErrors()) {
try zcu.failed_files.putNoClobber(zcu.gpa, file, null);
return error.AnalysisFail;
}
return &file.zoir.?;
}

Expand Down
19 changes: 6 additions & 13 deletions src/zon.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ pub fn lower(
import_loc: LazySrcLoc,
block: *Sema.Block,
) CompileError!InternPool.Index {
assert(file.tree_loaded);
const zoir = try file.getZoir(sema.gpa);

if (zoir.hasCompileErrors()) {
try sema.pt.zcu.failed_files.putNoClobber(sema.gpa, file, null);
return error.AnalysisFail;
}

_ = try file.getZoir(sema.pt.zcu);
const lower_zon: LowerZon = .{
.sema = sema,
.file = file,
Expand Down Expand Up @@ -70,13 +63,12 @@ fn fail(
loc: LazySrcLoc.Offset,
comptime format: []const u8,
args: anytype,
) (Allocator.Error || error{AnalysisFail}) {
) error{ AnalysisFail, OutOfMemory } {
@branchHint(.cold);
const src_loc = try self.lazySrcLoc(loc);
const err_msg = try Zcu.ErrorMsg.create(self.sema.pt.zcu.gpa, src_loc, format, args);
try self.sema.pt.zcu.errNote(self.import_loc, err_msg, "imported here", .{});
try self.sema.pt.zcu.failed_files.putNoClobber(self.sema.pt.zcu.gpa, self.file, err_msg);
return error.AnalysisFail;
return self.sema.failWithOwnedErrorMsg(self.block, err_msg);
}

const Ident = struct {
Expand Down Expand Up @@ -568,7 +560,8 @@ fn lowerStruct(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
const ip = &self.sema.pt.zcu.intern_pool;
const gpa = self.sema.gpa;

try res_ty.resolveFully(self.sema.pt);
try res_ty.resolveFields(self.sema.pt);
try res_ty.resolveStructFieldInits(self.sema.pt);
const struct_info = self.sema.pt.zcu.typeToStruct(res_ty).?;

const fields: std.meta.fieldInfo(Zoir.Node, .struct_literal).type = switch (node.get(self.file.zoir.?)) {
Expand Down Expand Up @@ -752,7 +745,7 @@ fn lowerPointer(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool

fn lowerUnion(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.Index {
const ip = &self.sema.pt.zcu.intern_pool;
try res_ty.resolveFully(self.sema.pt);
try res_ty.resolveFields(self.sema.pt);
const union_info = self.sema.pt.zcu.typeToUnion(res_ty).?;
const enum_tag_info = union_info.loadTagType(ip);

Expand Down

0 comments on commit 959c977

Please sign in to comment.