Skip to content

Commit 00a47ac

Browse files
cristianocclaude
andcommitted
Remove dead code enabled by structural arity
- The Too_many_arguments error cannot be raised anymore: the expected type is committed to an arrow of the literal's shape before destructuring, so every legacy path now surfaces as a regular type clash or Uncurried_arity_mismatch (which is what the fixture credited to it in ERROR_VARIANTS.md was already producing). Remove the variant, its printer, and the ?in_function threading through type_expect/type_cases that existed only to decorate it. - Remove the function$-vs-arrow unification bridge in ctype (nothing produces a function$ type expression anymore), the structural arity counter Ctype.arity (no callers), the parsetree arity probes get_uncurry_arity/get_curry_arity (is_arity_one reads the params list directly), and Ast_async's redundant newtype double-dig. - Deduplicate the arrow-flattening step shared by the analysis extract_function_type helpers. - Delete Ast_compatible outright. Every member was a thin veneer over an existing Ast_helper constructor (rec_type_str/rec_type_sig had byte-identical signatures to Str.type_/Sig.type_), hand-rolling the records the canonical constructors build; the OCaml-version compatibility it existed for is long gone, and its fun_ silently hard-coded arity 1. Call sites use Ast_helper directly, with two let-bound app1/app2 shorthands kept local to ast_derive_js_mapper. Generated code is unchanged. The Pjs_fn_make no-op elision explored alongside these cleanups is deliberately left out pending a dedicated analysis of that primitive. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent d980cec commit 00a47ac

21 files changed

Lines changed: 87 additions & 355 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
- Sync the platform npm package's compiler binaries (`packages/@rescript/<platform>/bin`) via dune promotion on every `dune build`, instead of Makefile/CI copy steps that only ran when make did: a plain `dune build` can no longer leave `cli/*.js` and the test harnesses running a stale compiler. https://github.com/rescript-lang/rescript/pull/8560
5050
- Remove unused compiler IR definitions, modules, helpers, error variants, and Typedtree fields. https://github.com/rescript-lang/rescript/pull/8551 https://github.com/rescript-lang/rescript/pull/8555
51+
- Cleanups enabled by structural arity: remove the unreachable `Too_many_arguments` error and the `?in_function` threading through the type checker that existed only to decorate it; remove the dead `function$`-vs-arrow unification bridge, `Ctype.arity`, and the unused parsetree arity helpers; deduplicate the analysis arrow-flattening helpers. https://github.com/rescript-lang/rescript/pull/8569
52+
5153
- Make the typed layers n-ary as well: `Types.Tarrow` carries a parameter list, `Texp_function` carries typed parameters (label, ident, pattern, per-parameter exhaustiveness) and a body, and `Ttyp_arrow`/`Otyp_arrow` follow. The `arity` annotation and its `int option` phantom state are gone from the compiler entirely; `push_defaults` in translcore and the hand-rolled gather-until-arity walks in gentype, reanalyze, and the outcome printer are deleted. The cmi and cmt magic numbers are bumped (`Caml1999I023`/`Caml1999T023`). Generated JavaScript is byte-identical across the test suite (optional-parameter internals are named `*opt_<label>*` instead of `*opt*`, visible only in the rare unprettified case); reanalyze no longer emits spurious empty optional-argument references, and genType recovers real parameter names after defaulted parameters. https://github.com/rescript-lang/rescript/pull/8568
5254
- Make functions and arrow types n-ary in the parsetree: `Pexp_fun` carries a parameter list and `Ptyp_arrow` a parameter list, replacing the curried one-parameter-per-node chains with an `arity` annotation on the head. Arity is now structural (`List.length params`) and `ast_uncurried.ml` is deleted. The typed layers, cmt format, printed output, and the external-PPX wire format are unchanged. Generated JavaScript is unchanged with one deliberate exception: `@this this => async arg => ...` now means what it says (a method returning an async function) instead of absorbing the nested parameter into the method; write `@this async (this, arg) => ...` for the old meaning. https://github.com/rescript-lang/rescript/pull/8566
5355
- Give marshaled current-parsetree streams (`-as-pp`, `res_parser -print binary`) their own magic numbers, distinct from the frozen Parsetree0 wire format used for external PPXes. https://github.com/rescript-lang/rescript/pull/8561

