Skip to content

Commit 42b4235

Browse files
authored
Merge pull request ocaml#38 from Gbury/flambda2.0-stable-uncp-fix
Bugfixes for Un_cps
2 parents d189909 + fa8a5dc commit 42b4235

File tree

10 files changed

+314
-155
lines changed

10 files changed

+314
-155
lines changed

middle_end/flambda2.0/basic/coeffects.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ let compare co1 co2 =
2929
| No_coeffects, Has_coeffects -> -1
3030
| Has_coeffects, Has_coeffects -> 0
3131
| Has_coeffects, No_coeffects -> 1
32+
33+
let join co1 co2 =
34+
match co1, co2 with
35+
| No_coeffects, No_coeffects -> No_coeffects
36+
| No_coeffects, Has_coeffects
37+
| Has_coeffects, Has_coeffects
38+
| Has_coeffects, No_coeffects -> Has_coeffects

middle_end/flambda2.0/basic/coeffects.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ val print : Format.formatter -> t -> unit
3434

3535
val compare : t -> t -> int
3636
(** Comparison function. *)
37+
38+
val join : t -> t -> t
39+
(** Join two coeffects. *)
40+
41+

middle_end/flambda2.0/basic/effects.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ let compare_mutable_or_immutable mut1 mut2 =
3434
| Immutable, Mutable -> -1
3535
| Mutable, Immutable -> 1
3636

37+
let join_mutable_or_immutable mut1 mut2 =
38+
match mut1, mut2 with
39+
| Immutable, Immutable -> Immutable
40+
| Mutable, Mutable
41+
| Immutable, Mutable
42+
| Mutable, Immutable -> Mutable
3743

3844
(* Effects *)
3945

@@ -64,4 +70,17 @@ let compare eff1 eff2 =
6470
| Arbitrary_effects, Arbitrary_effects -> 0
6571
| Arbitrary_effects, (No_effects | Only_generative_effects _) -> 1
6672

73+
let join eff1 eff2 =
74+
match eff1, eff2 with
75+
| No_effects, No_effects
76+
| No_effects, Only_generative_effects _
77+
| No_effects, Arbitrary_effects -> eff2
78+
| Only_generative_effects _, No_effects -> eff1
79+
| Only_generative_effects mut1,
80+
Only_generative_effects mut2 ->
81+
Only_generative_effects (join_mutable_or_immutable mut1 mut2)
82+
| Only_generative_effects _, Arbitrary_effects -> eff2
83+
| Arbitrary_effects, No_effects
84+
| Arbitrary_effects, Only_generative_effects _
85+
| Arbitrary_effects, Arbitrary_effects -> eff1
6786

middle_end/flambda2.0/basic/effects.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ val print : Format.formatter -> t -> unit
6666

6767
val compare : t -> t -> int
6868
(** Comparison function. *)
69+
70+
val join : t -> t -> t
71+
(** join two effects, effectively computing the maximum of the two
72+
given effects. *)

middle_end/flambda2.0/basic/effects_and_coeffects.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ let compare (e1, c1) (e2, c2) =
2323
| 0 -> Coeffects.compare c1 c2
2424
| res -> res
2525

26+
(* Some useful constants *)
2627
let pure : t = No_effects, No_coeffects
2728
let all : t = Arbitrary_effects, Has_coeffects
29+
let read : t = No_effects, Has_coeffects
30+
31+
(* Joining effects and coeffects *)
32+
let join (eff1, coeff1) (eff2, coeff2) =
33+
Effects.join eff1 eff2, Coeffects.join coeff1 coeff2
34+
2835

2936
(* For the purpose of commuting (i.e. there is no duplication),
3037
generative effects do not count. *)

middle_end/flambda2.0/basic/effects_and_coeffects.mli

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ val all : t
3131
(** The value stating that any effects and/or coeffects may take
3232
place. This is exactly [Arbitrary_effects, Has_coeffects]. *)
3333

34+
val read : t
35+
(** The calue stating that a read (i.e only a coeffect) takes place.
36+
This is [No_effects, Has_coeffects]. *)
37+
3438
val is_pure : t -> bool
3539
(** Is the expression with the given effects and coeffects pure ?
3640
In other words, can it commute with any expression ? *)
@@ -43,3 +47,12 @@ val has_commuting_effects : t -> bool
4347
(** Does the given effects and coeffects has observable effects ?
4448
Rather, does it have some effects with regards to whether it can
4549
commute with other expressions. *)
50+
51+
val has_commuting_coeffects : t -> bool
52+
(** Does the given effects and coeffects has observable coeffects ?
53+
Rather, does it have some coeffects with regards to whether it can
54+
commute with other expressions. *)
55+
56+
val join : t -> t -> t
57+
(** Join two effects and coeffects. *)
58+

0 commit comments

Comments
 (0)