P6A-11, P6A-12: malformed lowering is an internal compiler error; source type-check completeness
P6A-11: when a .aji module passed the frontend but its AIR does not parse (E0001-E0005) or has invalid SSA/CFG (E5001, E5002), the result is one E7900 source.internal_compiler_error at the source construct, with the AIR code in air_code; semantic codes (E0006 included) are unaffected. Unit test injects the checkpoint's `ret %` defect. P6A-12: source-decidable type errors are E7005 at the source: - `as` checks lossless widening with the verifier's own rule (shared function), and that both sides are integers - slice.copy element types; own.free / region.destroy operand types - element rules of channel.make<T> and mutex.make (no borrow, scope, task, shield or guard, at any depth) Probing every source position found no other E1001/E1002 leak. The old test encoding the previous rule (verifier_widen, E1002) is replaced by typecheck/lossy_widen (E7005); 9 typecheck tests. Spec 15 §10 states the frontend/verifier boundary.
This commit is contained in:
1 parent
154c39865f
commit
748eddf4e5
16 files changed
+249
-14
No files matched your search
@@ -36,7 +36,36 @@ pub fn checkFile(arena: std.mem.Allocator, file_name: []const u8, source: []cons
|
||||
.err => |d| return .{ .status = .rejected, .diagnostics = try arena.dupe(diag.Diagnostic, &.{d}) },
|
||||
.unimplemented => |what| return .{ .status = .unimplemented, .diagnostics = &.{}, .missing_stage = what },
|
||||
};
|
||||
return checkLowered(arena, file_name, lowered);
|
||||
}
|
||||
|
||||
/// AIR diagnostics that can only mean the frontend produced malformed AIR
|
||||
/// (spec 15 §10): parse errors and invalid SSA or CFG. Semantic codes,
|
||||
/// `E0006` included, are the program's.
|
||||
const malformed_air = [_][]const u8{ "E0001", "E0002", "E0003", "E0004", "E0005", "E5001", "E5002" };
|
||||
|
||||
/// The AIR pipeline on lowered `.aji`, with every diagnostic mapped to its
|
||||
/// source location; malformed AIR is one internal compiler error (`E7900`).
|
||||
pub fn checkLowered(arena: std.mem.Allocator, file_name: []const u8, lowered: frontend.lower_mod.Output) !Report {
|
||||
var r = try checkAir(arena, file_name, lowered.air);
|
||||
for (r.diagnostics) |d| {
|
||||
const internal = for (malformed_air) |c| {
|
||||
if (std.mem.eql(u8, c, d.code.id)) break true;
|
||||
} else false;
|
||||
if (!internal) continue;
|
||||
const m = try frontend.mapDiagnostic(arena, d, file_name, lowered.lines);
|
||||
var fields: std.ArrayList(diag.Field) = .empty;
|
||||
try fields.append(arena, .{ .name = "air_code", .value = .{ .str = d.code.id } });
|
||||
try fields.append(arena, .{ .name = "air_message", .value = .{ .str = d.message } });
|
||||
for (m.fields) |f| if (std.mem.eql(u8, f.name, "air_line") or std.mem.eql(u8, f.name, "air_col")) try fields.append(arena, f);
|
||||
const ice: diag.Diagnostic = .{
|
||||
.code = diag.lookup("E7900").?,
|
||||
.span = m.span,
|
||||
.message = "the frontend produced invalid AIR for this construct: a compiler bug, not an error in the program",
|
||||
.fields = fields.items,
|
||||
};
|
||||
return .{ .status = .rejected, .diagnostics = try arena.dupe(diag.Diagnostic, &.{ice}), .lowered = lowered };
|
||||
}
|
||||
// One source construct often lowers to several AIR instructions that the
|
||||
// verifier reports separately: keep one diagnostic per code and source
|
||||
// location (the first).
|
||||
@@ -62,3 +91,21 @@ pub fn checkAir(arena: std.mem.Allocator, file_name: []const u8, source: []const
|
||||
if (ds.len != 0) return .{ .status = .rejected, .diagnostics = ds };
|
||||
return .{ .status = .accepted, .diagnostics = &.{}, .module = module };
|
||||
}
|
||||
|
||||
test "malformed lowered AIR is an internal compiler error" {
|
||||
var a = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer a.deinit();
|
||||
const arena = a.allocator();
|
||||
const src = "module t\nfn main() -> void\neffects []\n{\n let x: u8 = 1;\n}\n";
|
||||
var lowered = (try frontend.compile(arena, "t.aji", src)).ok;
|
||||
// Inject the defect of the M checkpoint: a void `ret` with an empty operand.
|
||||
const at = std.mem.indexOf(u8, lowered.air, " ret").?;
|
||||
lowered.air = try std.mem.concat(arena, u8, &.{ lowered.air[0..at], " ret %", lowered.air[at + " ret".len ..] });
|
||||
const r = try checkLowered(arena, "t.aji", lowered);
|
||||
try std.testing.expectEqual(Status.rejected, r.status);
|
||||
try std.testing.expectEqual(@as(usize, 1), r.diagnostics.len);
|
||||
const d = r.diagnostics[0];
|
||||
try std.testing.expectEqualStrings("E7900", d.code.id);
|
||||
try std.testing.expectEqualStrings("E0001", d.fields[0].value.str);
|
||||
try std.testing.expect(d.span.?.line == 5 or d.span.?.line == 4);
|
||||
}
|
||||
Reference in new issue
Block a user