- air: string literals (trusted line only), trusted obligation on functions, assume, borrow.index.unchecked - verifier: unsafe stage (E6001 outside_boundary / trusted_declares_unsafe); effect stage leaves unsafe to it, so trusted functions discharge it; assume establishes bounds facts - interp: T0009 for detected unsafe precondition violations - aji check --report unsafe: trusted functions with obligations, unsafe functions, unsafe operations with their boundary - feature unsafe published and supported; 10 conformance tests; 3000 mutants without a crash
34 lines
718 B
LLVM
34 lines
718 B
LLVM
; Calling a trusted boundary within its obligation works.
|
|
; expect: run
|
|
; result: 9
|
|
; phase: 2
|
|
; spec: docs/spec/13-contracts-and-unsafe.md
|
|
module test.unsafe_trusted_call
|
|
air 0
|
|
lang 0.1
|
|
features [arrays, effects, ownership, unsafe]
|
|
|
|
fn @get(%s: slice<u8>, %i: usize) -> u8
|
|
effects []
|
|
trusted "callers pass %i < slice.len(%s)"
|
|
entry:
|
|
%e = borrow.index.unchecked %s, %i
|
|
%v = load %e
|
|
borrow.end %e
|
|
ret %v
|
|
|
|
fn @main() -> u8
|
|
effects []
|
|
entry:
|
|
%x = local.alloc array<u8, 4>
|
|
%nine = const.u8 9
|
|
%a = array.splat array<u8, 4> %nine
|
|
local.store %x, %a
|
|
%r = borrow.ref %x
|
|
%s = slice.make %r
|
|
%i = const.usize 3
|
|
%v = call @get(%s, %i)
|
|
borrow.end %s
|
|
borrow.end %r
|
|
ret %v
|