summaryrefslogtreecommitdiff
path: root/tests/fstar/traits/Traits.fst
blob: 318efa2b392ecc6f314e52da9de22502e37320ed (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
(** THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS *)
(** [traits] *)
module Traits
open Primitives

#set-options "--z3rlimit 50 --fuel 1 --ifuel 1"

(** Trait declaration: [traits::BoolTrait] *)
noeq type boolTrait_t (self : Type0) = { get_bool : self -> result bool; }

(** [traits::Bool::{0}::get_bool]: forward function *)
let bool_get_bool (self : bool) : result bool =
  Return self

(** Trait implementation: [traits::Bool::{0}] *)
let bool_BoolTraitInst : boolTrait_t bool = { get_bool = bool_get_bool; }

(** [traits::BoolTrait::ret_true]: forward function *)
let boolTrait_ret_true
  (#self : Type0) (self_clause : boolTrait_t self) (self0 : self) :
  result bool
  =
  Return true

(** [traits::test_bool_trait_bool]: forward function *)
let test_bool_trait_bool (x : bool) : result bool =
  let* b = bool_get_bool x in
  if b then boolTrait_ret_true bool_BoolTraitInst x else Return false

(** [traits::Option::{1}::get_bool]: forward function *)
let option_get_bool (t : Type0) (self : option t) : result bool =
  begin match self with | None -> Return false | Some x -> Return true end

(** Trait implementation: [traits::Option::{1}] *)
let option_BoolTraitInst (t : Type0) : boolTrait_t (option t) = {
  get_bool = option_get_bool t;
}

(** [traits::test_bool_trait_option]: forward function *)
let test_bool_trait_option (t : Type0) (x : option t) : result bool =
  let* b = option_get_bool t x in
  if b then boolTrait_ret_true (option_BoolTraitInst t) x else Return false

(** [traits::test_bool_trait]: forward function *)
let test_bool_trait (t : Type0) (inst : boolTrait_t t) (x : t) : result bool =
  inst.get_bool x

(** Trait declaration: [traits::ToU64] *)
noeq type toU64_t (self : Type0) = { to_u64 : self -> result u64; }

(** [traits::u64::{2}::to_u64]: forward function *)
let u64_to_u64 (self : u64) : result u64 =
  Return self

(** Trait implementation: [traits::u64::{2}] *)
let u64_ToU64Inst : toU64_t u64 = { to_u64 = u64_to_u64; }

(** [traits::Tuple2::{3}::to_u64]: forward function *)
let tuple2_to_u64
  (a : Type0) (inst : toU64_t a) (self : (a & a)) : result u64 =
  let (x, x0) = self in
  let* i = inst.to_u64 x in
  let* i0 = inst.to_u64 x0 in
  u64_add i i0

(** Trait implementation: [traits::Tuple2::{3}] *)
let tuple2_ToU64Inst (a : Type0) (inst : toU64_t a) : toU64_t (a & a) = {
  to_u64 = tuple2_to_u64 a inst;
}

(** [traits::f]: forward function *)
let f (t : Type0) (inst : toU64_t t) (x : (t & t)) : result u64 =
  tuple2_to_u64 t inst x

(** [traits::g]: forward function *)
let g (t : Type0) (inst : toU64_t (t & t)) (x : (t & t)) : result u64 =
  inst.to_u64 x

(** [traits::h0]: forward function *)
let h0 (x : u64) : result u64 =
  u64_to_u64 x

(** [traits::Wrapper] *)
type wrapper_t (t : Type0) = { x : t; }

(** [traits::Wrapper::{4}::to_u64]: forward function *)
let wrapper_to_u64
  (t : Type0) (inst : toU64_t t) (self : wrapper_t t) : result u64 =
  inst.to_u64 self.x

(** Trait implementation: [traits::Wrapper::{4}] *)
let wrapper_ToU64Inst (t : Type0) (inst : toU64_t t) : toU64_t (wrapper_t t)
  = {
  to_u64 = wrapper_to_u64 t inst;
}

(** [traits::h1]: forward function *)
let h1 (x : wrapper_t u64) : result u64 =
  wrapper_to_u64 u64 u64_ToU64Inst x

(** [traits::h2]: forward function *)
let h2 (t : Type0) (inst : toU64_t t) (x : wrapper_t t) : result u64 =
  wrapper_to_u64 t inst x

(** Trait declaration: [traits::ToType] *)
noeq type toType_t (self t : Type0) = { to_type : self -> result t; }

(** [traits::u64::{5}::to_type]: forward function *)
let u64_to_type (self : u64) : result bool =
  Return (self > 0)

(** Trait implementation: [traits::u64::{5}] *)
let u64_ToTypeInst : toType_t u64 bool = { to_type = u64_to_type; }

(** Trait declaration: [traits::OfType] *)
noeq type ofType_t (self : Type0) = {
  of_type : (t : Type0) -> (inst : toType_t t self) -> t -> result self;
}

(** [traits::h3]: forward function *)
let h3
  (t1 t2 : Type0) (inst : ofType_t t1) (inst0 : toType_t t2 t1) (y : t2) :
  result t1
  =
  inst.of_type t2 inst0 y

(** Trait declaration: [traits::OfTypeBis] *)
noeq type ofTypeBis_t (self t : Type0) = {
  parent_clause_0 : toType_t t self;
  of_type : t -> result self;
}

(** [traits::h4]: forward function *)
let h4
  (t1 t2 : Type0) (inst : ofTypeBis_t t1 t2) (inst0 : toType_t t2 t1) 
  (y : t2) :
  result t1
  =
  inst.of_type y

(** [traits::TestType] *)
type testType_t (t : Type0) = { _0 : t; }

(** [traits::TestType::{6}::test::TestType1] *)
type testType_test_TestType1_t = { _0 : u64; }

(** Trait declaration: [traits::TestType::{6}::test::TestTrait] *)
noeq type testType_test_TestTrait_t (self : Type0) = {
  test : self -> result bool;
}

(** [traits::TestType::{6}::test::TestType1::{0}::test]: forward function *)
let testType_test_TestType1_test
  (self : testType_test_TestType1_t) : result bool =
  Return (self._0 > 1)

(** Trait implementation: [traits::TestType::{6}::test::TestType1::{0}] *)
let testType_test_TestType1_TestType_test_TestTraitInst :
  testType_test_TestTrait_t testType_test_TestType1_t = {
  test = testType_test_TestType1_test;
}

(** [traits::TestType::{6}::test]: forward function *)
let testType_test
  (t : Type0) (inst : toU64_t t) (self : testType_t t) (x : t) : result bool =
  let* x0 = inst.to_u64 x in
  if x0 > 0 then testType_test_TestType1_test { _0 = 0 } else Return false

(** [traits::BoolWrapper] *)
type boolWrapper_t = { _0 : bool; }

(** [traits::BoolWrapper::{7}::to_type]: forward function *)
let boolWrapper_to_type
  (t : Type0) (inst : toType_t bool t) (self : boolWrapper_t) : result t =
  inst.to_type self._0

(** Trait implementation: [traits::BoolWrapper::{7}] *)
let boolWrapper_ToTypeInst (t : Type0) (inst : toType_t bool t) : toType_t
  boolWrapper_t t = {
  to_type = boolWrapper_to_type t inst;
}

(** [traits::WithConstTy::LEN2] *)
let with_const_ty_len2_body : result usize = Return 32
let with_const_ty_len2_c : usize = eval_global with_const_ty_len2_body

(** Trait declaration: [traits::WithConstTy] *)
noeq type withConstTy_t (self : Type0) (len : usize) = {
  cLEN1 : usize;
  cLEN2 : usize;
  tV : Type0;
  tW : Type0;
  tW_clause_0 : toU64_t tW;
  f : tW -> array u8 len -> result tW;
}

(** [traits::Bool::{8}::LEN1] *)
let bool_len1_body : result usize = Return 12
let bool_len1_c : usize = eval_global bool_len1_body

(** [traits::Bool::{8}::f]: merged forward/backward function
    (there is a single backward function, and the forward function returns ()) *)
let bool_f (i : u64) (a : array u8 32) : result u64 =
  Return i

(** Trait implementation: [traits::Bool::{8}] *)
let bool_WithConstTyInst : withConstTy_t bool 32 = {
  cLEN1 = bool_len1_c;
  cLEN2 = with_const_ty_len2_c;
  tV = u8;
  tW = u64;
  tW_clause_0 = u64_ToU64Inst;
  f = bool_f;
}

(** [traits::use_with_const_ty1]: forward function *)
let use_with_const_ty1
  (h : Type0) (len : usize) (inst : withConstTy_t h len) : result usize =
  let i = inst.cLEN1 in Return i

(** [traits::use_with_const_ty2]: forward function *)
let use_with_const_ty2
  (h : Type0) (len : usize) (inst : withConstTy_t h len) (w : inst.tW) :
  result unit
  =
  Return ()

(** [traits::use_with_const_ty3]: forward function *)
let use_with_const_ty3
  (h : Type0) (len : usize) (inst : withConstTy_t h len) (x : inst.tW) :
  result u64
  =
  inst.tW_clause_0.to_u64 x

(** [traits::test_where1]: forward function *)
let test_where1 (t : Type0) (_x : t) : result unit =
  Return ()

(** [traits::test_where2]: forward function *)
let test_where2
  (t : Type0) (inst : withConstTy_t t 32) (_x : u32) : result unit =
  Return ()

(** [alloc::string::String] *)
assume type alloc_string_String_t : Type0

(** Trait declaration: [traits::ParentTrait0] *)
noeq type parentTrait0_t (self : Type0) = {
  tW : Type0;
  get_name : self -> result alloc_string_String_t;
  get_w : self -> result tW;
}

(** Trait declaration: [traits::ParentTrait1] *)
type parentTrait1_t (self : Type0) = unit

(** Trait declaration: [traits::ChildTrait] *)
noeq type childTrait_t (self : Type0) = {
  parent_clause_0 : parentTrait0_t self;
  parent_clause_1 : parentTrait1_t self;
}

(** [traits::test_child_trait1]: forward function *)
let test_child_trait1
  (t : Type0) (inst : childTrait_t t) (x : t) : result alloc_string_String_t =
  inst.parent_clause_0.get_name x

(** [traits::test_child_trait2]: forward function *)
let test_child_trait2
  (t : Type0) (inst : childTrait_t t) (x : t) :
  result inst.parent_clause_0.tW
  =
  inst.parent_clause_0.get_w x

(** [traits::order1]: forward function *)
let order1
  (t u : Type0) (inst : parentTrait0_t t) (inst0 : parentTrait0_t u) :
  result unit
  =
  Return ()

(** Trait declaration: [traits::ChildTrait1] *)
noeq type childTrait1_t (self : Type0) = {
  parent_clause_0 : parentTrait1_t self;
}

(** Trait implementation: [traits::usize::{9}] *)
let usize_ParentTrait1Inst : parentTrait1_t usize = ()

(** Trait implementation: [traits::usize::{10}] *)
let usize_ChildTrait1Inst : childTrait1_t usize = {
  parent_clause_0 = usize_ParentTrait1Inst;
}

(** Trait declaration: [traits::Iterator] *)
noeq type iterator_t (self : Type0) = { tItem : Type0; }

(** Trait declaration: [traits::IntoIterator] *)
noeq type intoIterator_t (self : Type0) = {
  tItem : Type0;
  tIntoIter : Type0;
  tIntoIter_clause_0 : iterator_t tIntoIter;
  into_iter : self -> result tIntoIter;
}

(** Trait declaration: [traits::FromResidual] *)
type fromResidual_t (self t : Type0) = unit

(** Trait declaration: [traits::Try] *)
noeq type try_t (self : Type0) = {
  tResidual : Type0;
  parent_clause_0 : fromResidual_t self tResidual;
}

(** Trait declaration: [traits::WithTarget] *)
noeq type withTarget_t (self : Type0) = { tTarget : Type0; }

(** Trait declaration: [traits::ParentTrait2] *)
noeq type parentTrait2_t (self : Type0) = {
  tU : Type0;
  tU_clause_0 : withTarget_t tU;
}

(** Trait declaration: [traits::ChildTrait2] *)
noeq type childTrait2_t (self : Type0) = {
  parent_clause_0 : parentTrait2_t self;
  convert : parent_clause_0.tU -> result parent_clause_0.tU_clause_0.tTarget;
}

(** Trait implementation: [traits::u32::{11}] *)
let u32_WithTargetInst : withTarget_t u32 = { tTarget = u32; }

(** Trait implementation: [traits::u32::{12}] *)
let u32_ParentTrait2Inst : parentTrait2_t u32 = {
  tU = u32;
  tU_clause_0 = u32_WithTargetInst;
}

(** [traits::u32::{13}::convert]: forward function *)
let u32_convert (x : u32) : result u32 =
  Return x

(** Trait implementation: [traits::u32::{13}] *)
let u32_ChildTrait2Inst : childTrait2_t u32 = {
  parent_clause_0 = u32_ParentTrait2Inst;
  convert = u32_convert;
}

(** [traits::incr_u32]: forward function *)
let incr_u32 (x : u32) : result u32 =
  u32_add x 1

(** Trait declaration: [traits::CFnOnce] *)
noeq type cFnOnce_t (self args : Type0) = {
  tOutput : Type0;
  call_once : self -> args -> result tOutput;
}

(** Trait declaration: [traits::CFnMut] *)
noeq type cFnMut_t (self args : Type0) = {
  parent_clause_0 : cFnOnce_t self args;
  call_mut : self -> args -> result parent_clause_0.tOutput;
  call_mut_back : self -> args -> parent_clause_0.tOutput -> result self;
}

(** Trait declaration: [traits::CFn] *)
noeq type cFn_t (self args : Type0) = {
  parent_clause_0 : cFnMut_t self args;
  call_mut : self -> args -> result parent_clause_0.parent_clause_0.tOutput;
}