Skip to content

Commit 1cc1da7

Browse files
cknittclaude
andauthored
Remove @deriving(abstract) and @deriving(jsConverter) (#8729)
* Remove @deriving(abstract) and @deriving(jsConverter) Both derivers predate records compiling to plain JavaScript objects. Records with optional, mutable and @as-renamed fields now cover what @deriving(abstract) was used for, and records and polymorphic variants already have the runtime representation @deriving(jsConverter) converted to. Using either deriver now reports a dedicated error pointing to the replacement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Christoph Knittel <ck@cca.io> * Add PR link to changelog entry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Christoph Knittel <ck@cca.io> * Remove Primitive_util runtime module Its only function, raiseWhenNotFound, was called by code that @deriving(jsConverter) generated for polymorphic variants with newType. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Christoph Knittel <ck@cca.io> --------- Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 30ce369 commit 1cc1da7

44 files changed

Lines changed: 97 additions & 6802 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

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

1515
#### :boom: Breaking Change
1616

17+
- Remove `@deriving(abstract)` and `@deriving(jsConverter)`. Use record types (with optional fields, mutable fields and `@as` renaming) and polymorphic variants directly instead. https://github.com/rescript-lang/rescript/pull/8729
18+
1719
#### :eyeglasses: Spec Compliance
1820

1921
#### :rocket: New Feature

‎analysis/src/completion_decorators.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ It is also possible to map a ReScript record to a JavaScript array by passing in
2525
( "deriving",
2626
Some "deriving($0)",
2727
[
28-
{|When the `@deriving` decorator is applied to a record type, it expands the type into a factory function plus a set of getter/setter functions for its fields.
28+
{|When the `@deriving(accessors)` decorator is applied to a record type, it generates a getter function for each field. Applied to a variant type, it generates a function for each constructor.
2929

3030
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#deriving-decorator).|};
3131
] );

‎compiler/ext/primitive_modules.ml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ let hash = "Primitive_hash"
5050

5151
let exceptions = "Primitive_exceptions"
5252

53-
let util = "Primitive_util"
54-
5553
let js_extern = "Primitive_js_extern"
5654

5755
let pervasives = "Pervasives"

‎compiler/frontend/ast_attributes.ml‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,6 @@ let as_string (attrs : t) : string option =
155155
| None -> Bs_syntaxerr.err loc Expect_string_literal
156156
| Some v -> v)
157157

158-
let has_bs_optional (attrs : t) : bool =
159-
Ext_list.exists attrs (fun (({txt}, _) as attr) ->
160-
match txt with
161-
| "optional" ->
162-
Used_attributes.mark_used_attribute attr;
163-
true
164-
| _ -> false)
165-
166158
let has_unwrap_attr (attrs : t) : bool =
167159
Ext_list.exists attrs (fun ({txt}, _) ->
168160
match txt with
@@ -208,12 +200,6 @@ let as_const (attrs : t) =
208200

209201
let locg = Location.none
210202

211-
let get : attr = ({txt = "get"; loc = locg}, Ast_payload.empty)
212-
213-
let get_index : attr = ({txt = "get_index"; loc = locg}, Ast_payload.empty)
214-
215-
let set : attr = ({txt = "set"; loc = locg}, Ast_payload.empty)
216-
217203
let internal_expansive : attr =
218204
({txt = "internal.expansive"; loc = locg}, Ast_payload.empty)
219205

‎compiler/frontend/ast_attributes.mli‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ val arg_encoding : t -> [`Nothing | `String | `Int | `Ignore | `Unwrap]
4141

4242
val as_string : t -> string option
4343

44-
val has_bs_optional : t -> bool
45-
4644
val has_unwrap_attr : t -> bool
4745

4846
val as_int : t -> int option
@@ -52,12 +50,6 @@ val as_const : t -> as_const_payload option
5250

5351
val process_derive_type : t -> derive_attr * t
5452

55-
val get : attr
56-
57-
val get_index : attr
58-
59-
val set : attr
60-
6153
val internal_expansive : attr
6254

6355
val rs_externals : t -> Parsetree.primitive_repr option -> bool

‎compiler/frontend/ast_derive.ml‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,37 @@ let derive_table : derive_table ref = ref Map_string.empty
4141

4242
let register key value = derive_table := Map_string.add !derive_table key value
4343

44+
(* Derivers that used to be built in. They get a dedicated error pointing to
45+
the replacement instead of the generic "is not supported". *)
46+
let removed_deriver_hint = function
47+
| "abstract" ->
48+
Some
49+
"Use a record type instead. Records compile to plain JavaScript objects \
50+
and support optional fields (`field?: t`), mutable fields and `@as` \
51+
field renaming."
52+
| "jsConverter" ->
53+
Some
54+
"Records already compile to plain JavaScript objects and polymorphic \
55+
variants to their (`@as`-renamed) names, so the conversion functions \
56+
are no longer needed."
57+
| _ -> None
58+
59+
let dispatch (({txt = name; loc}, _) as action : Ast_payload.action) =
60+
match removed_deriver_hint name with
61+
| Some hint ->
62+
Location.raise_errorf ~loc "@deriving(%s) has been removed. %s" name hint
63+
| None -> Ast_payload.table_dispatch !derive_table action
64+
4465
let gen_signature tdcls (actions : Ast_payload.action list)
4566
(explict_nonrec : Asttypes.rec_flag) : Ast_signature.t =
4667
Ext_list.flat_map actions (fun action ->
47-
(Ast_payload.table_dispatch !derive_table action).signature_gen tdcls
48-
explict_nonrec)
68+
(dispatch action).signature_gen tdcls explict_nonrec)
4969

5070
open Ast_helper
5171

5272
let gen_structure_signature loc (tdcls : tdcls) (action : Ast_payload.action)
5373
(explicit_nonrec : Asttypes.rec_flag) =
54-
let derive_table = !derive_table in
55-
let u = Ast_payload.table_dispatch derive_table action in
74+
let u = dispatch action in
5675

5776
let a = u.structure_gen tdcls explicit_nonrec in
5877
let b = u.signature_gen tdcls explicit_nonrec in

‎compiler/frontend/ast_derive_abstract.ml‎

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

‎compiler/frontend/ast_derive_abstract.mli‎

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

0 commit comments

Comments
 (0)