Repository navigation
jihoo v0.4.3
jihoo v0.4.3
Contracts
Functions can state what they need and what they promise, and loops what holds each time they start over (Contracts):
fn bump(inout n: i64)
requires n < 100
ensures n == old(n) + 1
{
n += 1
}
fn sum(xs: [i64]) -> i64 {
var s = 0
var i = 0
while i < xs.len
invariant 0 <= i && i <= xs.len
{
s += xs[i]
i += 1
}
s
}
requiresandensuresgo between a signature and its body,invariantbetween a loop's head (while,loop, a rangefor) and its body.resultis the value returned andold(x)aninoutparameter's value on entry. The words are special only there, so code that uses them as names is unaffected.- A clause compares integers, joined by
&&: literals, parameters, variables,.lenof a slice orstr,+ -and*by a constant, with exact arithmetic. - This release reads contracts but does not prove them. The compiler checks that each clause is well formed, rejects a contract on a function without a body, and rejects a function with
requiresused as a value. A build is the same with or without contracts.emit-obligationsgives the clauses to the verifier in jihoo-proofs, which proves them modularly: a call proves its callee'srequiresand assumes itsensures. - The syntax is fixed from this release on, so the standard library can state contracts before 0.5.0, the release that proves them while compiling.
Verification model
jihoo emit-obligations f.jh prints each function's MIR as the integer model the verifier proves things about (format). Each check carries the span where it fails, and each opaque value the reason the model does not follow it. The output also gives each function's contract, the callee and arguments of each call, and two kinds of values as variables: the integer an inout parameter points to, and a local lent to a single call.
Systems programming
read_volatileandwrite_volatileaccess memory-mapped device registers.#[panic_handler]replaces how a program reports bugs, for library objects that another system links.-mno-red-zoneand-mgeneral-regs-onlygenerate code that can run in a kernel.
Tools and fixes
jihoo test f.jhalso runs the#[test]functions of the modulesf.jhimports.jihoo fmtindents contract clauses.- An
extern fnresolves to anexport fnof the same program. - Calls work through
fnptrfields behind pointers and borrows. nulltakes its type when assigned to astatic.- Aggregate and nullary-enum
staticinitializers are emitted as bytes. - A failed constant evaluation no longer stays marked as in progress.
The compiler is bootstrapped from 0.4.2, and from this release on the seed is 0.4.3. The archives hold bin/jihoo and its standard library. They need glibc and LLVM 21 (libLLVM, clang, ld.lld).