air: query cache-free nominal properties without recursion

This commit is contained in:
dev committed 2026-10-10 12:13:49 +03:00
1 parent 897f538840
commit 35635603f9
9 files changed
+539 -229

No files matched your search

+7 -6
View File
@@ -4,6 +4,7 @@
//! Borrow definitions have static provenance. Live values must agree at joins.
//! Resource relations also follow block arguments; a monotone worklist solves
//! them before the diagnostic walk, including later predecessors/backedges.
//! Runs after type verification, which prepares nominal properties and value types.
const std = @import("std");
const air = @import("../air.zig");
@@ -207,7 +208,7 @@ const Walker = struct {
/// Linear values: resources, owners and regions (spec 06 §6, spec 03 §19–§20).
fn isResource(w: *Walker, v: ValueId) bool {
return w.c.module.isLinearType(w.types[v]);
return w.c.module.isLinearTypeCached(w.types[v]);
}
/// A non-consuming use of resource `v` (a borrow of it).
@@ -319,7 +320,7 @@ fn walker(c: *Context, f: air.Function, types: []const air.Type) !Walker {
.parent = null,
};
// Linear parameters were moved in: the function owns them (spec 06 §6.3).
if (c.module.isLinearType(p.ty)) w.live[p.value] = true;
if (c.module.isLinearTypeCached(p.ty)) w.live[p.value] = true;
}
return w;
@@ -370,7 +371,7 @@ fn walkFunction(w: *Walker, dom: ssa.Dominators, facts: ?[]provenance.State, eve
const blk = f.blocks[b];
// Linear block parameters own their argument from here on; the
// parameter of a region allocation's `ok` target is a live borrow.
for (blk.params) |p| if (c.module.isLinearType(p.ty) or (p.ty.isBorrow() and w.info[p.value] != null)) {
for (blk.params) |p| if (c.module.isLinearTypeCached(p.ty) or (p.ty.isBorrow() and w.info[p.value] != null)) {
w.live[p.value] = true;
w.dead[p.value] = .none;
};
@@ -393,19 +394,19 @@ fn walkFunction(w: *Walker, dom: ssa.Dominators, facts: ?[]provenance.State, eve
@memcpy(w.live, base);
@memcpy(w.dead, base_dead);
w.facts = try base_facts.clone(c.arena);
for (e.args) |a| if (c.module.isLinearType(types[a])) try w.consume(a, .moved);
for (e.args) |a| if (c.module.isLinearTypeCached(types[a])) try w.consume(a, .moved);
// A linear parameter of the target that is still live on this
// edge would be overwritten: that instance leaks. Parameters are
// not part of the incoming state; they come alive in the block.
for (f.blocks[e.target].params) |p| {
if (c.module.isLinearType(p.ty) and w.live[p.value]) try w.report("E3002", "linear value not consumed before it is redefined", p.value, null);
if (c.module.isLinearTypeCached(p.ty) and w.live[p.value]) try w.report("E3002", "linear value not consumed before it is redefined", p.value, null);
w.live[p.value] = false;
}
if (entry_state[e.target]) |expected| {
if (!std.mem.eql(bool, expected, w.live) and !reported_join[e.target]) {
reported_join[e.target] = true;
for (expected, w.live, 0..) |a, x, v| if (a != x) {
const is_res = c.module.isLinearType(types[v]);
const is_res = c.module.isLinearTypeCached(types[v]);
try c.report(if (is_res) "E3002" else "E2105", f.blocks[e.target].span, if (is_res) "resource state differs between edges into this block" else "borrow state differs between edges into this block", &.{
.{ .name = "function", .value = .{ .str = f.name } },
.{ .name = "block", .value = .{ .str = f.blocks[e.target].name } },