analysis/src/type_utils.ml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,17 @@ let rec extract_object_type ~state ~env ~package (t : Types.type_expr) =
279279
| _ -> None)
280280
| _ -> None
281281

282+
let flatten_arrow_params (params : Types.arg list) acc =
283+
List.rev_append
284+
(List.map (fun ({lbl; typ} : Types.arg) -> (lbl, typ)) params)
285+
acc
286+
282287
let extract_function_type ~state ~env ~package ?(dig_into = true) typ =
283288
let rec loop ~env acc (t : Types.type_expr) =
284289
match t.desc with
285290
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> loop ~env acc t1
286291
| Tarrow (params, t_ret) ->
287-
loop ~env
288-
(List.rev_append
289-
(List.map (fun ({lbl; typ} : Types.arg) -> (lbl, typ)) params)
290-
acc)
291-
t_ret
292+
loop ~env (flatten_arrow_params params acc) t_ret
292293
| Tconstr (path, type_args, _) when dig_into -> (
293294
match References.dig_constructor ~state ~env ~package path with
294295
| Some (env, {item = {decl = {type_manifest = Some t1; type_params}}}) ->
@@ -304,11 +305,7 @@ let extract_function_type_with_env ~state ~env ~package typ =
304305
match t.desc with
305306
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> loop ~env acc t1
306307
| Tarrow (params, t_ret) ->
307-
loop ~env
308-
(List.rev_append
309-
(List.map (fun ({lbl; typ} : Types.arg) -> (lbl, typ)) params)
310-
acc)
311-
t_ret
308+
loop ~env (flatten_arrow_params params acc) t_ret
312309
| Tconstr (path, type_args, _) -> (
313310
match References.dig_constructor ~state ~env ~package path with
314311
| Some (_env, {item = {decl = {type_manifest = Some t1; type_params}}}) ->
@@ -345,11 +342,7 @@ let extract_function_type2 ?type_arg_context ~state ~env ~package typ =
345342
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) ->
346343
loop ?type_arg_context ~env acc t1
347344
| Tarrow (params, t_ret) ->
348-
loop ?type_arg_context ~env
349-
(List.rev_append
350-
(List.map (fun ({lbl; typ} : Types.arg) -> (lbl, typ)) params)
351-
acc)
352-
t_ret
345+
loop ?type_arg_context ~env (flatten_arrow_params params acc) t_ret
353346
| Tconstr (path, type_args, _) -> (
354347
match References.dig_constructor ~state ~env ~package path with
355348
| Some (env, {item = {decl = {type_manifest = Some t1; type_params}}}) ->

compiler/frontend/ast_comb.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424

2525
open Ast_helper
2626

27-
(* let fun_no_label ?loc ?attrs pat body =
28-
Ast_compatible.fun_ ?loc ?attrs pat body *)
29-
30-
(* let discard_exp_as_unit loc e =
31-
Ast_compatible.apply_simple ~loc
32-
(Exp.ident ~loc {txt = Ast_literal.Lid.ignore_id; loc})
33-
[Exp.constraint_ ~loc e
34-
(Ast_literal.type_unit ~loc ())] *)
35-
3627
let regexp_id = Ast_literal.Lid.regexp_id
3728

3829
let to_regexp_type loc = Typ.constr ~loc {txt = regexp_id; loc} []

compiler/frontend/ast_compatible.ml

Lines changed: 0 additions & 126 deletions
This file was deleted.

compiler/frontend/ast_compatible.mli

Lines changed: 0 additions & 97 deletions
This file was deleted.

compiler/frontend/ast_core_type.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ let make_obj ~loc xs = Typ.object_ ~loc xs Closed
110110
{[ 'a -> ('a. 'a -> 'b) ]}
111111
112112
*)
113-
let get_curry_arity (ty : t) =
113+
let is_arity_one (ty : t) =
114114
match ty.ptyp_desc with
115-
| Ptyp_arrow {params} -> List.length params
116-
| _ -> 0
117-
118-
let is_arity_one ty = get_curry_arity ty = 1
115+
| Ptyp_arrow {params = [_]} -> true
116+
| _ -> false
119117

