blob: f90a98efe105f1b997289afd924ccda92ee55906 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
open Utils
open TypesUtils
open Types
open Values
let mk_unit_value : typed_value =
{ value = Adt { variant_id = None; field_values = [] }; ty = mk_unit_ty }
let mk_typed_value (ty : ety) (value : value) : typed_value = { value; ty }
let mk_bottom (ty : ety) : typed_value = { value = Bottom; ty }
(** Box a value *)
let mk_box_value (v : typed_value) : typed_value =
let box_ty = mk_box_ty v.ty in
let box_v = Adt { variant_id = None; field_values = [ v ] } in
mk_typed_value box_ty box_v
(** Check if a value contains a borrow *)
let borrows_in_value (v : typed_value) : bool =
let obj =
object
inherit [_] iter_typed_value
method! visit_borrow_content _env _ = raise Found
end
in
(* We use exceptions *)
try
obj#visit_typed_value () v;
false
with Found -> true
(** Check if a value contains inactivated mutable borrows *)
let inactivated_in_value (v : typed_value) : bool =
let obj =
object
inherit [_] iter_typed_value
method! visit_InactivatedMutBorrow _env _ = raise Found
end
in
(* We use exceptions *)
try
obj#visit_typed_value () v;
false
with Found -> true
(** Check if a value contains a loan *)
let loans_in_value (v : typed_value) : bool =
let obj =
object
inherit [_] iter_typed_value
method! visit_loan_content _env _ = raise Found
end
in
(* We use exceptions *)
try
obj#visit_typed_value () v;
false
with Found -> true
(** Check if a value contains outer loans (i.e., loans which are not in borrwed
values. *)
let outer_loans_in_value (v : typed_value) : bool =
let obj =
object
inherit [_] iter_typed_value
method! visit_loan_content _env _ = raise Found
method! visit_borrow_content _ _ = ()
end
in
(* We use exceptions *)
try
obj#visit_typed_value () v;
false
with Found -> true
|