7
7
(* ******************************)
8
8
(* Examples from documentation *)
9
9
10
- type t = Con of { field : int }
10
+ (* ************)
11
+ (* intro.md *)
12
+
13
+ type t = Con of { field : int list }
11
14
12
15
let free : t @ unique -> unit = fun t -> ()
13
16
let free_field (unique_ i ) = ()
14
17
let store : t @ aliased -> unit = fun t -> ()
15
18
let store_field i = ()
16
19
let flip_coin () = true
17
20
[%% expect{|
18
- type t = Con of { field : int ; }
21
+ type t = Con of { field : int list ; }
19
22
val free : unique_ t -> unit @@ global many = < fun>
20
23
val free_field : ('a : value_or_null ). unique_ 'a -> unit @@ global many =
21
24
< fun>
@@ -97,8 +100,11 @@ let okay t =
97
100
val okay : t -> unit @@ global many = < fun>
98
101
|}]
99
102
103
+ (* ***************)
104
+ (* pitfalls.md *)
105
+
100
106
let module_ret_unique =
101
- let mk () = Con { field = 1 } in
107
+ let mk () = Con { field = [ 1 ] } in
102
108
let use () = free (mk () ) in
103
109
()
104
110
[%% expect{|
@@ -111,7 +117,7 @@ val module_ret_unique : unit @@ global many = ()
111
117
|}]
112
118
113
119
module Mk = struct
114
- let mk () = Con { field = 1 }
120
+ let mk () = Con { field = [ 1 ] }
115
121
end
116
122
117
123
let module_ret_unique =
@@ -178,6 +184,79 @@ val set_all_zero : ('a : value_or_null). unique_ 'a -> 'a @@ global many =
178
184
< fun>
179
185
|}]
180
186
187
+ (* ***************)
188
+ (* reference.md *)
189
+
190
+ type t = { field1 : t ; field2 : t }
191
+
192
+ let free : t @ unique -> unit = fun t -> ()
193
+ let free_field (unique_ i ) = ()
194
+ let store : t @ aliased -> unit = fun t -> ()
195
+ let store_field i = ()
196
+ let flip_coin () = true
197
+ [%% expect{|
198
+ type t = { field1 : t ; field2 : t ; }
199
+ val free : unique_ t -> unit @@ global many = < fun>
200
+ val free_field : ('a : value_or_null ). unique_ 'a -> unit @@ global many =
201
+ < fun>
202
+ val store : t -> unit @@ global many = < fun>
203
+ val store_field : ('a : value_or_null ). 'a -> unit @@ global many = < fun>
204
+ val flip_coin : unit -> bool @@ global many = < fun>
205
+ |}]
206
+
207
+ let okay t =
208
+ if flip_coin ()
209
+ then free t
210
+ else (store t; store t)
211
+ [%% expect{|
212
+ val okay : unique_ t -> unit @@ global many = < fun>
213
+ |}]
214
+
215
+ let okay r =
216
+ free r.field1;
217
+ match r with
218
+ | { field2 } -> free field2
219
+ [%% expect{|
220
+ val okay : unique_ t -> unit @@ global many = < fun>
221
+ |}]
222
+
223
+ let bad r =
224
+ free r.field1;
225
+ match r with
226
+ | { field2 } -> free r
227
+ [%% expect{|
228
+ Line 4 , characters 23-24 :
229
+ 4 | | { field2 } -> free r
230
+ ^
231
+ Error : This value is used here,
232
+ but part of it has already been used as unique :
233
+ Line 2 , characters 7-15 :
234
+ 2 | free r .field1;
235
+ ^^^^^^^^
236
+
237
+ | }]
238
+
239
+ let okay r =
240
+ let x = r in
241
+ free x.field1;
242
+ match r with
243
+ | { field2 } -> free field2
244
+ [%% expect{|
245
+ val okay : unique_ t -> unit @@ global many = < fun>
246
+ |}]
247
+
248
+ let bad r =
249
+ let x = Fun. id r in
250
+ free x.field1;
251
+ match r with
252
+ | { field2 } -> free field2
253
+ [%% expect{|
254
+ Line 3 , characters 7-15 :
255
+ 3 | free x.field1;
256
+ ^^^^^^^^
257
+ Error : This value is " aliased" but expected to be " unique" .
258
+ | }]
259
+
181
260
let check_tuple x y z =
182
261
let m =
183
262
match x, y, z with
0 commit comments