spec: accept RFC 0013 and add spec 15, the .aji source language 0.1
Owner decisions D1-D7 and the boundary rule (source may hide representation mechanics, never authority, allocation, ownership transfer, synchronization, external effects or recoverable failure). spec 15 normative: items, types, statements, expressions, places and borrows, explicit move (named values), outcome matches and 'or trap', scope/shield/lock blocks (lock lowering defined exactly), select, channels, allocation, frame storage, lexical borrow scopes, inferred features, one canonical spelling per construct. grammar.ebnf replaced; E7001-E7007; E3101 gains suggested_effects; spec 01 examples updated.
This commit is contained in:
1 parent
0e25a17e9d
commit
65b10e3fb5
9 files changed
+471
-56
No files matched your search
@@ -64,6 +64,13 @@ pub const registry = [_]Code{
|
||||
// E6xxx — Unsafe/ABI
|
||||
.{ .id = "E6001", .kind = "unsafe.required", .meaning = "Operation requires explicit unsafe boundary; field `reason`: `outside_boundary`, `trusted_declares_unsafe`" },
|
||||
.{ .id = "E6101", .kind = "abi.unaligned_reference", .meaning = "Normal reference requested from insufficiently aligned storage" },
|
||||
.{ .id = "E7001", .kind = "source.syntax", .meaning = "Malformed `.aji` source" },
|
||||
.{ .id = "E7002", .kind = "source.unknown_name", .meaning = "Undefined variable, function, type, field or variant" },
|
||||
.{ .id = "E7003", .kind = "source.missing_move", .meaning = "Named linear value consumed without `move`" },
|
||||
.{ .id = "E7004", .kind = "source.not_exhaustive", .meaning = "`match` misses an outcome, variant or default" },
|
||||
.{ .id = "E7005", .kind = "source.type_mismatch", .meaning = "Expression has the wrong type in a source position" },
|
||||
.{ .id = "E7006", .kind = "source.invalid_construct", .meaning = "Construct not allowed here" },
|
||||
.{ .id = "E7007", .kind = "source.ambiguous", .meaning = "Source meaning cannot be determined" },
|
||||
// T0xxx — Runtime traps (reported in trap records, not by the verifier)
|
||||
.{ .id = "T0001", .kind = "trap.explicit", .meaning = "`trap` instruction executed" },
|
||||
.{ .id = "T0002", .kind = "trap.assert", .meaning = "Assertion failed" },
|
||||
|
||||
@@ -10,11 +10,14 @@ const air = @import("../air.zig");
|
||||
const verifier = @import("../verifier.zig");
|
||||
|
||||
const Context = verifier.Context;
|
||||
const diag = @import("../diag.zig");
|
||||
|
||||
pub fn check(c: *Context) !void {
|
||||
const m = c.module;
|
||||
if (!m.declares("effects")) return;
|
||||
for (m.functions) |f| {
|
||||
const first = c.diags.items.len;
|
||||
defer suggest(c, f, first) catch {};
|
||||
for (f.blocks) |b| for (b.insts) |inst| switch (inst.op) {
|
||||
.task_spawn => |x| {
|
||||
if (!contains(f.effects, "task.spawn")) try c.report("E3101", inst.span, "task.spawn requires the effect task.spawn", &.{
|
||||
@@ -65,6 +68,35 @@ pub fn check(c: *Context) !void {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds `suggested_effects` to every E3101 reported for `f` since diagnostic
|
||||
/// `first`: the complete, sorted effect list the function needs (its declared
|
||||
/// effects plus every missing one). Effects stay declared by the programmer;
|
||||
/// the suggestion makes the repair mechanical.
|
||||
fn suggest(c: *Context, f: air.Function, first: usize) !void {
|
||||
var list: std.ArrayList([]const u8) = .empty;
|
||||
for (f.effects) |e| if (!contains(list.items, e)) try list.append(c.arena, e);
|
||||
const new = c.diags.items[first..];
|
||||
for (new) |d| if (std.mem.eql(u8, d.code.id, "E3101")) for (d.fields) |fld| {
|
||||
if (std.mem.eql(u8, fld.name, "effect") and !contains(list.items, fld.value.str)) try list.append(c.arena, fld.value.str);
|
||||
};
|
||||
if (list.items.len == f.effects.len) return;
|
||||
std.mem.sort([]const u8, list.items, {}, struct {
|
||||
fn lt(_: void, a: []const u8, b: []const u8) bool {
|
||||
return std.mem.lessThan(u8, a, b);
|
||||
}
|
||||
}.lt);
|
||||
var w: std.Io.Writer.Allocating = .init(c.arena);
|
||||
w.writer.writeAll("[") catch return error.OutOfMemory;
|
||||
for (list.items, 0..) |e, i| w.writer.print("{s}{s}", .{ if (i == 0) "" else ", ", e }) catch return error.OutOfMemory;
|
||||
w.writer.writeAll("]") catch return error.OutOfMemory;
|
||||
for (new) |*d| if (std.mem.eql(u8, d.code.id, "E3101")) {
|
||||
const fields = try c.arena.alloc(diag.Field, d.fields.len + 1);
|
||||
@memcpy(fields[0..d.fields.len], d.fields);
|
||||
fields[d.fields.len] = .{ .name = "suggested_effects", .value = .{ .str = w.written() } };
|
||||
d.fields = fields;
|
||||
};
|
||||
}
|
||||
|
||||
fn need(c: *Context, f: air.Function, inst: air.Inst, effect: []const u8) !void {
|
||||
if (contains(f.effects, effect)) return;
|
||||
try c.report("E3101", inst.span, "instruction requires an effect the function does not declare", &.{
|
||||
|
||||
Reference in new issue
Block a user