Skip to content

AST: Remove Pexp_new #7239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- AST cleanup: Prepare for ast async cleanup: Refactor code for "@res.async" payload handling and clean up handling of type and term parameters, so that now each `=>` in a function definition corresponds to a function. https://github.com/rescript-lang/rescript/pull/7223
- AST: always put type parameters first in function definitions. https://github.com/rescript-lang/rescript/pull/7233
- AST cleanup: Remove `@res.async` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7234
- AST cleanup: Remove `expression_desc.Pexp_new`, `expression_desc.Pexp_setinstvar`, `expression_desc.Pexp_override`, `expression_desc.Pexp_poly`, `exp_extra.Texp_poly`, `expression_desc.Texp_new`, `expression_desc.Texp_setinstvar`, `expression_desc.Texp_override` & `expression_desc.Texp_instvar` from AST as it is unused. https://github.com/rescript-lang/rescript/pull/7239
- AST cleanup: Remove `@res.partial` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7238 https://github.com/rescript-lang/rescript/pull/7240

# 12.0.0-alpha.7
Expand Down
12 changes: 0 additions & 12 deletions analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -982,18 +982,6 @@ module Compile = struct
| Texp_send _ ->
notImplemented "Texp_send";
assert false
| Texp_new _ ->
notImplemented "Texp_new";
assert false
| Texp_instvar _ ->
notImplemented "Texp_instvar";
assert false
| Texp_setinstvar _ ->
notImplemented "Texp_setinstvar";
assert false
| Texp_override _ ->
notImplemented "Texp_override";
assert false
| Texp_letmodule _ ->
notImplemented "Texp_letmodule";
assert false
Expand Down
4 changes: 0 additions & 4 deletions analysis/reanalyze/src/SideEffects.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ let rec exprNoSideEffects (expr : Typedtree.expression) =
e1 |> exprNoSideEffects && e2 |> exprNoSideEffects
&& e3 |> exprNoSideEffects
| Texp_send _ -> false
| Texp_new _ -> true
| Texp_instvar _ -> true
| Texp_setinstvar _ -> false
| Texp_override _ -> false
| Texp_letexception (_ec, e) -> e |> exprNoSideEffects
| Texp_pack _ -> false
| Texp_extension_constructor _ when true -> true
Expand Down
4 changes: 0 additions & 4 deletions analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,10 @@ let identifyPexp pexp =
| Pexp_constraint _ -> "Pexp_constraint"
| Pexp_coerce _ -> "Pexp_coerce"
| Pexp_send _ -> "Pexp_send"
| Pexp_new _ -> "Pexp_new"
| Pexp_setinstvar _ -> "Pexp_setinstvar"
| Pexp_override _ -> "Pexp_override"
| Pexp_letmodule _ -> "Pexp_letmodule"
| Pexp_letexception _ -> "Pexp_letexception"
| Pexp_assert _ -> "Pexp_assert"
| Pexp_lazy _ -> "Pexp_lazy"
| Pexp_poly _ -> "Pexp_poly"
| Pexp_newtype _ -> "Pexp_newtype"
| Pexp_pack _ -> "Pexp_pack"
| Pexp_extension _ -> "Pexp_extension"
Expand Down
2 changes: 0 additions & 2 deletions compiler/frontend/bs_ast_invariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ let emit_external_warnings : iterator =
(fun self ({pexp_loc = loc} as a) ->
match a.pexp_desc with
| Pexp_constant const -> check_constant loc const
| Pexp_new _ ->
Location.raise_errorf ~loc "OCaml style objects are not supported"
| Pexp_variant (s, None) when Ext_string.is_valid_hash_number s -> (
try ignore (Ext_string.hash_number_as_i32_exn s : int32)
with _ ->
Expand Down
8 changes: 0 additions & 8 deletions compiler/frontend/bs_ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,6 @@ module E = struct
| Pexp_constraint (e, t) ->
constraint_ ~loc ~attrs (sub.expr sub e) (sub.typ sub t)
| Pexp_send (e, s) -> send ~loc ~attrs (sub.expr sub e) (map_loc sub s)
| Pexp_new lid -> new_ ~loc ~attrs (map_loc sub lid)
| Pexp_setinstvar (s, e) ->
setinstvar ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_override sel ->
override ~loc ~attrs
(List.map (map_tuple (map_loc sub) (sub.expr sub)) sel)
| Pexp_letmodule (s, me, e) ->
letmodule ~loc ~attrs (map_loc sub s) (sub.module_expr sub me)
(sub.expr sub e)
Expand All @@ -370,8 +364,6 @@ module E = struct
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_poly (e, t) ->
poly ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t)
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down
18 changes: 0 additions & 18 deletions compiler/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
(* Its output should not be rewritten anymore *)
| Pexp_extension extension ->
Ast_exp_extension.handle_extension e self extension
| Pexp_setinstvar ({txt; loc}, expr) ->
if Stack.is_empty Js_config.self_stack then
Location.raise_errorf ~loc:e.pexp_loc
"This assignment can only happen in object context";
let name = Stack.top Js_config.self_stack in
if name = "" then
Location.raise_errorf ~loc:e.pexp_loc
"The current object does not assign a name";
let open Ast_helper in
self.expr self
(Exp.apply ~loc:e.pexp_loc
(Exp.ident ~loc {loc; txt = Lident "#="})
[
( Nolabel,
Exp.send ~loc (Exp.ident ~loc {loc; txt = Lident name}) {loc; txt}
);
(Nolabel, expr);
])
| Pexp_constant (Pconst_string (s, Some delim)) ->
Ast_utf8_string_interp.transform_exp e s delim
| Pexp_constant (Pconst_integer (s, Some 'l')) ->
Expand Down
4 changes: 0 additions & 4 deletions compiler/ml/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,10 @@ module Exp = struct
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_constraint (a, b))
let coerce ?loc ?attrs a c = mk ?loc ?attrs (Pexp_coerce (a, (), c))
let send ?loc ?attrs a b = mk ?loc ?attrs (Pexp_send (a, b))
let new_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_new a)
let setinstvar ?loc ?attrs a b = mk ?loc ?attrs (Pexp_setinstvar (a, b))
let override ?loc ?attrs a = mk ?loc ?attrs (Pexp_override a)
let letmodule ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_letmodule (a, b, c))
let letexception ?loc ?attrs a b = mk ?loc ?attrs (Pexp_letexception (a, b))
let assert_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_assert a)
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_lazy a)
let poly ?loc ?attrs a b = mk ?loc ?attrs (Pexp_poly (a, b))
let newtype ?loc ?attrs a b = mk ?loc ?attrs (Pexp_newtype (a, b))
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
Expand Down
6 changes: 0 additions & 6 deletions compiler/ml/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ module Exp : sig
val constraint_ :
?loc:loc -> ?attrs:attrs -> expression -> core_type -> expression
val send : ?loc:loc -> ?attrs:attrs -> expression -> str -> expression
val new_ : ?loc:loc -> ?attrs:attrs -> lid -> expression
val setinstvar : ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
val override :
?loc:loc -> ?attrs:attrs -> (str * expression) list -> expression
val letmodule :
?loc:loc -> ?attrs:attrs -> str -> module_expr -> expression -> expression
val letexception :
Expand All @@ -207,8 +203,6 @@ module Exp : sig
expression
val assert_ : ?loc:loc -> ?attrs:attrs -> expression -> expression
val lazy_ : ?loc:loc -> ?attrs:attrs -> expression -> expression
val poly :
?loc:loc -> ?attrs:attrs -> expression -> core_type option -> expression
val newtype : ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
val pack : ?loc:loc -> ?attrs:attrs -> module_expr -> expression
val open_ :
Expand Down
9 changes: 0 additions & 9 deletions compiler/ml/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,6 @@ module E = struct
sub.expr sub e;
sub.typ sub t
| Pexp_send (e, _s) -> sub.expr sub e
| Pexp_new lid -> iter_loc sub lid
| Pexp_setinstvar (s, e) ->
iter_loc sub s;
sub.expr sub e
| Pexp_override sel ->
List.iter (iter_tuple (iter_loc sub) (sub.expr sub)) sel
| Pexp_letmodule (s, me, e) ->
iter_loc sub s;
sub.module_expr sub me;
Expand All @@ -348,9 +342,6 @@ module E = struct
sub.expr sub e
| Pexp_assert e -> sub.expr sub e
| Pexp_lazy e -> sub.expr sub e
| Pexp_poly (e, t) ->
sub.expr sub e;
iter_opt (sub.typ sub) t
| Pexp_newtype (_s, e) -> sub.expr sub e
| Pexp_pack me -> sub.module_expr sub me
| Pexp_open (_ovf, lid, e) ->
Expand Down
8 changes: 0 additions & 8 deletions compiler/ml/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,6 @@ module E = struct
| Pexp_constraint (e, t) ->
constraint_ ~loc ~attrs (sub.expr sub e) (sub.typ sub t)
| Pexp_send (e, s) -> send ~loc ~attrs (sub.expr sub e) (map_loc sub s)
| Pexp_new lid -> new_ ~loc ~attrs (map_loc sub lid)
| Pexp_setinstvar (s, e) ->
setinstvar ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_override sel ->
override ~loc ~attrs
(List.map (map_tuple (map_loc sub) (sub.expr sub)) sel)
| Pexp_letmodule (s, me, e) ->
letmodule ~loc ~attrs (map_loc sub s) (sub.module_expr sub me)
(sub.expr sub e)
Expand All @@ -333,8 +327,6 @@ module E = struct
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_poly (e, t) ->
poly ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t)
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down
14 changes: 6 additions & 8 deletions compiler/ml/ast_mapper_from0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,11 @@ module E = struct
| Pexp_constraint (e, t) ->
constraint_ ~loc ~attrs (sub.expr sub e) (sub.typ sub t)
| Pexp_send (e, s) -> send ~loc ~attrs (sub.expr sub e) (map_loc sub s)
| Pexp_new lid -> new_ ~loc ~attrs (map_loc sub lid)
| Pexp_setinstvar (s, e) ->
setinstvar ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_override sel ->
override ~loc ~attrs
(List.map (map_tuple (map_loc sub) (sub.expr sub)) sel)
| Pexp_new _ -> failwith "Pexp_new is no longer present in ReScript"
| Pexp_setinstvar _ ->
failwith "Pexp_setinstvar is no longer present in ReScript"
| Pexp_override _ ->
failwith "Pexp_override is no longer present in ReScript"
| Pexp_letmodule (s, me, e) ->
letmodule ~loc ~attrs (map_loc sub s) (sub.module_expr sub me)
(sub.expr sub e)
Expand All @@ -402,8 +401,7 @@ module E = struct
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_poly (e, t) ->
poly ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t)
| Pexp_poly _ -> failwith "Pexp_poly is no longer present in ReScript"
| Pexp_object () -> assert false
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
Expand Down
8 changes: 0 additions & 8 deletions compiler/ml/ast_mapper_to0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,6 @@ module E = struct
| Pexp_constraint (e, t) ->
constraint_ ~loc ~attrs (sub.expr sub e) (sub.typ sub t)
| Pexp_send (e, s) -> send ~loc ~attrs (sub.expr sub e) (map_loc sub s)
| Pexp_new lid -> new_ ~loc ~attrs (map_loc sub lid)
| Pexp_setinstvar (s, e) ->
setinstvar ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_override sel ->
override ~loc ~attrs
(List.map (map_tuple (map_loc sub) (sub.expr sub)) sel)
| Pexp_letmodule (s, me, e) ->
letmodule ~loc ~attrs (map_loc sub s) (sub.module_expr sub me)
(sub.expr sub e)
Expand All @@ -384,8 +378,6 @@ module E = struct
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_poly (e, t) ->
poly ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t)
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down
6 changes: 0 additions & 6 deletions compiler/ml/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,18 +271,12 @@ let rec add_expr bv exp =
add_expr bv e1;
add_type bv ty2
| Pexp_send (e, _m) -> add_expr bv e
| Pexp_new li -> add bv li
| Pexp_setinstvar (_v, e) -> add_expr bv e
| Pexp_override sel -> List.iter (fun (_s, e) -> add_expr bv e) sel
| Pexp_letmodule (id, m, e) ->
let b = add_module_binding bv m in
add_expr (StringMap.add id.txt b bv) e
| Pexp_letexception (_, e) -> add_expr bv e
| Pexp_assert e -> add_expr bv e
| Pexp_lazy e -> add_expr bv e
| Pexp_poly (e, t) ->
add_expr bv e;
add_opt add_type bv t
| Pexp_newtype (_, e) -> add_expr bv e
| Pexp_pack m -> add_module bv m
| Pexp_open (_ovf, m, e) ->
Expand Down
9 changes: 0 additions & 9 deletions compiler/ml/parsetree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ and expression_desc =
(* (E :> T) (None, T)
*)
| Pexp_send of expression * label loc (* E # m *)
| Pexp_new of Longident.t loc (* new M.c *)
| Pexp_setinstvar of label loc * expression (* x <- 2 *)
| Pexp_override of (label loc * expression) list
(* {< x1 = E1; ...; Xn = En >} *)
| Pexp_letmodule of string loc * module_expr * expression
(* let module M = ME in E *)
| Pexp_letexception of extension_constructor * expression
Expand All @@ -308,11 +304,6 @@ and expression_desc =
Note: "assert false" is treated in a special way by the
type-checker. *)
| Pexp_lazy of expression (* lazy E *)
| Pexp_poly of expression * core_type option
(* Used for method bodies.

Can only be used as the expression under Cfk_concrete
for methods (not values). *)
| Pexp_newtype of string loc * expression (* fun (type t) -> E *)
| Pexp_pack of module_expr
(* (module ME)
Expand Down
15 changes: 0 additions & 15 deletions compiler/ml/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -706,15 +706,6 @@ and expression ctxt f x =
in
let lst = sequence_helper [] x in
pp f "@[<hv>%a@]" (list (expression (under_semi ctxt)) ~sep:";@;") lst
| Pexp_new li -> pp f "@[<hov2>new@ %a@]" longident_loc li
| Pexp_setinstvar (s, e) ->
pp f "@[<hov2>%s@ <-@ %a@]" s.txt (expression ctxt) e
| Pexp_override l ->
(* FIXME *)
let string_x_expression f (s, e) =
pp f "@[<hov2>%s@ =@ %a@]" s.txt (expression ctxt) e
in
pp f "@[<hov2>{<%a>}@]" (list string_x_expression ~sep:";") l
| Pexp_letmodule (s, me, e) ->
pp f "@[<hov2>let@ module@ %s@ =@ %a@ in@ %a@]" s.txt
(module_expr reset_ctxt) me (expression ctxt) e
Expand All @@ -724,12 +715,6 @@ and expression ctxt f x =
cd (expression ctxt) e
| Pexp_assert e -> pp f "@[<hov2>assert@ %a@]" (simple_expr ctxt) e
| Pexp_lazy e -> pp f "@[<hov2>lazy@ %a@]" (simple_expr ctxt) e
(* Pexp_poly: impossible but we should print it anyway, rather than
assert false *)
| Pexp_poly (e, None) -> pp f "@[<hov2>!poly!@ %a@]" (simple_expr ctxt) e
| Pexp_poly (e, Some ct) ->
pp f "@[<hov2>(!poly!@ %a@ : %a)@]" (simple_expr ctxt) e (core_type ctxt)
ct
| Pexp_open (ovf, lid, e) ->
pp f "@[<2>let open%s %a in@;%a@]" (override ovf) longident_loc lid
(expression ctxt) e
Expand Down
15 changes: 0 additions & 15 deletions compiler/ml/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,6 @@ and expression i ppf x =
| Pexp_send (e, s) ->
line i ppf "Pexp_send \"%s\"\n" s.txt;
expression i ppf e
| Pexp_new li -> line i ppf "Pexp_new %a\n" fmt_longident_loc li
| Pexp_setinstvar (s, e) ->
line i ppf "Pexp_setinstvar %a\n" fmt_string_loc s;
expression i ppf e
| Pexp_override l ->
line i ppf "Pexp_override\n";
list i string_x_expression ppf l
| Pexp_letmodule (s, me, e) ->
line i ppf "Pexp_letmodule %a\n" fmt_string_loc s;
module_expr i ppf me;
Expand All @@ -339,10 +332,6 @@ and expression i ppf x =
| Pexp_lazy e ->
line i ppf "Pexp_lazy\n";
expression i ppf e
| Pexp_poly (e, cto) ->
line i ppf "Pexp_poly\n";
expression i ppf e;
option i core_type ppf cto
| Pexp_newtype (s, e) ->
line i ppf "Pexp_newtype \"%s\"\n" s.txt;
expression i ppf e
Expand Down Expand Up @@ -666,10 +655,6 @@ and value_binding i ppf x =
pattern (i + 1) ppf x.pvb_pat;
expression (i + 1) ppf x.pvb_expr

and string_x_expression i ppf (s, e) =
line i ppf "<override> %a\n" fmt_string_loc s;
expression (i + 1) ppf e

and longident_x_expression i ppf (li, e, opt) =
line i ppf "%a%s\n" fmt_longident_loc li (if opt then "?" else "");
expression (i + 1) ppf e
Expand Down
6 changes: 0 additions & 6 deletions compiler/ml/printtyped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ and expression_extra i ppf x attrs =
| Texp_open (ovf, m, _, _) ->
line i ppf "Texp_open %a \"%a\"\n" fmt_override_flag ovf fmt_path m;
attributes i ppf attrs
| Texp_poly cto ->
line i ppf "Texp_poly\n";
attributes i ppf attrs;
option i core_type ppf cto
| Texp_newtype s ->
line i ppf "Texp_newtype \"%s\"\n" s;
attributes i ppf attrs
Expand All @@ -279,7 +275,6 @@ and expression i ppf x =
in
match x.exp_desc with
| Texp_ident (li, _, _) -> line i ppf "Texp_ident %a\n" fmt_path li
| Texp_instvar () -> assert false
| Texp_constant c -> line i ppf "Texp_constant %a\n" fmt_constant c
| Texp_let (rf, l, e) ->
line i ppf "Texp_let %a\n" fmt_rec_flag rf;
Expand Down Expand Up @@ -361,7 +356,6 @@ and expression i ppf x =
line i ppf "Texp_send \"%s\"\n" s;
expression i ppf e;
option i expression ppf eo
| Texp_new _ | Texp_setinstvar _ | Texp_override _ -> ()
| Texp_letmodule (s, _, me, e) ->
line i ppf "Texp_letmodule \"%a\"\n" fmt_ident s;
module_expr i ppf me;
Expand Down
Loading
Loading