71 lines
2.0 KiB
LLVM
71 lines
2.0 KiB
LLVM
; expect: run
|
|
; result: 42
|
|
; grant: heap=mem.alloc:12
|
|
; phase: 2
|
|
; spec: docs/spec/08-verifier.md §7.1; docs/spec/03-memory-model.md §19.2
|
|
module runtime.nested_quota
|
|
air 0
|
|
lang 0.1
|
|
features [arrays, capabilities, effects, heap, linear_aggregates, ownership, resources]
|
|
|
|
type @Empty = struct {}
|
|
|
|
fn @main(%heap: cap<mem.alloc>) -> u64
|
|
effects [mem.alloc]
|
|
entry:
|
|
%c_1 = const.u16 7
|
|
%c_2 = const.u16 14
|
|
%c_3 = const.u16 21
|
|
%arr_4 = array.make array<u16, 3>(%c_1, %c_2, %c_3)
|
|
%arr_5 = array.splat array<array<u16, 3>, 2> %arr_4
|
|
own.new %arr_5, %heap, ok -> @ok_6, err -> @err_8
|
|
ok_6(%ok_7: own<array<array<u16, 3>, 2>>):
|
|
%s_10 = struct.make @Empty()
|
|
%arr_11 = array.splat array<@Empty, 2> %s_10
|
|
own.new %arr_11, %heap, ok -> @ok_12, err -> @err_14
|
|
err_8(%err_9: alloc_error):
|
|
trap
|
|
ok_12(%ok_13: own<array<@Empty, 2>>):
|
|
own.new %arr_5, %heap, ok -> @ok_16, err -> @err_18
|
|
err_14(%err_15: alloc_error):
|
|
trap
|
|
ok_16(%ok_17: own<array<array<u16, 3>, 2>>):
|
|
own.free %ok_17
|
|
trap
|
|
err_18(%err_19: alloc_error):
|
|
enum.switch alloc_error %err_19, budget_exceeded -> @case_budget_exceeded_20, out_of_memory -> @case_out_of_memory_21
|
|
case_budget_exceeded_20:
|
|
br @endmatch_22()
|
|
case_out_of_memory_21:
|
|
trap
|
|
endmatch_22:
|
|
br @endmatch_23()
|
|
endmatch_23:
|
|
own.free %ok_13
|
|
own.free %ok_7
|
|
%c_24 = const.usize 2
|
|
own.array %c_24, %arr_4, %heap, ok -> @ok_25, err -> @err_27
|
|
ok_25(%ok_26: own_array<array<u16, 3>>):
|
|
%again_29 = borrow.ref %ok_26
|
|
%c_30 = const.usize 0
|
|
%e_31 = borrow.index %again_29, %c_30
|
|
%c_32 = const.usize 2
|
|
%e_33 = borrow.index %e_31, %c_32
|
|
%v_34 = load %e_33
|
|
borrow.end %e_33
|
|
borrow.end %e_31
|
|
%c_35 = const.usize 1
|
|
%e_36 = borrow.index %again_29, %c_35
|
|
%c_37 = const.usize 2
|
|
%e_38 = borrow.index %e_36, %c_37
|
|
%v_39 = load %e_38
|
|
borrow.end %e_38
|
|
borrow.end %e_36
|
|
%t_40 = add.checked.u16 %v_34, %v_39
|
|
borrow.end %again_29
|
|
own.free %ok_26
|
|
%cast_41 = cast.widen.u64 %t_40
|
|
ret %cast_41
|
|
err_27(%err_28: alloc_error):
|
|
trap
|