Initial import: Aji 0.1 draft spec and Zig scaffolding
Draft specification, RFCs, reference registries and examples, plus the reference-implementation skeleton: build.zig, diagnostic envelope with error-code registry synced to docs, aji CLI, conformance runner with seed tests, CI and contributor docs.
This commit is contained in:
commit
17a55a7fef
67 files changed
+4197
No files matched your search
@@ -0,0 +1,86 @@
|
||||
# 13. Contracts and Unsafe Boundaries
|
||||
|
||||
## 1. Contracts
|
||||
|
||||
Functions may declare preconditions and postconditions. Types/modules may declare invariants.
|
||||
|
||||
```aji
|
||||
fn append(log: mut<Log>, data: slice<u8>) -> Result<u64, Error>
|
||||
requires {
|
||||
len(data) <= 16 MiB
|
||||
}
|
||||
ensures {
|
||||
result.is_ok() => log.offset >= old(log.offset)
|
||||
}
|
||||
effects [fs.write]
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
The verifier reports each contract as one of:
|
||||
|
||||
```text
|
||||
PROVEN_STATICALLY
|
||||
CHECKED_AT_RUNTIME
|
||||
ASSUMED_UNSAFE
|
||||
UNPROVEN
|
||||
```
|
||||
|
||||
A high-assurance profile may reject runtime-only or unproven obligations.
|
||||
|
||||
## 2. Assertions and guards
|
||||
|
||||
`assert condition` is a runtime-visible correctness check unless statically proven. Failure traps.
|
||||
|
||||
`guard condition` both checks the condition as required by its form and introduces a path fact to the verifier.
|
||||
|
||||
`assume condition` is unsafe-only because it introduces a proof fact without checking it.
|
||||
|
||||
## 3. Unsafe
|
||||
|
||||
Unsafe operations occur only in an explicit `unsafe` block/function/module.
|
||||
|
||||
Unsafe does not disable the type system globally. It enables specific operations whose safety obligations cannot be established by the normal verifier.
|
||||
|
||||
Typical unsafe facilities:
|
||||
|
||||
```text
|
||||
addr<T> dereference
|
||||
pointer arithmetic
|
||||
FFI
|
||||
direct syscalls
|
||||
inline assembly
|
||||
manual Send/Share declarations
|
||||
custom synchronization primitives
|
||||
```
|
||||
|
||||
## 4. Unsafe proof obligations
|
||||
|
||||
Unsafe code must document applicable obligations, including:
|
||||
|
||||
- valid allocation/provenance;
|
||||
- alignment;
|
||||
- initialization;
|
||||
- lifetime;
|
||||
- aliasing;
|
||||
- synchronization;
|
||||
- ABI assumptions;
|
||||
- resource-state assumptions.
|
||||
|
||||
Violation of an unsafe precondition may cause Undefined Aji Behavior.
|
||||
|
||||
## 5. Unsafe dependency report
|
||||
|
||||
The toolchain should produce a machine-readable report containing:
|
||||
|
||||
```text
|
||||
application unsafe blocks
|
||||
unsafe standard-library modules
|
||||
raw dereference sites
|
||||
inline assembly sites
|
||||
FFI boundaries
|
||||
manual Send/Share declarations
|
||||
```
|
||||
|
||||
This report is part of the audit surface for agent-generated systems.
|
||||
Reference in new issue
Block a user