package / ocaml-base-compiler.4.10.0 / middle_end / semantics_of_primitives.mli
1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Pierre Chambart, OCamlPro *)
6 (* Mark Shinwell and Leo White, Jane Street Europe *)
7 (* *)
8 (* Copyright 2013--2016 OCamlPro SAS *)
9 (* Copyright 2014--2016 Jane Street Group LLC *)
10 (* *)
11 (* All rights reserved. This file is distributed under the terms of *)
12 (* the GNU Lesser General Public License version 2.1, with the *)
13 (* special exception on linking described in the file LICENSE. *)
14 (* *)
15 (**************************************************************************)
16
17 [@@@ocaml.warning "+a-4-9-30-40-41-42"]
18
19 (** Description of the semantics of primitives, to be used for optimization
20 purposes.
21
22 "No effects" means that the primitive does not change the observable state
23 of the world. For example, it must not write to any mutable storage,
24 call arbitrary external functions or change control flow (e.g. by raising
25 an exception). Note that allocation is not "No effects" (see below).
26
27 It is assumed in the compiler that applications of primitives with no
28 effects, whose results are not used, may be eliminated. It is further
29 assumed that applications of primitives with no effects may be
30 duplicated (and thus possibly executed more than once).
31
32 (Exceptions arising from allocation points, for example "out of memory" or
33 exceptions propagated from finalizers or signal handlers, are treated as
34 "effects out of the ether" and thus ignored for our determination here
35 of effectfulness. The same goes for floating point operations that may
36 cause hardware traps on some platforms.)
37
38 "Only generative effects" means that a primitive does not change the
39 observable state of the world save for possibly affecting the state of
40 the garbage collector by performing an allocation. Applications of
41 primitives that only have generative effects and whose results are unused
42 may be eliminated by the compiler. However, unlike "No effects"
43 primitives, such applications will never be eligible for duplication.
44
45 "Arbitrary effects" covers all other primitives.
46
47 "No coeffects" means that the primitive does not observe the effects (in
48 the sense described above) of other expressions. For example, it must not
49 read from any mutable storage or call arbitrary external functions.
50
51 It is assumed in the compiler that, subject to data dependencies,
52 expressions with neither effects nor coeffects may be reordered with
53 respect to other expressions.
54 *)
55
56 type effects = No_effects | Only_generative_effects | Arbitrary_effects
57 type coeffects = No_coeffects | Has_coeffects
58
59 (** Describe the semantics of a primitive. This does not take into account of
60 the (non-)(co)effectfulness of the arguments in a primitive application.
61 To determine whether such an application is (co)effectful, the arguments
62 must also be analysed. *)
63 val for_primitive: Clambda_primitives.primitive -> effects * coeffects
64
65 type return_type =
66 | Float
67 | Other
68
69 val return_type_of_primitive: Clambda_primitives.primitive -> return_type
70