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 5 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` from the untyped typed AST as it is unused. https://github.com/rescript-lang/rescript/pull/7239

# 12.0.0-alpha.7

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 @@ -354,12 +354,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 @@ -369,8 +363,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 @@ -171,14 +171,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 @@ -192,10 +192,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 @@ -206,8 +202,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 @@ -317,12 +317,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 @@ -332,8 +326,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 @@ -376,12 +376,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 @@ -391,8 +390,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 @@ -365,12 +365,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 @@ -380,8 +374,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 @@ -291,10 +291,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 @@ -304,11 +300,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 @@ -702,15 +702,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 @@ -720,12 +711,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 @@ -317,13 +317,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 @@ -338,10 +331,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 @@ -665,10 +654,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
42 changes: 1 addition & 41 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ let iter_expression f e =
f e;
match e.pexp_desc with
| Pexp_extension _ (* we don't iterate under extension point *)
| Pexp_ident _ | Pexp_new _ | Pexp_constant _ ->
| Pexp_ident _ | Pexp_constant _ ->
()
| Pexp_fun {default = eo; rhs = e} ->
may expr eo;
Expand All @@ -155,10 +155,8 @@ let iter_expression f e =
List.iter (fun (_, e, _) -> expr e) iel
| Pexp_open (_, _, e)
| Pexp_newtype (_, e)
| Pexp_poly (e, _)
| Pexp_lazy e
| Pexp_assert e
| Pexp_setinstvar (_, e)
| Pexp_send (e, _)
| Pexp_constraint (e, _)
| Pexp_coerce (e, _, _)
Expand All @@ -177,7 +175,6 @@ let iter_expression f e =
expr e1;
expr e2;
expr e3
| Pexp_override sel -> List.iter (fun (_, e) -> expr e) sel
| Pexp_letmodule (_, me, e) ->
expr e;
module_expr me
Expand Down Expand Up @@ -3034,7 +3031,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
(Error
(e.pexp_loc, env, Undefined_method (obj.exp_type, met, valid_methods)))
)
| Pexp_new _ | Pexp_setinstvar _ | Pexp_override _ -> assert false
| Pexp_letmodule (name, smodl, sbody) ->
let ty = newvar () in
(* remember original level *)
Expand Down Expand Up @@ -3110,42 +3106,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
exp_attributes = sexp.pexp_attributes;
exp_env = env;
}
| Pexp_poly (sbody, sty) ->
let ty, cty =
match sty with
| None -> (repr ty_expected, None)
| Some sty ->
let sty = Ast_helper.Typ.force_poly sty in
let cty = Typetexp.transl_simple_type env false sty in
(repr cty.ctyp_type, Some cty)
in
if sty <> None then
unify_exp_types loc env (instance env ty) (instance env ty_expected);
let exp =
match (expand_head env ty).desc with
| Tpoly (ty', []) ->
let exp = type_expect env sbody ty' in
{exp with exp_type = instance env ty}
| Tpoly (ty', tl) ->
(* One more level to generalize locally *)
begin_def ();
let vars, ty'' = instance_poly true tl ty' in
let exp = type_expect env sbody ty'' in
end_def ();
check_univars env false "method" exp ty_expected vars;
{exp with exp_type = instance env ty}
| Tvar _ ->
let exp = type_exp env sbody in
let exp = {exp with exp_type = newty (Tpoly (exp.exp_type, []))} in
unify_exp env exp ty;
exp
| _ -> assert false
in
re
{
exp with
exp_extra = (Texp_poly cty, loc, sexp.pexp_attributes) :: exp.exp_extra;
}
| Pexp_newtype ({txt = name}, sbody) ->
let ty = newvar () in
(* remember original level *)
Expand Down
Loading
Loading