Skip to content

Commit

Permalink
flambda-backend: ocamlformat in JS-only files in lambda (#1882)
Browse files Browse the repository at this point in the history
ocamlformat in JS-only files in lambda/

Co-authored-by: Zesen Qian <[email protected]>
  • Loading branch information
goldfirere and riaqn authored Apr 2, 2024
1 parent 57eacdb commit 386de39
Show file tree
Hide file tree
Showing 12 changed files with 586 additions and 575 deletions.
24 changes: 20 additions & 4 deletions lambda/.ocamlformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
profile=conventional
if-then-else=k-r
indicate-multiline-delimiters=closing-on-separate-line
break-cases=all
# Please make a pull request to change this file.
disable=true
# There is an .ocamlformat-enable file in this directory.
# Keep the remainder of this file in sync with other .ocamlformat files in this repo.
assignment-operator=begin-line
cases-exp-indent=2
doc-comments=before
dock-collection-brackets=false
if-then-else=keyword-first
module-item-spacing=sparse
parens-tuple=multi-line-only
sequence-blank-line=compact
space-around-lists=false
space-around-variants=false
type-decl=sparse
version=0.24.1

# The existing comments are hand-formatted and lose a lot of readability
# if we wrap them. We should either convert the comments we care about to
# doc comments, or make this same setting change everywhere.
wrap-comments=false
8 changes: 8 additions & 0 deletions lambda/.ocamlformat-enable
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
assume_info.ml
assume_info.mli
transl_array_comprehension.ml
transl_array_comprehension.mli
transl_comprehension_utils.ml
transl_comprehension_utils.mli
transl_list_comprehension.ml
transl_list_comprehension.mli
translmode.ml
translmode.mli
47 changes: 17 additions & 30 deletions lambda/assume_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,26 @@ module Witnesses = struct
type t = unit

let join _ _ = ()

let lessequal _ _ = true

let meet _ _ = ()

let print _ _ = ()

let empty = ()

let compare _ _ = 0
end

include Zero_alloc_utils.Make (Witnesses)

type t = No_assume | Assume of Value.t
type t =
| No_assume
| Assume of Value.t

let compare t1 t2 =
match (t1, t2) with
match t1, t2 with
| No_assume, No_assume -> 0
| Assume v1, Assume v2 -> Value.compare v1 v2
| No_assume, Assume _ -> -1
Expand All @@ -61,44 +68,24 @@ let print ppf = function
let to_string v = Format.asprintf "%a" print v

let join t1 t2 =
match (t1, t2) with
match t1, t2 with
| No_assume, No_assume -> No_assume
| No_assume, Assume _
| Assume _, No_assume ->
No_assume
| No_assume, Assume _ | Assume _, No_assume -> No_assume
| Assume t1, Assume t2 -> Assume (Value.join t1 t2)

let meet t1 t2 =
match (t1, t2) with
match t1, t2 with
| No_assume, No_assume -> No_assume
| No_assume, (Assume _ as t)
| (Assume _ as t), No_assume ->
t
| No_assume, (Assume _ as t) | (Assume _ as t), No_assume -> t
| Assume t1, Assume t2 -> Assume (Value.meet t1 t2)

let none = No_assume

let create ~strict ~never_returns_normally =
let res =
if strict then
Value.safe
else
Value.relaxed Witnesses.empty
in
let res =
if never_returns_normally then
{ res with nor = V.Bot }
else
res
in
let res = if strict then Value.safe else Value.relaxed Witnesses.empty in
let res = if never_returns_normally then { res with nor = V.Bot } else res in
Assume res

let get_value t =
match t with
| No_assume -> None
| Assume v -> Some v
let get_value t = match t with No_assume -> None | Assume v -> Some v

let is_none t =
match t with
| No_assume -> true
| Assume _ -> false
let is_none t = match t with No_assume -> true | Assume _ -> false
12 changes: 12 additions & 0 deletions lambda/assume_info.mli
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
type t

val none : t

val create : strict:bool -> never_returns_normally:bool -> t

val compare : t -> t -> int

val equal : t -> t -> bool

val join : t -> t -> t

val meet : t -> t -> t

val to_string : t -> string

val print : Format.formatter -> t -> unit

val is_none : t -> bool

module Witnesses : sig
type t = unit

val join : t -> t -> t

val meet : t -> t -> t

val lessequal : t -> t -> bool

val print : Format.formatter -> t -> unit

val compare : t -> t -> int
end

Expand Down
Loading

0 comments on commit 386de39

Please sign in to comment.