Skip to content

Commit b3be9aa

Browse files
authored
Remove meth attribute (#7684)
* Remove meth attribute when running formatter * Remove @meth in test * WIP: More removal * More @meth removal * Redo removal method * Update test file * Update CHANGELOG
1 parent 36824ed commit b3be9aa

File tree

18 files changed

+70
-113
lines changed

18 files changed

+70
-113
lines changed

.mcp.json

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

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Polish arity mismatch error message a bit. https://github.com/rescript-lang/rescript/pull/7709
3131
- Suggest related functions with the expected arity in errors when it makes sense. https://github.com/rescript-lang/rescript/pull/7712
3232
- Improve error when a constructor expects an inline record. https://github.com/rescript-lang/rescript/pull/7713
33+
- Remove @meth attribute. https://github.com/rescript-lang/rescript/pull/7684
3334

3435
#### :house: Internal
3536

analysis/examples/larger-project/src/BucklescriptAnnotations.res

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ type someMutableFields = {
1111

1212
@genType
1313
type someMethods = {
14-
@meth
1514
"send": string => unit,
16-
@meth
1715
"on": (string, (. int) => unit) => unit,
18-
@meth
1916
"threeargs": (int, string, int) => string,
2017
"twoArgs": (. int, string) => int,
2118
}

compiler/frontend/ast_attributes.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,12 @@ let process_method_attributes_rev (attrs : t) =
7474
({st with set = Some result}, acc)
7575
| _ -> (st, attr :: acc))
7676

77-
type attr_kind = Nothing | Meth_callback of attr | Method of attr
77+
type attr_kind = Nothing | Meth_callback of attr
7878

7979
let process_attributes_rev (attrs : t) : attr_kind * t =
80-
Ext_list.fold_left attrs (Nothing, [])
81-
(fun (st, acc) (({txt; loc}, _) as attr) ->
80+
Ext_list.fold_left attrs (Nothing, []) (fun (st, acc) (({txt}, _) as attr) ->
8281
match (txt, st) with
8382
| "this", (Nothing | Meth_callback _) -> (Meth_callback attr, acc)
84-
| "meth", (Nothing | Method _) -> (Method attr, acc)
85-
| "this", _ -> Bs_syntaxerr.err loc Conflict_bs_bs_this_bs_meth
8683
| _, _ -> (st, attr :: acc))
8784

8885
let external_attrs =

compiler/frontend/ast_attributes.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type ('a, 'b) st = {get: 'a option; set: 'b option}
2929

3030
val process_method_attributes_rev : t -> (bool * bool, [`Get | `No_get]) st * t
3131

32-
type attr_kind = Nothing | Meth_callback of attr | Method of attr
32+
type attr_kind = Nothing | Meth_callback of attr
3333

3434
val process_attributes_rev : t -> attr_kind * t
3535

compiler/frontend/ast_core_type_class_type.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
7575
match fst (Ast_attributes.process_attributes_rev ty.ptyp_attributes) with
7676
| Meth_callback _ ->
7777
Ast_typ_uncurry.to_method_callback_type loc self ~arity ty
78-
| Method _ -> Bs_ast_mapper.default_mapper.typ self ty
7978
| Nothing -> Bs_ast_mapper.default_mapper.typ self ty)
8079
| Ptyp_object (methods, closed_flag) ->
8180
let ( +> ) attr (typ : Parsetree.core_type) =
@@ -90,8 +89,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
9089
let attrs, core_type =
9190
match Ast_attributes.process_attributes_rev attrs with
9291
| Nothing, attrs -> (attrs, ty) (* #1678 *)
93-
| Method _, _ ->
94-
Location.raise_errorf ~loc "%@get/set conflicts with %@meth"
9592
| Meth_callback attr, attrs -> (attrs, attr +> ty)
9693
in
9794
Ast_compatible.object_field name attrs (self.typ self core_type)
@@ -100,8 +97,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
10097
let attrs, core_type =
10198
match Ast_attributes.process_attributes_rev attrs with
10299
| Nothing, attrs -> (attrs, ty)
103-
| Method _, _ ->
104-
Location.raise_errorf ~loc "%@get/set conflicts with %@meth"
105100
| Meth_callback attr, attrs -> (attrs, attr +> ty)
106101
in
107102
Ast_compatible.object_field name attrs
@@ -113,7 +108,6 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
113108
let attrs, core_type =
114109
match Ast_attributes.process_attributes_rev ptyp_attrs with
115110
| Nothing, attrs -> (attrs, ty)
116-
| Method attr, attrs -> (attrs, attr +> ty)
117111
| Meth_callback attr, attrs -> (attrs, attr +> ty)
118112
in
119113
Ast_compatible.object_field label attrs (self.typ self core_type)

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
102102
async_context := (old_in_function_def && !async_context) || async;
103103
in_function_def := true;
104104
Ast_async.make_function_async ~async (default_expr_mapper self e)
105-
| Method _, _ ->
106-
Location.raise_errorf ~loc:e.pexp_loc
107-
"%@meth is not supported in function expression"
108105
| Meth_callback _, pexp_attributes ->
109106
(* FIXME: does it make sense to have a label for [this] ? *)
110107
async_context := false;

compiler/frontend/bs_syntaxerr.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let pp_error fmt err =
6464
| Illegal_attribute -> "Illegal attributes"
6565
| Unsupported_predicates -> "unsupported predicates"
6666
| Conflict_bs_bs_this_bs_meth ->
67-
"%@this, %@bs, %@meth can not be applied at the same time"
67+
"%@this and %@bs can not be applied at the same time"
6868
| Duplicated_bs_deriving -> "duplicate @deriving attribute"
6969
| Conflict_attributes -> "conflicting attributes "
7070
| Expect_string_literal -> "expect string literal "

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ let filter_parsing_attrs attrs =
198198
match attr with
199199
| ( {
200200
Location.txt =
201-
( "res.braces" | "ns.braces" | "res.iflet" | "res.ternary"
202-
| "res.await" | "res.template" | "res.taggedTemplate"
203-
| "res.patVariantSpread" | "res.dictPattern"
204-
| "res.inlineRecordDefinition" );
201+
( "meth" | "res.braces" | "ns.braces" | "res.iflet"
202+
| "res.ternary" | "res.await" | "res.template"
203+
| "res.taggedTemplate" | "res.patVariantSpread"
204+
| "res.dictPattern" | "res.inlineRecordDefinition" );
205205
},
206206
_ ) ->
207207
false

tests/analysis_tests/tests-reanalyze/deadcode/expected/deadcode.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
addVariantCaseDeclaration R4 AutoAnnotate.res:15:2 path:+AutoAnnotate.annotatedVariant
1010
Scanning BootloaderResource.cmt Source:BootloaderResource.res
1111
Scanning BucklescriptAnnotations.cmt Source:BucklescriptAnnotations.res
12-
addValueDeclaration +bar BucklescriptAnnotations.res:25:4 path:+BucklescriptAnnotations
13-
addValueDeclaration +f BucklescriptAnnotations.res:26:6 path:+BucklescriptAnnotations
14-
addValueReference BucklescriptAnnotations.res:26:6 --> BucklescriptAnnotations.res:25:11
15-
addValueReference BucklescriptAnnotations.res:25:4 --> BucklescriptAnnotations.res:26:6
12+
addValueDeclaration +bar BucklescriptAnnotations.res:22:4 path:+BucklescriptAnnotations
13+
addValueDeclaration +f BucklescriptAnnotations.res:23:6 path:+BucklescriptAnnotations
14+
addValueReference BucklescriptAnnotations.res:23:6 --> BucklescriptAnnotations.res:22:11
15+
addValueReference BucklescriptAnnotations.res:22:4 --> BucklescriptAnnotations.res:23:6
1616
Scanning ComponentAsProp.cmt Source:ComponentAsProp.res
1717
addValueDeclaration +make ComponentAsProp.res:6:4 path:+ComponentAsProp
1818
addRecordLabelDeclaration title ComponentAsProp.res:6:12 path:+ComponentAsProp.props
@@ -2594,9 +2594,9 @@ File References
25942594
BucklescriptAnnotations is a dead module as all its items are dead.
25952595

25962596
Warning Dead Value
2597-
BucklescriptAnnotations.res:25:1-70
2597+
BucklescriptAnnotations.res:22:1-70
25982598
bar is never used
2599-
<-- line 25
2599+
<-- line 22
26002600
@dead("bar") let bar = (x: someMethods) => {
26012601

26022602
Warning Dead Exception

0 commit comments

Comments
 (0)