Skip to content

Commit e5d34a4

Browse files
committed
Store parsed string delimiters in Lambda constants
Give Lambda Const_string the same structured payload used by Lam, and move processed-delimiter decoding into External_arg_spec so Lambda producers can store the final delimiter directly. Remove the inline-constant delimiter round-trip, cover every processed delimiter encoding, and consolidate the branch changelog into review-facing entries. Signed-off-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent b02837e commit e5d34a4

13 files changed

Lines changed: 53 additions & 56 deletions

CHANGELOG.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,8 @@
7070
- Represent optional parameters with defaults structurally, removing downstream name-based detection and producing more consistent JavaScript parameter names. https://github.com/rescript-lang/rescript/pull/8580
7171
- 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
7272
- 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
73-
- Remove the unused OCaml pipe primitives `%revapply`/`%apply` and the `Ploc` Lambda constructor. `__LOC__` and friends still compile to location constants in `translcore`.
74-
- Lower exception packing in `translcore` instead of convert, drop unused `raise_kind` / reraise tracking, and emit `RE_EXN_ID` string equality from matching instead of `Pextension_slot_eq`.
75-
- Remove the `Pwrap_exn` / `%wrap_exn` primitive. Exception packing, `Promise.catch`, and `JsExn.anyToExnInternal` call `Primitive_exceptions.internalToException` as a normal module function.
76-
- Split `let rec` groups into actual recursive clusters when Lambda is produced (`Lambda_scc.bind_rec`). Convert `Lletrec` is identity; `Lam_scc` is removed. JS compile only sorts functions before values for dummy/`updateDummy` init.
77-
- Remove the dense int-switch-to-add peephole (`happens_to_be_diff`) from Lambda-to-Lam conversion. Convert `Lswitch` is identity.
78-
- Remove the switcher-offset peephole from Lambda-to-Lam conversion. Convert `Llet` is identity.
79-
- Convert `Lstaticcatch` / `Lstaticraise` are identity. Drop exit aliasing (`exit_map`); `Lam_pass_exits` already inlines a catch whose handler is a tiny `Lstaticraise`.
80-
- Drop the unused `exports` argument from Lambda-to-Lam conversion.
81-
- Represent `%identity` / `%ignore` / unary `+` as `Peliminated` on both Lambda and Lam. `Lambda.mk_prim` expands them so they never appear as `Lprim` nodes; Lam matches `assert false`.
82-
- Use a single `int32` integer constant on Lambda and Lam (`Const_int of int32`). Assert-false is a dedicated constant (`Const_assertfalse`), not a tagged `0`.
83-
- Drop dead typedtree constants `Const_int32` and `Const_int64`. Integer literals are `Const_int` (native `int`) or `Const_bigint`.
84-
- Put char, string, float, and bigint constants on Lambda and drop `Const_base`.
85-
- Drop Lambda `Const_immstring`; location primitives use `Const_string`, and matching can share equivalent string-valued actions.
73+
- Make Lambda-to-Lam conversion structural for lets, switches, static exits, recursive binding groups, exception packing, and eliminated identity operations. Semantic rewrites now happen during Lambda production or in named Lam passes; obsolete conversion state and `Lam_scc` are removed.
74+
- Remove obsolete Lambda and Lam primitives and align their scalar constant representations. Lambda and Lam now use `int32` integers and matching char, string, float, and bigint cases; Lambda strings carry their parsed output delimiter, assert-false is distinct from integer zero, and dead typedtree integer variants are removed.
8675
- Make locally abstract value constraints (`let f: type a. t = value`) structural in the parsetree, remove the obsolete `Pexp_newtype` and `Texp_newtype` wrapper metadata, and keep the old encoding confined to the frozen external-PPX bridge. The CMT magic number is bumped to `Caml1999T024`. https://github.com/rescript-lang/rescript/pull/8575
8776
- Eliminate the `Pjs_fn_make`/`Pjs_fn_make_unit` arity-adjustment primitives and the `unsafe_adjust_to_arity` machinery: with structural arity, functions are constructed at their final arity, so the enforcement layer (and the active-pattern currying split it compensated for) is deleted. Generated code improves: no adapter closures for patterns on mutable fields, better constant propagation and name preservation, and recursive modules whose members are plain functions compile statically without the runtime bootstrap. https://github.com/rescript-lang/rescript/pull/8570
8877
- 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

compiler/core/lam_constant_convert.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
2626
match const with
2727
| Const_int i -> Const_int i
2828
| Const_char i -> Const_char i
29-
| Const_string (s, opt) ->
30-
let delim = Ast_utf8_string_interp.parse_processed_delim opt in
31-
Const_string {s; delim}
29+
| Const_string {s; delim} -> Const_string {s; delim}
3230
| Const_float i -> Const_float i
3331
| Const_bigint (sign, i) -> Const_bigint (sign, i)
3432
| Const_pointer (Pt_constructor {name = "()"}) ->

compiler/frontend/ast_utf8_string_interp.ml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,6 @@ let transform_test s =
271271
List.rev cxt.segments
272272

