Phase 2: unsafe operations and trusted boundaries (RFC 0009)
- air: string literals (trusted line only), trusted obligation on functions, assume, borrow.index.unchecked - verifier: unsafe stage (E6001 outside_boundary / trusted_declares_unsafe); effect stage leaves unsafe to it, so trusted functions discharge it; assume establishes bounds facts - interp: T0009 for detected unsafe precondition violations - aji check --report unsafe: trusted functions with obligations, unsafe functions, unsafe operations with their boundary - feature unsafe published and supported; 10 conformance tests; 3000 mutants without a crash
This commit is contained in:
1 parent
c510a37cf9
commit
008654999e
24 files changed
+422
-18
No files matched your search
@@ -190,6 +190,7 @@ const TrapKind = enum {
|
||||
cast_out_of_range,
|
||||
call_depth,
|
||||
out_of_bounds,
|
||||
unsafe_precondition,
|
||||
|
||||
fn code(k: TrapKind) *const diag.Code {
|
||||
return switch (k) {
|
||||
@@ -201,6 +202,7 @@ const TrapKind = enum {
|
||||
.cast_out_of_range => diag.lookup("T0006").?,
|
||||
.call_depth => diag.lookup("T0007").?,
|
||||
.out_of_bounds => diag.lookup("T0008").?,
|
||||
.unsafe_precondition => diag.lookup("T0009").?,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -376,7 +378,7 @@ const Machine = struct {
|
||||
.intrinsic => |x| return m.intrinsic(f, vals, inst, x),
|
||||
.ret => |v| return .{ .ret = if (v) |x| vals[x] else .void },
|
||||
.trap => return .{ .trap = .explicit },
|
||||
.local_alloc, .local_store, .local_zero, .local_load, .borrow_ref, .borrow_mut, .borrow_field, .borrow_end, .load, .store, .array_splat, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split, .slice_copy, .guard => return m.execMemory(vals, inst),
|
||||
.local_alloc, .local_store, .local_zero, .local_load, .borrow_ref, .borrow_mut, .borrow_field, .borrow_end, .load, .store, .array_splat, .borrow_index, .slice_make, .slice_len, .slice_sub, .slice_split, .slice_copy, .guard, .assume => return m.execMemory(vals, inst),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -782,7 +784,9 @@ const Machine = struct {
|
||||
};
|
||||
// `.proven` was verified in bounds; the check is kept as a
|
||||
// defensive assertion that can never fire on verified AIR.
|
||||
if (i >= len) return .{ .trap = .out_of_bounds };
|
||||
// The reference interpreter detects violated unsafe
|
||||
// preconditions (spec 13 §6.1).
|
||||
if (i >= len) return .{ .trap = if (x.unchecked) .unsafe_precondition else .out_of_bounds };
|
||||
return bind(vals, inst.result, .{ .place = try m.extend(place, start + i) });
|
||||
},
|
||||
.slice_make => |v| {
|
||||
@@ -816,6 +820,7 @@ const Machine = struct {
|
||||
return .next;
|
||||
},
|
||||
.guard => |v| return if (vals[v].boolean) .next else .{ .trap = .assert },
|
||||
.assume => |v| return if (vals[v].boolean) .next else .{ .trap = .unsafe_precondition },
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user