Tether
Tether is a compile-time proof engine. For every pointer dereference in the program, it attempts to prove that the access is safe. When it succeeds, no runtime code is emitted. When it can prove everything except one residual property, it emits the minimal runtime code required to discharge exactly that property and nothing else. When it cannot prove the access safe and no runtime check or code transformation can establish safety, it is a hard compile error.
The system is not a pointer tracker that decides where to insert checks. It is a proof engine that asks one question at every dereference:
What is the strongest proof I have that this access is safe?
The answer to that question and only the answer determines what code is generated. Tether never asks "should I insert a check here." It asks "which proof obligations remain after static analysis," and emits code for the residual.
Tether operates on safe pointers (*T) only. Raw pointers (unsafe *T) carry no obligations and are never analyzed. The programmer owns their correctness.
Tether is not yet implemented. The current compiler is Stage 1.5; Tether development begins at Stage 2. The roadmap:
- Stage 0 (retired): the original compiler, written in C++. It was used only to bootstrap Stage 1.
- Stage 1: the compiler written in Kairo, built by Stage 0. No lifetime analysis.
- Stage 1.5 (current, 0.2.0): Stage 1 migrated to Kairo's standard library. It compiles itself. No lifetime analysis.
- Stage 2: compiler rewritten using Kairo's extended feature set. Tether work begins here.
This page describes the intended design and target semantics. The analysis is the target, not the current state. A separate formal paper will carry the full proofs; this page states the model and the obligations precisely enough to implement against, but is not itself the proof.
In this section
- Proof Model: the dereference obligation, the proof lattice and the residual table.
- Bounds and Provenance: pointer arithmetic, hoisting, provenance and epochs, interior pointers.
- Ownership and Promotion: smart-pointer promotion and stack-pointer escapes.
- Threading: strict mode and the race-freedom rule set.
- Tether Internals: C/C++ interop, generic code,
.amtsummaries, soundness and testing. - Allocators: global, scoped and freestanding allocators and the allocator interface.
Destruction Timing
Where Tether places a value's destruction depends on whether the destructor is observable.
A destructor is timing-insensitive if and only if it does nothing but free memory the value owns and run destructors that are themselves timing-insensitive (fields, bases, owned pointees). Everything else is observable: a destructor that touches a global or thread variable, does I/O, takes or releases a lock, changes a reference count, calls C or C++, or calls any function not known to be timing-insensitive. This is a different property from being trivially destructible: a destructor with a body that only frees an owned buffer is not trivial, but it is timing-insensitive. In the rest of this section, "trivial" means timing-insensitive.
Trivial destructors (no observable side effect just memory to reclaim) run at last use. Tether places the @destroy/@free as early as the final use permits, since reclaiming memory after the last use is indistinguishable from reclaiming it at the scope brace:
var *foo = @create SomeClass() // trivial destructor
use(foo)
// @destroy foo inserted here
std::io::println(10)
Non-trivial destructors (a user-defined op finally, or any member with one file close, lock release, flush, disconnect) run at the end of the owning binding's lexical scope, in reverse declaration order. Tether does not move these to last use:
fn example() {
var *cfg = @create Config(8080) // side-effecting destructor
use(cfg)
std::io::println(10)
}
// cfg's destructor runs here, at the brace not after use(cfg)
This is the "predictable from source" guarantee: any observable destructor side effect fires at the scope brace exactly as written. finally blocks, lock guards, and NON_TRANSFER scope guards depend on it.
Shared objects separate two events. The refcount decrement happens at each Shared binding's own scope boundary, in reverse declaration order. The object destructor and deallocation happen once, when the last live Shared reference's scope ends and the count reaches zero which is not necessarily the last-declared binding in any single scope. Reason about shared destruction as "when the final owner goes away," not "reverse declaration order of the binding in front of me." Weak scope exit does not touch the count; a Weak simply becomes invalid once the target is freed.
Arena memory is freed wholesale at scope end; see Scoped allocator.
Copy Elision
For COPY types, Tether may emit a move instead of a copy when it proves the source is unused after the transfer and the elision is unobservable. Elision means the source's destructor runs at the transfer point instead of at its own scope exit; Tether performs it only when the source's destructor is timing-insensitive. A Shared source is never elided this way: its decrement can be the one that reaches zero and runs the pointee's destructor, so it counts as observable.
If the destructor has timing-sensitive side effects a flush, a lock release, a log line Tether does not elide. The copy is preserved and the source is destroyed at its lexical scope exit as written. Elision is silent precisely because it is only applied where it cannot be observed. The programmer neither opts in nor controls it, and it is never applied if the move constructor is deleted.
What Tether Does Not Do
- Garbage collection. No tracing, no mark-and-sweep, no runtime collector. Reference counting for
Sharedis the only runtime ownership cost, and it exists only where multiple ownership is required. - Runtime borrow checking. Aliasing is resolved at compile time. Tether does not insert runtime aliasing checks; it inserts bounds, epoch, and (for tainted residuals) access checks those are clause discharges, not borrow checks.
- Lifetime annotations. No
'a-style parameters, no lifetime polymorphism. Whole-program analysis infers concrete lifetimes from usage. - Reference counting everywhere. Single-owner pointers promote to
Unique(no refcount); contained lifetimes are not promoted at all. Refcounting appears only under proven multiple ownership. - Cross-language analysis. C++ is opaque beyond the one-level heuristic on a visible body. Across the FFI boundary, Tether fails closed (taint inbound, epoch-freeze outbound) rather than guessing.
Summary
The whole system, in one table maps each clause's residual to its response:
| Residual | Response | Tier |
|---|---|---|
| bounds (range) | hoisted/local check, both modes | R |
| formation range, unprovable | hoisted/local check at the arithmetic | R |
formation outside [base, base+count] (static) | compile error | N |
< across allocations / unprovable provenance | compile error | N |
| UAF (provenance intact) | epoch compare, both modes | R |
| UAF (provenance lost) | hard error | N |
| nullability | compile error, both modes | N |
| ownership escape (heap-promotable) | debug promote / release error | P |
| stack escape (heap-promotable) | debug heap-lift / release error | P |
| stack escape (non-promotable) | hard error | N |
| scoped-allocator escape | hard error | N |
| opaque-container escape | hard error | N |
| iterator invalidation | hard error | N |
| moved-from use | hard error | N |
| second writer to shared allocation | hard error | N |
| access residual on shared mutable allocation | hard error (strict mode) | N |
| access residual on shared read-only allocation | normal Tier-R check | R |
| taint (provenance recoverable) | runtime check | R |
| taint (provenance opaque) | hard error (demand unsafe) | N |
| Type | Tracked? | Promoted? | Escape |
|---|---|---|---|
| Plain *T (stack) | Yes | Heap-lift in debug only | Promotable: debug-lift / release-err; else hard error |
| Plain *T (heap) | Yes | Debug: yes / Release: no | Release: hard error (annotate) |
| unsafe *T | No | Never | Programmer's problem |
| Scoped-alloc ptr | Yes | Never | Always hard error |
| Shared (thread) | Yes | n/a | One writer, or many const readers |
| FFI smart ptr | Yes | Mapped 1:1 | Type mismatch = error |
| FFI raw ptr | No | Never | Tainted; requires unsafe/launder |
Tether proves every dereference safe statically when it can, and emits nothing. When only a checkable property remains, it emits the minimal check Tier R, the only runtime cost in a release build. When safety needs a program change it transforms in debug and errors in release (Tier P), and when nothing can establish safety it is a hard error in every mode (Tier N).