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:
dev committed 2026-10-05 10:35:55 +03:00
1 parent 0e25a17e9d
commit 65b10e3fb5
9 files changed
+471 -56

No files matched your search

+32
View File
@@ -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", &.{