273273
module Delim = struct
274-
let parse_processed = function
275-
| None -> Some External_arg_spec.DNone
276-
| Some "json" -> Some DNoQuotes
277-
| Some "*j" -> Some DStarJ
278-
| Some "bq" -> Some DBackQuotes
279-
| _ -> None
280-
281274
type interpolation =
282275
| BackQuotes (* string interpolation *)
283276
| Js (* simple double quoted string *)
@@ -333,4 +326,4 @@ let transform_pat (p : Parsetree.pattern) s delim : Parsetree.pattern =
333326
}
334327
| Unrecognized -> p
335328

336-
let parse_processed_delim = Delim.parse_processed
329+
let parse_processed_delim = External_arg_spec.parse_processed_delim

compiler/ml/external_arg_spec.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626

2727
type delim = DNone | DStarJ | DNoQuotes | DBackQuotes
2828

29+
let parse_processed_delim = function
30+
| None -> Some DNone
31+
| Some "json" -> Some DNoQuotes
32+
| Some "*j" -> Some DStarJ
33+
| Some "bq" -> Some DBackQuotes
34+
| _ -> None
35+
2936
type cst = Arg_int_lit of int | Arg_string_lit of string * delim
3037

3138
type label_noname = Arg_label | Arg_empty | Arg_optional

compiler/ml/external_arg_spec.mli

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

2525
type delim = DNone | DStarJ | DNoQuotes | DBackQuotes
2626

27+
val parse_processed_delim : string option -> delim option
28+
2729
type cst = private Arg_int_lit of int | Arg_string_lit of string * delim
2830

2931
type attr =

compiler/ml/lambda.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ type pointer_info =
336336
type structured_constant =
337337
| Const_int of int32
338338
| Const_char of int
339-
| Const_string of string * string option
339+
| Const_string of {s: string; delim: External_arg_spec.delim option}
340340
| Const_float of string
341341
| Const_bigint of bool * string
342342
| Const_pointer of pointer_info
@@ -423,11 +423,14 @@ and lambda_switch = lambda switch
423423
*)
424424
let const_int (i : int) = Const_int (Int32.of_int i)
425425

426+
let const_string s delim =
427+
Const_string {s; delim = External_arg_spec.parse_processed_delim delim}
428+
426429
let const_of_typed (c : Asttypes.constant) : structured_constant =
427430
match c with
428431
| Asttypes.Const_int i -> Const_int (Int32.of_int i)
429432
| Asttypes.Const_char i -> Const_char i
430-
| Asttypes.Const_string (s, d) -> Const_string (s, d)
433+
| Asttypes.Const_string (s, d) -> const_string s d
431434
| Asttypes.Const_float f -> Const_float f
432435
| Asttypes.Const_bigint (sign, i) -> Const_bigint (sign, i)
433436

compiler/ml/lambda.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ and value_kind = Pgenval
292292
type structured_constant =
293293
| Const_int of int32
294294
| Const_char of int
295-
| Const_string of string * string option
295+
| Const_string of {s: string; delim: External_arg_spec.delim option}
296296
| Const_float of string
297297
| Const_bigint of bool * string
298298
| Const_pointer of pointer_info
@@ -403,6 +403,7 @@ and lambda_switch = lambda switch
403403
val make_key : lambda -> lambda option
404404

405405
val const_int : int -> structured_constant
406+
val const_string : string -> string option -> structured_constant
406407
val const_of_typed : constant -> structured_constant
407408
val const_unit : structured_constant
408409
val lambda_assert_false : lambda

compiler/ml/matching.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,9 +2702,8 @@ let partial_function loc () =
27022702
Lconst
27032703
(Const_block
27042704
( Blk_tuple,
2705-
[
2706-
Const_string (fname, None); const_int line; const_int char;
2707-
] ));
2705+
[const_string fname None; const_int line; const_int char]
2706+
));
27082707
],
27092708
loc );
27102709
],

compiler/ml/printlambda.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ open Lambda
2020
let rec struct_const ppf = function
2121
| Const_int n -> fprintf ppf "%ld" n
2222
| Const_char i -> fprintf ppf "%s" (Pprintast.string_of_int_as_char i)
23-
| Const_string (s, _) -> fprintf ppf "%S" s
23+
| Const_string {s} -> fprintf ppf "%S" s
2424
| Const_float f -> fprintf ppf "%s" f
2525
| Const_bigint (sign, n) -> fprintf ppf "%sn" (Bigint_utils.to_string sign n)
2626
| Const_pointer (Pt_constructor {name}) -> fprintf ppf "`%s" name

compiler/ml/transl_recmodule.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ let undefined_location loc =
1515
Lconst
1616
(Const_block
1717
( Lambda.Blk_tuple,
18-
[Const_string (fname, None); const_int line; const_int char] ))
18+
[const_string fname None; const_int line; const_int char] ))
1919

2020
let init_shape modl =
2121
let add_name x id =
22-
Const_block (Blk_tuple, [x; Const_string (Ident.name id, None)])
22+
Const_block (Blk_tuple, [x; const_string (Ident.name id) None])
2323
in
2424
let module_tag_info : Lambda.tag_info =
2525
Blk_constructor

0 commit comments

Comments
 (0)