-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathfexpr.ml
563 lines (466 loc) · 12.4 KB
/
fexpr.ml
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
type location = Lambda.scoped_location
type 'a located =
{ txt : 'a;
loc : location
}
type variable = string located
type continuation_id = string located
type code_id = string located
type function_slot = string located
type value_slot = string located
type compilation_unit =
{ ident : string;
linkage_name : string option (* defaults to same as ident *)
}
type symbol = (compilation_unit option * string) located
type immediate = string
type targetint = int64
type special_continuation =
| Done
(* top-level normal continuation *)
| Error
(* top-level exception continuation *)
type continuation =
| Named of continuation_id
| Special of special_continuation
type result_continuation =
| Return of continuation
| Never_returns
type continuation_sort =
| Normal
| Exn
| Define_root_symbol
(* There's also [Return] and [Toplevel_return], but those don't need to be
* specified explicitly *)
type region =
| Named of variable
| Toplevel
type const =
| Naked_immediate of immediate
| Tagged_immediate of immediate
| Naked_float of float
| Naked_int32 of int32
| Naked_int64 of int64
| Naked_vec128 of Vector_types.Vec128.Bit_pattern.bits
| Naked_nativeint of targetint
type field_of_block =
| Symbol of symbol
| Tagged_immediate of immediate
| Dynamically_computed of variable
type is_recursive =
| Nonrecursive
| Recursive
type tag_scannable = int
type mutability = Mutability.t =
| Mutable
| Immutable
| Immutable_unique
type empty_array_kind = Empty_array_kind.t
type 'a or_variable =
| Const of 'a
| Var of variable
type static_data =
| Block of
{ tag : tag_scannable;
mutability : mutability;
elements : field_of_block list
}
| Boxed_float of float or_variable
| Boxed_int32 of int32 or_variable
| Boxed_int64 of int64 or_variable
| Boxed_nativeint of targetint or_variable
| Boxed_vec128 of Vector_types.Vec128.Bit_pattern.bits or_variable
| Immutable_float_block of float or_variable list
| Immutable_float_array of float or_variable list
| Immutable_value_array of field_of_block list
| Empty_array of empty_array_kind
| Mutable_string of { initial_value : string }
| Immutable_string of string
type kind = Flambda_kind.t
type subkind =
| Anything
| Boxed_float
| Boxed_int32
| Boxed_int64
| Boxed_nativeint
| Boxed_vec128
| Tagged_immediate
| Variant of
{ consts : targetint list;
non_consts : (tag_scannable * kind_with_subkind list) list
}
| Float_block of { num_fields : int }
| Float_array
| Immediate_array
| Value_array
| Generic_array
and kind_with_subkind =
| Value of subkind
| Naked_number of Flambda_kind.Naked_number_kind.t
| Region
| Rec_info
type static_data_binding =
{ symbol : symbol;
defining_expr : static_data
}
type raise_kind = Trap_action.Raise_kind.t =
| Regular
| Reraise
| No_trace
type trap_action =
| Push of { exn_handler : continuation }
| Pop of
{ exn_handler : continuation;
raise_kind : raise_kind option
}
type rec_info =
| Depth of int
| Infinity
| Do_not_inline
| Var of variable
| Succ of rec_info
| Unroll of int * rec_info
type coercion =
| Id
| Change_depth of
{ from : rec_info;
to_ : rec_info
}
type kinded_parameter =
{ param : variable;
kind : kind_with_subkind option
}
type name =
| Var of variable
| Symbol of symbol
type simple =
| Var of variable
| Symbol of symbol
| Const of const
| Coerce of simple * coercion
type array_kind = Flambda_primitive.Array_kind.t =
| Immediates
| Values
| Naked_floats
| Naked_int32s
| Naked_int64s
| Naked_nativeints
type box_kind = Flambda_kind.Boxable_number.t =
| Naked_float
| Naked_int32
| Naked_int64
| Naked_nativeint
| Naked_vec128
type generic_array_specialisation =
| No_specialisation
| Full_of_naked_floats
| Full_of_immediates
| Full_of_arbitrary_values_but_not_floats
type block_access_field_kind = Flambda_primitive.Block_access_field_kind.t =
| Any_value
| Immediate
type block_access_kind =
| Values of
{ tag : tag_scannable option;
size : targetint option;
field_kind : block_access_field_kind
}
| Naked_floats of { size : targetint option }
type standard_int = Flambda_kind.Standard_int.t =
| Tagged_immediate
| Naked_immediate
| Naked_int32
| Naked_int64
| Naked_nativeint
type standard_int_or_float = Flambda_kind.Standard_int_or_float.t =
| Tagged_immediate
| Naked_immediate
| Naked_float
| Naked_int32
| Naked_int64
| Naked_nativeint
type string_or_bytes = Flambda_primitive.string_or_bytes =
| String
| Bytes
type alloc_mode_for_allocations =
| Heap
| Local of { region : region }
type alloc_mode_for_assignments =
| Heap
| Local
type init_or_assign =
| Initialization
| Assignment of alloc_mode_for_assignments
type 'signed_or_unsigned comparison =
'signed_or_unsigned Flambda_primitive.comparison =
| Eq
| Neq
| Lt of 'signed_or_unsigned
| Gt of 'signed_or_unsigned
| Le of 'signed_or_unsigned
| Ge of 'signed_or_unsigned
type equality_comparison = Flambda_primitive.equality_comparison =
| Eq
| Neq
type signed_or_unsigned = Flambda_primitive.signed_or_unsigned =
| Signed
| Unsigned
type nullop =
| Begin_region
| Begin_try_region
type unary_int_arith_op = Flambda_primitive.unary_int_arith_op =
| Neg
| Swap_byte_endianness
type array_kind_for_length = Flambda_primitive.Array_kind_for_length.t =
| Array_kind of array_kind
| Float_array_opt_dynamic
type unop =
| Array_length of array_kind_for_length
| Boolean_not
| Box_number of box_kind * alloc_mode_for_allocations
| End_region
| End_try_region
| Get_tag
| Int_arith of standard_int * unary_int_arith_op
| Is_flat_float_array
| Is_int
| Num_conv of
{ src : standard_int_or_float;
dst : standard_int_or_float
}
| Opaque_identity
| Project_value_slot of
{ project_from : function_slot;
value_slot : value_slot
}
| Project_function_slot of
{ move_from : function_slot;
move_to : function_slot
}
| String_length of string_or_bytes
| Unbox_number of box_kind
| Untag_immediate
| Tag_immediate
type 'signed_or_unsigned comparison_behaviour =
'signed_or_unsigned Flambda_primitive.comparison_behaviour =
| Yielding_bool of 'signed_or_unsigned comparison
| Yielding_int_like_compare_functions of 'signed_or_unsigned
type binary_int_arith_op = Flambda_primitive.binary_int_arith_op =
| Add
| Sub
| Mul
| Div
| Mod
| And
| Or
| Xor
type int_shift_op = Flambda_primitive.int_shift_op =
| Lsl
| Lsr
| Asr
type binary_float_arith_op = Flambda_primitive.binary_float_arith_op =
| Add
| Sub
| Mul
| Div
type string_accessor_width = Flambda_primitive.string_accessor_width =
| Eight
| Sixteen
| Thirty_two
| Sixty_four
| One_twenty_eight of { aligned : bool }
type array_accessor_width = Flambda_primitive.array_accessor_width =
| Scalar
| Vec128
type string_like_value = Flambda_primitive.string_like_value =
| String
| Bytes
| Bigstring
type bytes_like_value = Flambda_primitive.bytes_like_value =
| Bytes
| Bigstring
type infix_binop =
| Int_arith of binary_int_arith_op (* on tagged immediates *)
| Int_shift of int_shift_op (* on tagged immediates *)
| Int_comp of signed_or_unsigned comparison_behaviour (* on tagged imms *)
| Float_arith of binary_float_arith_op
| Float_comp of unit comparison_behaviour
type binop =
| Array_load of array_kind * array_accessor_width * mutability
| Block_load of block_access_kind * mutability
| Phys_equal of equality_comparison
| Int_arith of standard_int * binary_int_arith_op
| Int_comp of standard_int * signed_or_unsigned comparison_behaviour
| Int_shift of standard_int * int_shift_op
| Infix of infix_binop
| String_or_bigstring_load of string_like_value * string_accessor_width
| Bigarray_get_alignment of int
type ternop =
(* CR mshinwell: Array_set should use "array_set_kind" *)
| Array_set of array_kind * array_accessor_width * init_or_assign
| Block_set of block_access_kind * init_or_assign
| Bytes_or_bigstring_set of bytes_like_value * string_accessor_width
type varop =
| Make_block of tag_scannable * mutability * alloc_mode_for_allocations
type prim =
| Nullary of nullop
| Unary of unop * simple
| Binary of binop * simple * simple
| Ternary of ternop * simple * simple * simple
| Variadic of varop * simple list
type arity = kind_with_subkind list
type function_call =
| Direct of
{ code_id : code_id;
function_slot : function_slot option;
alloc : alloc_mode_for_allocations
}
| Indirect of alloc_mode_for_allocations
(* Will translate to indirect_known_arity or indirect_unknown_arity depending on
whether the apply record's arities field has a value *)
type method_kind =
| Self
| Public
| Cached
type call_kind =
| Function of function_call
(* | Method of { kind : method_kind; obj : simple; } *)
| C_call of { alloc : bool }
type function_arities =
{ params_arity : arity option;
ret_arity : arity
}
type inline_attribute = Inline_attribute.t =
| Always_inline
| Available_inline
| Never_inline
| Unroll of int
| Default_inline
type inlined_attribute =
| Always_inlined
| Hint_inlined
| Never_inlined
| Unroll of int
| Default_inlined
type inlining_state = { depth : int (* CR lmaurer: Add inlining arguments *) }
type loopify_attribute = Loopify_attribute.t =
| Always_loopify
| Never_loopify
| Already_loopified
| Default_loopify_and_tailrec
| Default_loopify_and_not_tailrec
type apply =
{ func : simple;
continuation : result_continuation;
exn_continuation : continuation;
args : simple list;
call_kind : call_kind;
arities : function_arities option;
inlined : inlined_attribute option;
inlining_state : inlining_state option
}
type size = int
type apply_cont =
{ cont : continuation;
trap_action : trap_action option;
args : simple list
}
type expr =
| Let of let_
| Let_cont of let_cont
| Let_symbol of let_symbol
| Apply of apply
| Apply_cont of apply_cont
| Switch of
{ scrutinee : simple;
cases : (int * apply_cont) list
}
| Invalid of { message : string }
and value_slots = one_value_slot list
and one_value_slot =
{ var : value_slot;
value : simple
}
and let_ =
{ bindings : let_binding list;
value_slots : value_slots option;
body : expr
}
and let_binding =
{ var : variable;
defining_expr : named
}
and named =
| Simple of simple
| Prim of prim
| Closure of fun_decl
| Rec_info of rec_info
and fun_decl =
{ code_id : code_id;
function_slot : function_slot option (* defaults to same name as code id *);
alloc : alloc_mode_for_allocations
(* alloc mode for set of closures (ignored except on first binding) *)
}
and let_cont =
{ recursive : is_recursive;
body : expr;
bindings : continuation_binding list
}
and continuation_binding =
{ name : continuation_id;
params : kinded_parameter list;
sort : continuation_sort option;
handler : expr
}
and let_symbol =
{ bindings : symbol_binding list;
(* Only used if there's no [Set_of_closures] in the list *)
value_slots : value_slots option;
body : expr
}
and symbol_binding =
| Data of static_data_binding
| Code of code
| Deleted_code of code_id
| Closure of static_closure_binding
| Set_of_closures of static_set_of_closures
and static_set_of_closures =
{ bindings : static_closure_binding list;
elements : value_slots option
}
and code =
{ id : code_id;
newer_version_of : code_id option;
param_arity : arity option;
ret_arity : arity option;
recursive : is_recursive;
inline : inline_attribute option;
params_and_body : params_and_body;
code_size : code_size;
is_tupled : bool;
loopify : loopify_attribute option;
result_mode : alloc_mode_for_assignments
}
and code_size = int
and params_and_body =
{ params : kinded_parameter list;
closure_var : variable;
region_var : variable;
depth_var : variable;
ret_cont : continuation_id;
exn_cont : continuation_id;
body : expr
}
and static_closure_binding =
{ symbol : symbol;
fun_decl : fun_decl
}
type flambda_unit = { body : expr }
type expect_test_spec =
{ before : flambda_unit;
after : flambda_unit
}
type markdown_node =
| Text of string
| Expect of expect_test_spec
type markdown_doc = markdown_node list