Formal semanticsmodels Rust

a-mir-formality

Also known as formality-rust

An early-stage, executable model of Rust's type system, trait solver and borrow checker, written as inference rules in Rust and maintained by members of the Rust types team.

Not staged Written in Rust (formality-core judgment library) Open source · MIT OR Apache-2.0 Last commit · 2 days ago

The rules are written with formality-core, a Rust library for defining judgments, so the model runs as an ordinary Rust program and its tests check whether small Rust-like programs are accepted or rejected. It works on its own Rust-like grammar (types, traits, impls, functions, ADTs and a MIR-like expression language), not on real Rust source code. Function bodies can be translated to MiniRust, which gives them a run-time meaning. The README says the intention is to propose the model to Rust as an RFC if the experiments succeed.

What it covers

Models
Rust
Fragment
Static semantics: well-formedness of types and items, trait solving and associated-type normalization, coherence (overlap and orphan rules), and borrow checking of a MIR-like expression language. Run-time behavior is delegated to MiniRust through a code generator. No list of covered or excluded Rust features is published.
Written in
Rust (formality-core judgment library)
Usable in
—
Validation
Snapshot tests in the repository check that example programs type-check or fail with an expected error. No published comparison against rustc was found.
Maintained by
Rust types team members (github.com/rust-lang/a-mir-formality)

Stage

Computed from the evidence below; see the criteria. MechanizedMechanized. Written in a form a computer can check, rather than on paper. means a computer can check the definition.

Stage 0 Mechanized Next
  • Met: Machine-checked or machine-readable definition The judgments are machine-readable Rust code. The model is not available in a proof assistant. evidence
  • Not met: Fragment and version are stated The book describes the layers of the model, but there is no list of covered Rust features and no Rust version. evidence
Stage 1 Validated Later
  • Met: Can be executed or tested The model runs with cargo test; judgments are executed directly. evidence
  • Not met: Published results against conformance tests or real implementations Repository tests only; no published differential testing against rustc. evidence
Stage 2 Authoritative Later
  • Not met: Adopted by the language or ISA owner, or covers the full current version and tracks new ones Adopted by the owner: no; full coverage: no; tracks new versions: no. Hosted in the rust-lang organization and described as maintained by the Rust types team, but the README calls it an early-stage experiment that may later be proposed as an official part of the language definition through an RFC. Described as early-stage and experimental. No stated policy for following Rust releases. evidence

Coverage

Which parts of Rust the model defines.

Common features

Common features
FeatureSupportNotes
Machine integers Fixed-width integer arithmetic, overflow and bit operations. Unknown
Floating point IEEE 754 floating-point arithmetic, including rounding and NaNs. Unknown
Heap and pointers Dynamically allocated memory, pointers or references, and aliasing. Unknown
Arrays and buffers Indexed memory such as arrays, slices, vectors and byte buffers. Unknown
Loops Unbounded loops, which need invariants or bounds to verify. Unknown
Recursion Functions that call themselves, directly or through others. Unknown
Higher-order code Function pointers, closures and callbacks. Unknown
Threads and shared memory Concurrent threads with locks, atomics or message passing. Unknown
I/O and system calls Files, network, system calls and foreign-function calls. Unknown
Standard library Specifications or models for the language's standard library. Unknown

Rust-specific features

Rust-specific features
FeatureSupportNotes
References and borrowing Shared and mutable references checked by the borrow checker. PartialPartial.Borrow checking is modeled as judgments over its MIR-like expression language (let, if, loop, break, return and expressions); how much of rustc's borrow checker it matches is not documented.
Source
Borrow checking is modeled as judgments over its MIR-like expression language (let, if, loop, break, return and expressions); how much of rustc's borrow checker it matches is not documented. source
Traits and generics Generic functions and types with trait bounds. PartialPartial.Trait solving, associated-type normalization, higher-ranked where clauses and coherence (overlap and orphan checks) are modeled; the project does not claim full coverage of Rust's trait system.
Source
Trait solving, associated-type normalization, higher-ranked where clauses and coherence (overlap and orphan checks) are modeled; the project does not claim full coverage of Rust's trait system. source
Closures Anonymous functions that capture their environment. Unknown
unsafe and raw pointers Code inside unsafe blocks, raw pointer dereferences and FFI. Unknown
Interior mutability Cell, RefCell, UnsafeCell and other mutation through shared references. Unknown
Trait objects dyn Trait values with dynamic dispatch. Unknown
Iterators Iterator chains such as map, filter and for loops over collections. Unknown
Panics Panicking operations (unwrap, indexing, overflow in debug builds) and their absence. Unknown
async / await Asynchronous functions and futures. Unknown

Used by

Toolchains in this index whose proofs are about this model.

No toolchain in the index refers to it yet.

Sources

esc