120118
let list_of_arrow (ty : t) : t * Parsetree.arg list =
121119
match ty.ptyp_desc with

compiler/frontend/ast_core_type.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ val make_obj : loc:Location.t -> Parsetree.object_field list -> t
4242
val is_user_option : t -> bool
4343

4444
val list_of_arrow : t -> t * Parsetree.arg list
45-
(** fails when Ptyp_poly *)
45+
(** [list_of_arrow ty] returns [(return_type, params)] of an arrow type,
46+
or [(ty, [])] when [ty] is not an arrow. *)
4647

4748
val is_arity_one : t -> bool

compiler/frontend/ast_core_type_class_type.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,28 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
9595
| Nothing, attrs -> (attrs, ty) (* #1678 *)
9696
| Meth_callback attr, attrs -> (attrs, attr +> ty)
9797
in
98-
Ast_compatible.object_field name attrs (self.typ self core_type)
98+
Parsetree.Otag (name, attrs, self.typ self core_type)
9999
in
100100
let set ty name attrs =
101101
let attrs, core_type =
102102
match Ast_attributes.process_attributes_rev attrs with
103103
| Nothing, attrs -> (attrs, ty)
104104
| Meth_callback attr, attrs -> (attrs, attr +> ty)
105105
in
106-
Ast_compatible.object_field name attrs
107-
(Ast_helper.Typ.arrow ~loc
108-
[{attrs = []; lbl = Nolabel; typ = self.typ self core_type}]
109-
(Ast_literal.type_unit ~loc ()))
106+
Parsetree.Otag
107+
( name,
108+
attrs,
109+
Ast_helper.Typ.arrow ~loc
110+
[{attrs = []; lbl = Nolabel; typ = self.typ self core_type}]
111+
(Ast_literal.type_unit ~loc ()) )
110112
in
111113
let not_getter_setter ty =
112114
let attrs, core_type =
113115
match Ast_attributes.process_attributes_rev ptyp_attrs with
114116
| Nothing, attrs -> (attrs, ty)
115117
| Meth_callback attr, attrs -> (attrs, attr +> ty)
116118
in
117-
Ast_compatible.object_field label attrs (self.typ self core_type)
119+
Parsetree.Otag (label, attrs, self.typ self core_type)
118120
in
119121
process_getter_setter ~not_getter_setter ~get ~set loc label
120122
ptyp_attrs core_type acc)

compiler/frontend/ast_derive_abstract.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ let handle_tdcls_in_str ~light rf tdcls =
209209
Ext_list.map_append value_descriptions sts (fun x ->
210210
Str.primitive x) ))
211211
in
212-
Ast_compatible.rec_type_str rf tdcls :: code
212+
Str.type_ rf tdcls :: code
213213
(* still need perform transformation for non-abstract type*)
214214

215215
let handle_tdcls_in_sig ~light rf tdcls =
@@ -220,4 +220,4 @@ let handle_tdcls_in_sig ~light rf tdcls =
220220
( ntdcl :: tdcls,
221221
Ext_list.map_append value_descriptions sts (fun x -> Sig.value x) ))
222222
in
223-
Ast_compatible.rec_type_sig rf tdcls :: code
223+
Sig.type_ rf tdcls :: code

0 commit comments

Comments
 (0)