; expect: run ; result: [5,5,5,165] ; phase: 1 ; spec: docs/spec/16-standard-library.md ยง2.4; docs/spec/07a-air-instructions.md module test.bounded_copy air 0 lang 0.1 features [arrays, effects, ownership] type @WriteResult = enum { ok, short_output } fn @main() -> array effects [] entry: %src_storage = local.alloc array %dst_storage = local.alloc array %five = const.u8 5 %marker = const.u8 165 %src_value = array.splat array %five %dst_value = array.splat array %marker local.store %src_storage, %src_value local.store %dst_storage, %dst_value %r = borrow.ref %src_storage %src = slice.make %r %m = borrow.mut %dst_storage %dst = slice.make %m %zero = const.usize 0 %two = const.usize 2 %short_dst = slice.sub %dst, %zero, %two %short = call @copy(%short_dst, %src) borrow.end %short_dst %first = borrow.index %dst, %zero %untouched = load %first borrow.end %first %same = eq.u8 %untouched, %marker assert %same enum.switch @WriteResult %short, ok -> @bad, short_output -> @copy_all bad: trap copy_all: %full = call @copy(%dst, %src) enum.switch @WriteResult %full, ok -> @done, short_output -> @bad done: borrow.end %dst borrow.end %m borrow.end %src borrow.end %r %result = local.load %dst_storage ret %result fn @copy(%dst: slice_mut, %src: slice) -> @WriteResult effects [] entry: %capacity = slice.len %dst %count = slice.len %src %short = lt.usize %capacity, %count cbr %short, @failure(), @success() failure: %error = enum.make @WriteResult.short_output() ret %error success: slice.copy %dst, %src %ok = enum.make @WriteResult.ok() ret %ok