Skip to content

Commit

Permalink
Clarify the types used for static jump/catch (ocaml-flambda#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gbury authored and mshinwell committed Mar 9, 2023
1 parent 7932502 commit 140116a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
13 changes: 8 additions & 5 deletions backend/cmm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,8 @@ type float_comparison = Lambda.float_comparison =
let negate_float_comparison = Lambda.negate_float_comparison

let swap_float_comparison = Lambda.swap_float_comparison
type label = int

type exit_label =
| Return_lbl
| Lbl of label
type label = int

let init_label = 99

Expand All @@ -128,6 +125,12 @@ let cur_label () = !label_counter

let new_label() = incr label_counter; !label_counter

type static_label = Lambda.static_label

type exit_label =
| Return_lbl
| Lbl of static_label

type rec_flag = Nonrecursive | Recursive

type prefetch_temporal_locality_hint = Nonlocal | Low | Moderate | High
Expand Down Expand Up @@ -242,7 +245,7 @@ type expression =
* Debuginfo.t * value_kind
| Ccatch of
rec_flag
* (label * (Backend_var.With_provenance.t * machtype) list
* (static_label * (Backend_var.With_provenance.t * machtype) list
* expression * Debuginfo.t) list
* expression * value_kind
| Cexit of exit_label * expression list * trap_action list
Expand Down
6 changes: 3 additions & 3 deletions backend/cmm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ val cur_label: unit -> label

type exit_label =
| Return_lbl
| Lbl of label
| Lbl of Lambda.static_label

type rec_flag = Nonrecursive | Recursive

Expand Down Expand Up @@ -138,7 +138,7 @@ type phantom_defining_expr =
(** The phantom-let-bound variable points at a block with the given
structure. *)

type trywith_shared_label = int (* Same as Ccatch handlers *)
type trywith_shared_label = Lambda.static_label (* Same as Ccatch handlers *)

type trap_action =
| Push of trywith_shared_label
Expand Down Expand Up @@ -250,7 +250,7 @@ type expression =
* Debuginfo.t * value_kind
| Ccatch of
rec_flag
* (label * (Backend_var.With_provenance.t * machtype) list
* (Lambda.static_label * (Backend_var.With_provenance.t * machtype) list
* expression * Debuginfo.t) list
* expression
* value_kind
Expand Down
8 changes: 6 additions & 2 deletions backend/cmm_helpers.mli
Original file line number Diff line number Diff line change
Expand Up @@ -994,14 +994,18 @@ type static_handler
binding variables [vars] in [body]. *)
val handler :
dbg:Debuginfo.t ->
int ->
Lambda.static_label ->
(Backend_var.With_provenance.t * Cmm.machtype) list ->
Cmm.expression ->
static_handler

(** [cexit id args] creates the cmm expression for static to a static handler
with exit number [id], with arguments [args]. *)
val cexit : int -> Cmm.expression list -> Cmm.trap_action list -> Cmm.expression
val cexit :
Lambda.static_label ->
Cmm.expression list ->
Cmm.trap_action list ->
Cmm.expression

(** [trap_return res traps] creates the cmm expression for returning [res] after
applying the trap actions in [traps]. *)
Expand Down
6 changes: 2 additions & 4 deletions middle_end/flambda2/to_cmm/to_cmm_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type expr_with_info =

type cont =
| Jump of
{ cont : Cmm.label;
{ cont : Lambda.static_label;
param_types : Cmm.machtype list
}
| Inline of
Expand Down Expand Up @@ -317,10 +317,8 @@ let get_continuation env k =
Continuation.print k
| res -> res

let new_cmm_continuation = Lambda.next_raise_count

let add_jump_cont env k ~param_types =
let cont = new_cmm_continuation () in
let cont = Lambda.next_raise_count () in
let conts = Continuation.Map.add k (Jump { param_types; cont }) env.conts in
cont, { env with conts }

Expand Down
9 changes: 6 additions & 3 deletions middle_end/flambda2/to_cmm/to_cmm_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ val extra_info : t -> Simple.t -> extra_info option
label), or inlined at any unique use site. *)
type cont = private
| Jump of
{ cont : Cmm.label;
{ cont : Lambda.static_label;
param_types : Cmm.machtype list
}
| Inline of
Expand All @@ -292,7 +292,10 @@ type cont = private
(** Record that the given continuation should be compiled to a jump, creating a
fresh Cmm continuation identifier for it. *)
val add_jump_cont :
t -> Continuation.t -> param_types:Cmm.machtype list -> Cmm.label * t
t ->
Continuation.t ->
param_types:Cmm.machtype list ->
Lambda.static_label * t

(** Record that the given continuation should be inlined. *)
val add_inline_cont :
Expand Down Expand Up @@ -327,4 +330,4 @@ val get_continuation : t -> Continuation.t -> cont
(** Returns the Cmm continuation identifier bound to a continuation. Produces a
fatal error if given an unbound continuation, or a continuation that was
registered (using [add_inline_cont]) to be inlined. *)
val get_cmm_continuation : t -> Continuation.t -> Cmm.label
val get_cmm_continuation : t -> Continuation.t -> Lambda.static_label
6 changes: 4 additions & 2 deletions ocaml/lambda/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ let equal_meth_kind x y =

type shared_code = (int * int) list

type static_label = int

type function_attribute = {
inline : inline_attribute;
specialise : specialise_attribute;
Expand Down Expand Up @@ -461,8 +463,8 @@ type lambda =
| Lswitch of lambda * lambda_switch * scoped_location * layout
| Lstringswitch of
lambda * (string * lambda) list * lambda option * scoped_location * layout
| Lstaticraise of int * lambda list
| Lstaticcatch of lambda * (int * (Ident.t * layout) list) * lambda * layout
| Lstaticraise of static_label * lambda list
| Lstaticcatch of lambda * (static_label * (Ident.t * layout) list) * lambda * layout
| Ltrywith of lambda * Ident.t * lambda * layout
| Lifthenelse of lambda * lambda * lambda * layout
| Lsequence of lambda * lambda
Expand Down
8 changes: 5 additions & 3 deletions ocaml/lambda/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ val equal_meth_kind : meth_kind -> meth_kind -> bool

type shared_code = (int * int) list (* stack size -> code label *)

type static_label = int

type function_attribute = {
inline : inline_attribute;
specialise : specialise_attribute;
Expand Down Expand Up @@ -369,8 +371,8 @@ type lambda =
strings are pairwise distinct *)
| Lstringswitch of
lambda * (string * lambda) list * lambda option * scoped_location * layout
| Lstaticraise of int * lambda list
| Lstaticcatch of lambda * (int * (Ident.t * layout) list) * lambda * layout
| Lstaticraise of static_label * lambda list
| Lstaticcatch of lambda * (static_label * (Ident.t * layout) list) * lambda * layout
| Ltrywith of lambda * Ident.t * lambda * layout
(* Lifthenelse (e, t, f, layout) evaluates t if e evaluates to 0, and evaluates f if
e evaluates to any other value; layout must be the layout of [t] and [f] *)
Expand Down Expand Up @@ -618,7 +620,7 @@ val primitive_may_allocate : primitive -> alloc_mode option
(***********************)

(* Get a new static failure ident *)
val next_raise_count : unit -> int
val next_raise_count : unit -> static_label

val staticfail : lambda (* Anticipated static failure *)

Expand Down

0 comments on commit 140116a

Please sign in to comment.