Phase 3: channels, mutex, select and cancellation points (RFC 0012)

- features cancellation, channels, sync supported
- AIR model/parser/printer: shield, sender<T>, receiver<T>, mutex<T>,
  guard<T>; task.check_cancel, task.join.cancel, task.shield.*,
  channel.*, select (bracketed arms), mutex.*
- verifier: arities (E5002), element rules (E4001/E1001, E0006
  channel_transfer), guard_transfer gating, task.wait effect (gated for
  task.join by cancellation), per-edge consumption with values and
  handles returned as block parameters, loans moved to the handle on
  task.join.cancel's cancelled edge, shield order (E4305), guard
  children (E2102), critical-section rule (E4304)
- interpreter: waiting-operation rule (ready, else cancelled if
  observable, else wait), shield depth, bounded and rendezvous channels
  with FIFO offers, drain-then-close receiver, budget release at the
  last close, select with seeded draw among ready arms, mutex wakeups;
  schedule record also after a select draw
- report counts task.spawn, task.wait and channel allocations
- spec erratum: mutex<T> is linear (format 0 has no droppable
  move-only class)
- 30 new conformance tests (10 run with schedules, 4 accept, 16
  reject); 6000-run schedule stress and 4350 mutants without failure
This commit is contained in:
dev committed 2026-10-04 16:49:37 +03:00
1 parent b82bc35c5f
commit aaf32b6853
45 files changed
+2077 -43

No files matched your search

+14 -1
View File
@@ -42,6 +42,11 @@ pub fn check(c: *Context) !void {
});
};
},
// In a module declaring `cancellation`, every operation that may
// suspend requires `task.wait`, `task.join` included (spec 04 §37.4).
.task_join => if (m.declares("cancellation")) try need(c, f, inst, "task.wait"),
.task_join_cancel, .channel_send, .channel_recv, .select, .mutex_lock => try need(c, f, inst, "task.wait"),
.channel_make => try need(c, f, inst, "mem.alloc"),
.own_new, .own_array, .region_create, .region_new, .region_array => if (!contains(f.effects, "mem.alloc")) {
try c.report("E3101", inst.span, "allocation requires the effect mem.alloc", &.{
.{ .name = "function", .value = .{ .str = f.name } },
@@ -60,7 +65,15 @@ pub fn check(c: *Context) !void {
}
}
fn contains(list: []const []const u8, name: []const u8) bool {
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", &.{
.{ .name = "function", .value = .{ .str = f.name } },
.{ .name = "effect", .value = .{ .str = effect } },
});
}
pub fn contains(list: []const []const u8, name: []const u8) bool {
for (list) |x| if (std.mem.eql(u8, x, name)) return true;
return false;
}