Skip to content

Commit

Permalink
flambda-backend: Revert "Support stack_ exp syntax" (#2753)
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn authored Jul 2, 2024
1 parent b35bb0d commit 0f30fe9
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 478 deletions.
1 change: 0 additions & 1 deletion boot/menhir/parser.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type token =
| STRUCT
| STRING of (string * Location.t * string option)
| STAR
| STACK
| SIG
| SEMISEMI
| SEMI
Expand Down
24 changes: 12 additions & 12 deletions lambda/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ let fuse_method_arity (parent : fusable_function) : fusable_function =
(function (Texp_poly _, _, _) -> true | _ -> false)
exp_extra
->
begin match transl_alloc_mode method_.alloc_mode with
begin match transl_alloc_mode_r method_.alloc_mode with
| Alloc_heap -> ()
| Alloc_local ->
(* If we support locally-allocated objects, we'll also have to
Expand Down Expand Up @@ -466,7 +466,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
Lconst(Const_block(0, List.map extract_constant ll))
with Not_constant ->
Lprim(Pmakeblock(0, Immutable, Some shape,
transl_alloc_mode alloc_mode),
transl_alloc_mode_r alloc_mode),
ll,
(of_location ~scopes e.exp_loc))
end
Expand Down Expand Up @@ -508,7 +508,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
begin match const_block with
| Some const_block -> const_block
| None ->
let alloc_mode = transl_alloc_mode (Option.get alloc_mode) in
let alloc_mode = transl_alloc_mode_r (Option.get alloc_mode) in
let makeblock =
match cstr.cstr_shape with
| Constructor_uniform_value ->
Expand All @@ -534,7 +534,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
that out by checking that the sort list is empty *)
lam)
else
let alloc_mode = transl_alloc_mode (Option.get alloc_mode) in
let alloc_mode = transl_alloc_mode_r (Option.get alloc_mode) in
let makeblock =
match cstr.cstr_shape with
| Constructor_uniform_value ->
Expand Down Expand Up @@ -569,13 +569,13 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
extract_constant lam]))
with Not_constant ->
Lprim(Pmakeblock(0, Immutable, None,
transl_alloc_mode alloc_mode),
transl_alloc_mode_r alloc_mode),
[Lconst(const_int tag); lam],
of_location ~scopes e.exp_loc)
end
| Texp_record {fields; representation; extended_expression; alloc_mode} ->
transl_record ~scopes e.exp_loc e.exp_env
(Option.map transl_alloc_mode alloc_mode)
(Option.map transl_alloc_mode_r alloc_mode)
fields representation extended_expression
| Texp_field(arg, id, lbl, float) ->
let targ = transl_exp ~scopes Jkind.Sort.for_record arg in
Expand All @@ -595,7 +595,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
| Boxing (alloc_mode, _) -> alloc_mode
| Non_boxing _ -> assert false
in
let mode = transl_alloc_mode alloc_mode in
let mode = transl_alloc_mode_r alloc_mode in
Lprim (Pfloatfield (lbl.lbl_pos, sem, mode), [targ],
of_location ~scopes e.exp_loc)
| Record_ufloat ->
Expand All @@ -614,7 +614,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
| Float_boxed ->
(match float with
| Boxing (mode, _) ->
flat_read_float_boxed (transl_alloc_mode mode)
flat_read_float_boxed (transl_alloc_mode_r mode)
| Non_boxing _ ->
Misc.fatal_error
"expected typechecking to make [float] boxing mode\
Expand Down Expand Up @@ -668,7 +668,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
transl_exp ~scopes lbl_sort newval],
of_location ~scopes e.exp_loc)
| Texp_array (amut, element_sort, expr_list, alloc_mode) ->
let mode = transl_alloc_mode alloc_mode in
let mode = transl_alloc_mode_r alloc_mode in
let kind = array_kind e element_sort in
let ll =
transl_list ~scopes
Expand Down Expand Up @@ -1578,7 +1578,7 @@ and transl_function ~in_new_scope ~scopes e params body
~alloc_mode ~ret_mode:sreturn_mode ~ret_sort:sreturn_sort ~region:sregion
~zero_alloc =
let attrs = e.exp_attributes in
let mode = transl_alloc_mode alloc_mode in
let mode = transl_alloc_mode_r alloc_mode in
let assume_zero_alloc =
Builtin_attributes.assume_zero_alloc ~is_check_allowed:true zero_alloc
in
Expand Down Expand Up @@ -1981,7 +1981,7 @@ and transl_match ~scopes ~arg_sort ~return_sort e arg pat_expr_list partial =
match arg, exn_cases with
| {exp_desc = Texp_tuple (argl, alloc_mode)}, [] ->
assert (static_handlers = []);
let mode = transl_alloc_mode alloc_mode in
let mode = transl_alloc_mode_r alloc_mode in
let argl =
List.map (fun (_, a) -> (a, Jkind.Sort.for_tuple_element)) argl
in
Expand All @@ -2000,7 +2000,7 @@ and transl_match ~scopes ~arg_sort ~return_sort e arg pat_expr_list partial =
argl
|> List.split
in
let mode = transl_alloc_mode alloc_mode in
let mode = transl_alloc_mode_r alloc_mode in
static_catch (transl_list ~scopes argl) val_ids
(Matching.for_multiple_match ~scopes ~return_layout e.exp_loc
lvars mode val_cases partial)
Expand Down
3 changes: 0 additions & 3 deletions lambda/translmode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ let transl_alloc_mode_r mode =
(* we only take the locality axis *)
Alloc.proj (Comonadic Areality) mode |> transl_locality_mode_r

