cli: bootstrap verified std bytes and math with source imports
This commit is contained in:
52 files changed
+1000
-22
No files matched your search
+36
-1
@@ -73,7 +73,7 @@ pub fn checkLowered(arena: std.mem.Allocator, file_name: []const u8, lowered: fr
|
||||
for (r.diagnostics) |d| {
|
||||
const m = try frontend.mapDiagnostic(arena, d, file_name, lowered.lines);
|
||||
const dup = for (mapped.items) |prev| {
|
||||
if (prev.code == m.code and prev.span.?.line == m.span.?.line and prev.span.?.col == m.span.?.col) break true;
|
||||
if (prev.code == m.code and std.mem.eql(u8, prev.span.?.file, m.span.?.file) and prev.span.?.line == m.span.?.line and prev.span.?.col == m.span.?.col) break true;
|
||||
} else false;
|
||||
if (!dup) try mapped.append(arena, m);
|
||||
}
|
||||
@@ -109,3 +109,38 @@ test "malformed lowered AIR is an internal compiler error" {
|
||||
try std.testing.expectEqualStrings("E0001", d.fields[0].value.str);
|
||||
try std.testing.expect(d.span.?.line == 5 or d.span.?.line == 4);
|
||||
}
|
||||
|
||||
test "standard imports lower identically in either order" {
|
||||
var a = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer a.deinit();
|
||||
const arena = a.allocator();
|
||||
const body = "fn main() -> u64\neffects []\n{ return std.math.min_u64(7, 11); }\n";
|
||||
const first = try checkFile(arena, "a.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.math;\nimport std.bytes;\n", body }));
|
||||
const second = try checkFile(arena, "/another/directory/b.aji", try std.mem.concat(arena, u8, &.{ "module t\nimport std.bytes;\nimport std.math;\n", body }));
|
||||
try std.testing.expectEqual(Status.accepted, first.status);
|
||||
try std.testing.expectEqual(Status.accepted, second.status);
|
||||
try std.testing.expectEqualStrings(first.lowered.?.air, second.lowered.?.air);
|
||||
// Imported code enters the ordinary verifier with its original locations.
|
||||
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.annotated, "; std/bytes.aji:") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "intrinsic ") == null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "own.") == null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, first.lowered.?.air, "cap<") == null);
|
||||
}
|
||||
|
||||
test "standard source provenance maps diagnostics to the library file" {
|
||||
var a = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer a.deinit();
|
||||
const arena = a.allocator();
|
||||
const report = try checkFile(arena, "client.aji", "module t\nimport std.math;\nfn main() -> u64\neffects []\n{ return std.math.clamp_u64(5, 9, 4); }\n");
|
||||
try std.testing.expectEqual(Status.accepted, report.status);
|
||||
const lowered = report.lowered.?;
|
||||
const assertion = std.mem.indexOf(u8, lowered.air, " assert ").?;
|
||||
const line: u32 = @intCast(std.mem.count(u8, lowered.air[0..assertion], "\n") + 1);
|
||||
const d = try frontend.mapDiagnostic(arena, .{
|
||||
.code = diag.lookup("E2101").?,
|
||||
.span = .{ .file = "client.aji", .line = line, .col = 5 },
|
||||
.message = "test mapping",
|
||||
}, "client.aji", lowered.lines);
|
||||
try std.testing.expectEqualStrings("std/math.aji", d.span.?.file);
|
||||
try std.testing.expectEqual(@as(u32, 20), d.span.?.line);
|
||||
}
|
||||
Reference in new issue
Block a user