Skip to content

jihoo v0.4.3

Choose a tag to compare

@github-actions github-actions released this 01 Nov 03:24
· 552 commits to main since this release

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
}
  • requires and ensures go between a signature and its body, invariant between a loop's head (while, loop, a range for) and its body. result is the value returned and old(x) an inout parameter'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, .len of a slice or str, + - 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 requires used as a value. A build is the same with or without contracts. emit-obligations gives the clauses to the verifier in jihoo-proofs, which proves them modularly: a call proves its callee's requires and assumes its ensures.
  • 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_volatile and write_volatile access memory-mapped device registers.
  • #[panic_handler] replaces how a program reports bugs, for library objects that another system links.
  • -mno-red-zone and -mgeneral-regs-only generate code that can run in a kernel.

Tools and fixes

  • jihoo test f.jh also runs the #[test] functions of the modules f.jh imports.
  • jihoo fmt indents contract clauses.
  • An extern fn resolves to an export fn of the same program.
  • Calls work through fnptr fields behind pointers and borrows.
  • null takes its type when assigned to a static.
  • Aggregate and nullary-enum static initializers 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).