let transl_alloc_mode (mode : Typedtree.alloc_mode) =
transl_alloc_mode_r mode.mode

let transl_modify_mode locality =
match Locality.zap_to_floor locality with
| Global -> modify_heap
Expand Down
2 changes: 0 additions & 2 deletions lambda/translmode.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ val transl_alloc_mode_l : (allowed * 'r) Alloc.t -> Lambda.alloc_mode

val transl_alloc_mode_r : ('l * allowed) Alloc.t -> Lambda.alloc_mode

val transl_alloc_mode : Typedtree.alloc_mode -> Lambda.alloc_mode

val transl_modify_mode : (allowed * 'r) Locality.t -> Lambda.modify_mode
1 change: 0 additions & 1 deletion parsing/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ module Exp = struct
mk ?loc ?attrs (Pexp_letop {let_; ands; body})
let extension ?loc ?attrs a = mk ?loc ?attrs (Pexp_extension a)
let unreachable ?loc ?attrs () = mk ?loc ?attrs Pexp_unreachable
let stack ?loc ?attrs e = mk ?loc ?attrs (Pexp_stack e)

let case lhs ?guard rhs =
{
Expand Down
1 change: 0 additions & 1 deletion parsing/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ module Exp:
-> binding_op list -> expression -> expression
val extension: ?loc:loc -> ?attrs:attrs -> extension -> expression
val unreachable: ?loc:loc -> ?attrs:attrs -> unit -> expression
val stack : ?loc:loc -> ?attrs:attrs -> expression -> expression

val case: pattern -> ?guard:expression -> expression -> case
val binding_op: str -> pattern -> expression -> loc -> binding_op
Expand Down
1 change: 0 additions & 1 deletion parsing/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ module E = struct
sub.expr sub body
| Pexp_extension x -> sub.extension sub x
| Pexp_unreachable -> ()
| Pexp_stack e -> sub.expr sub e

let iter_binding_op sub {pbop_op; pbop_pat; pbop_exp; pbop_loc} =
iter_loc sub pbop_op;
Expand Down
1 change: 0 additions & 1 deletion parsing/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ module E = struct
(List.map (sub.binding_op sub) ands) (sub.expr sub body)
| Pexp_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pexp_unreachable -> unreachable ~loc ~attrs ()
| Pexp_stack e -> stack ~loc ~attrs (sub.expr sub e)

let map_binding_op sub {pbop_op; pbop_pat; pbop_exp; pbop_loc} =
let open Exp in
Expand Down
1 change: 0 additions & 1 deletion parsing/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ let rec add_expr bv exp =
| Ok { arg; _ } -> add_expr bv arg
end
| Pexp_extension e -> handle_extension e
| Pexp_stack e -> add_expr bv e
| Pexp_unreachable -> ()

and add_expr_jane_syntax bv : Jane_syntax.Expression.t -> _ = function
Expand Down
1 change: 0 additions & 1 deletion parsing/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ let keyword_table =
"private", PRIVATE;
"rec", REC;
"sig", SIG;
"stack_", STACK;
"struct", STRUCT;
"then", THEN;
"to", TO;
Expand Down
5 changes: 1 addition & 4 deletions parsing/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,6 @@ let unboxed_type sloc lident tys =
%token HASH_SUFFIX "# "
%token <string> HASHOP "##" (* just an example *)
%token SIG "sig"
%token STACK "stack_"
%token STAR "*"
%token <string * Location.t * string option>
STRING "\"hello\"" (* just an example *)
Expand Down Expand Up @@ -1134,7 +1133,7 @@ The precedences must be listed from low to high.
%nonassoc BACKQUOTE BANG BEGIN CHAR FALSE FLOAT HASH_FLOAT INT HASH_INT OBJECT
LBRACE LBRACELESS LBRACKET LBRACKETBAR LBRACKETCOLON LIDENT LPAREN
NEW PREFIXOP STRING TRUE UIDENT
LBRACKETPERCENT QUOTED_STRING_EXPR STACK
LBRACKETPERCENT QUOTED_STRING_EXPR


/* Entry points */
Expand Down Expand Up @@ -2812,8 +2811,6 @@ fun_expr:
%inline expr_:
| simple_expr nonempty_llist(labeled_simple_expr)
{ mkexp ~loc:$sloc (Pexp_apply($1, $2)) }
| STACK simple_expr
{ mkexp ~loc:$sloc (Pexp_stack $2) }
| labeled_tuple %prec below_COMMA
{ pexp_ltuple $sloc $1 }
| mkrhs(constr_longident) simple_expr %prec below_HASH
Expand Down
1 change: 0 additions & 1 deletion parsing/parsetree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ and expression_desc =
- [let* P0 = E00 and* P1 = E01 in E1] *)
| Pexp_extension of extension (** [[%id]] *)
| Pexp_unreachable (** [.] *)
| Pexp_stack of expression (** stack_ exp *)

and case =
{
Expand Down
3 changes: 0 additions & 3 deletions parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,6 @@ and expression ?(jane_syntax_parens = false) ctxt f x =
end (e,l)
end

| Pexp_stack e ->
(* Similar to the common case of [Pexp_apply] *)
pp f "@[<hov2>stack_@ %a@]" (expression2 reset_ctxt) e
| Pexp_construct (li, Some eo)
when not (is_simple_construct (view_expr x))-> (* Not efficient FIXME*)
(match view_expr x with
Expand Down
3 changes: 0 additions & 3 deletions parsing/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,6 @@ and expression i ppf x =
payload i ppf arg
| Pexp_unreachable ->
line i ppf "Pexp_unreachable"
| Pexp_stack e ->
line i ppf "Pexp_stack\n";
expression i ppf e

and value_description i ppf x =
line i ppf "value_description %a %a\n" fmt_string_loc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ module Example = struct
end"

let local_exp = parse expression "let x = foo (local_ x) in local_ y"
let stack_exp = parse expression
"let x = stack_ 42 in \
let y = stack_ (f x) in \
let z = foo (stack_ 42) in \
foo (stack_ (f x))"

let modal_kind_struct =
parse module_expr "struct \
Expand Down Expand Up @@ -183,7 +178,6 @@ end = struct
let modality_val = test "modality_val" module_type Example.modality_val

let local_exp = test "local_exp" expression Example.local_exp
let stack_exp = test "stack_exp" expression Example.stack_exp

let longident = test "longident" longident Example.longident
let expression = test "expression" expression Example.expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ modality_val: sig val t : string -> local_ string @@ foo bar end

local_exp: let x = foo (local_ x) in local_ y

stack_exp:
let x = stack_ 42 in
let y = stack_ (f x) in let z = foo (stack_ 42) in foo (stack_ (f x))

longident: No.Longidents.Require.extensions

expression: [x for x = 1 to 10]
Expand Down Expand Up @@ -122,10 +118,6 @@ modality_val: sig val t : string -> local_ string @@ foo bar end

local_exp: let x = foo (local_ x) in local_ y

stack_exp:
let x = stack_ 42 in
let y = stack_ (f x) in let z = foo (stack_ 42) in foo (stack_ (f x))

longident: No.Longidents.Require.extensions

expression: [x for x = 1 to 10]
Expand Down
Loading

0 comments on commit 0f30fe9

Please sign in to comment.