Repository navigation
Commit b7c67d2
Remove OCaml attribute aliases and the features only OCaml used (#8928)
* Remove OCaml attribute aliases and the features only OCaml used
Why:
The compiler still accepted OCaml spellings of builtin attributes that
nothing in ReScript produces, and some of them only half worked:
`@ocaml.unboxed` changed the type's representation but was ignored by
untagged variants. `@boxed`, `@deprecated_mutable` and
`%extension_constructor` are OCaml features with no use in ReScript.
The `ocaml.*` spellings are now rejected with the bare name to use instead.
`@boxed` and `@deprecated_mutable` are reported as unused attributes, and
`%extension_constructor` as an uninterpreted extension. With it go the
typed tree node `Texp_extension_constructor`, the predefined type
`extension_constructor`, the error "A type cannot be boxed and unboxed at
the same time." and the deprecated-mutation checks. The CMT magic number is
bumped.
Diagnostic added (removed OCaml spelling):
Example:
@ocaml.unboxed
type t = Name(string)
Before (diagnostic): (none, the type is unboxed)
After (diagnostic):
`@ocaml.unboxed` is no longer supported, use `@unboxed` instead.
Diagnostic modified (boxed and unboxed):
Example:
@unboxed @boxed
type t = One(int)
Before (diagnostic):
A type cannot be boxed and unboxed at the same time.
After (diagnostic):
Warning number 101
Unused attribute: @boxed
This attribute has no effect here.
Diagnostic modified (extension constructor):
Example:
exception A
let _ = %extension_constructor(A)
Before (diagnostic): (none, the constructor's slot)
After (diagnostic):
Uninterpreted extension 'extension_constructor'.
Typedtree removed (Texp_extension_constructor):
Before (typed):
expression
Texp_extension_constructor "A"
After (typed): (removed)
Breaking: `@ocaml.deprecated`, `@ocaml.unboxed`, `@ocaml.immediate` and `@ocaml.warnerror` are errors; use `@deprecated`, `@unboxed`, `@immediate` and `@warnerror`. `@ocaml.boxed`, `@ocaml.deprecated_mutable` and `@ocaml.text` are errors; remove them (use a doc comment for `@ocaml.text`). `@boxed` and `@deprecated_mutable` are unused attributes (warning 101, an error by default); remove them. `%extension_constructor` and the type `extension_constructor` are gone.
Review: Why keep `@ocaml.ppwarning`? ppxlib's driver emits `[@@@ocaml.ppwarning]` for lint warnings, so PPXs built with ppxlib still produce it.
Review: Why keep `@immediate`, `@warnerror` and `@ppwarning`? `@immediate` on an abstract type makes comparisons on it compile to `===`/`<`; `@warnerror` turns warnings into errors in a scope; `@ppwarning` is how PPXs report warnings.
Review: Does removing a typed tree constructor break reading older CMTs? The CMT magic is bumped; older CMTs were already unreadable since `Texp_dict` was inserted mid-variant.
Area: compiler/ml, compiler/frontend, analysis
Output: unchanged for programs that use none of the removed spellings
Tests: super_errors fixtures for the removed spellings, unused `@boxed`/`@deprecated_mutable` and `%extension_constructor`; three obsolete fixtures removed; `@ocaml.unboxed` in the reanalyze and gentype tests switched to `@unboxed`
PPX: v0 wire unchanged; `ocaml.error`, `ocaml.warning`, `ocaml.ppwarning` and `ocaml.explicit_arity` still accepted
Editor: hover no longer reads `@ocaml.text` as documentation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Read warning and error attributes only by their bare names
Why:
`ocaml.warning`, `ocaml.ppwarning` and `ocaml.error` were still read
everywhere because PPXs built on OCaml tooling emit them (ppxlib reports
errors as `[%ocaml.error]` and lint warnings as `[@@@ocaml.ppwarning]`).
Renaming them once, where PPX output enters the compiler, lets every
other reader use the bare name.
The PPX bridge (`Ast_mapper_from0`) renames the three names in its default
attribute and extension mappers, so they are renamed at any depth,
payloads included. `Ast_mapper.extension_of_error` emits `error`, and the
internal `ocaml.warn_on_literal_pattern` that `Predef` puts on `Failure`
and `Invalid_argument` is now `warn_on_literal_pattern`. Written by hand in
source, the prefixed spellings are rejected like the other removed
aliases; the check now also sees attributes on constants.
AST modified (PPX output):
Example:
%%ocaml.error("ppx error")
let x = @ocaml.warning("-3") 1
Before (parse):
structure_item
Pstr_extension "ocaml.error"
attribute "ocaml.warning"
After (parse):
structure_item
Pstr_extension "error"
attribute "warning"
Diagnostic added (written by hand):
Example:
@@ocaml.warning("-32")
Before (diagnostic): (none, warning 32 disabled)
After (diagnostic):
`@ocaml.warning` is no longer supported, use `@warning` instead.
Breaking: `@ocaml.warning`, `@ocaml.ppwarning` and `%ocaml.error` in source are errors; use `@warning`, `@ppwarning` and `%error`. A hand-written `@ocaml.warn_on_literal_pattern` no longer has an effect. PPX output that uses the prefixed names keeps working.
Review: Can a PPX's `ocaml.warning` still reach the error check? Only if the bridge skipped an attribute position; the ounit test covers structure and signature items, type declarations, expressions and attribute payloads, and the ast-mapping fixture covers the parser round trip.
Review: Does warning 52 still fire on `Failure("boom")`? Yes, a new super_errors fixture covers it.
Area: compiler/ml, compiler/frontend, analysis
Output: unchanged
Tests: ounit tests for the bridge renaming and `extension_of_error`; ast-mapping fixture OcamlPrefixedBuiltins; super_errors fixtures for hand-written `@ocaml.warning`, `@ocaml.ppwarning`, `%ocaml.error` and warning 52 on `Failure`; the reanalyze test's `@@ocaml.warning` switched to `@@warning`
PPX: v0 wire unchanged; `ocaml.warning`, `ocaml.ppwarning` and `ocaml.error` from a PPX are renamed to the bare names; `ocaml.explicit_arity` still read by the bridge
Editor: reanalyze reads only `@warning`
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Ignore `@boxed` and `@deprecated_mutable` like any unknown attribute
Why:
Reporting them as unused attributes (warning 101, an error by default)
broke builds over attributes that never changed anything in ReScript.
Diagnostic removed (unused boxed):
Example:
@boxed
type t = One(int)
Before (diagnostic):
Warning number 101
Unused attribute: @boxed
This attribute has no effect here.
After (diagnostic): (none, the attribute is ignored)
Breaking: `@boxed` and `@deprecated_mutable` are no longer interpreted and are silently ignored; remove them.
Area: compiler/frontend
Output: unchanged
Tests: the unused_boxed_deprecated_mutable super_errors fixture is removed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Reject removed `ocaml.*` spellings before external PPXs and bump the CMI magic
Why:
With a `-ppx`, the source tree went through the PPX bridge, which
renames `ocaml.warning`, `ocaml.ppwarning` and `ocaml.error` to the bare
names, before the removed-spelling check ran, so hand-written
`@@ocaml.warning("-32")` was silently accepted. Removing the predefined
type `extension_constructor` shifted the stamps of later predefined
types, but `.cmi` files from before the change were still accepted.
`Cmd_ppx_apply` now runs the removed-spelling check from `Bs_ast_invariant`
on the source before handing it to external PPXs; the check after the PPXs
is unchanged. The CMI magic number is bumped to `Caml1999I039`.
Diagnostic added (with an external PPX):
Example:
@@ocaml.warning("-32")
let value = 1
Before (diagnostic): (none, accepted as `@@warning("-32")`)
After (diagnostic):
`@ocaml.warning` is no longer supported, use `@warning` instead.
Breaking: `.cmi` files built by an earlier compiler are rejected; rebuild them.
Area: compiler/core, compiler/frontend, compiler/ext
Output: unchanged
Tests: ounit test ppx_removed_ocaml_spelling compiles `@@ocaml.warning`, `@ocaml.ppwarning` in an interface and `%ocaml.error` through an identity PPX and expects the errors, and `@@warning` to compile
PPX: v0 wire unchanged; source is checked before it is sent to a PPX, and PPX output is still renamed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Remove redundant tests for the removed OCaml spellings
The removed `ocaml.*` attributes share one table lookup, which the
`@ocaml.unboxed` fixture already covers. Warning 52 on predefined
exceptions is covered by `warning_52_fragile_literal_pattern`, and the
bridge renaming by the ounit test.
Area: tests
Output: unchanged
Tests: removed super_errors fixtures removed_ocaml_deprecated, removed_ocaml_boxed, removed_ocaml_warning, removed_ocaml_ppwarning and warning_52_failure_literal_pattern, and the ast-mapping fixture OcamlPrefixedBuiltins, each with its expected file
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
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 f79ec1f commit b7c67d2
47 files changed
Lines changed: 298 additions & 237 deletions
File tree
- analysis
- reanalyze/src
- src
- changes
- compiler
- core
- ext
- frontend
- ml
- tests
- analysis_tests/tests-reanalyze/deadcode/src
- build_tests/super_errors
- expected
- fixtures
- gentype_tests/typescript-react-example/src
- ounit_tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 86 | + | |
90 | 87 | | |
91 | 88 | | |
92 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1033 | 1033 | | |
1034 | 1034 | | |
1035 | 1035 | | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
| 1036 | + | |
| 1037 | + | |
1042 | 1038 | | |
1043 | 1039 | | |
1044 | 1040 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | 81 | | |
84 | 82 | | |
85 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
37 | 64 | | |
38 | 65 | | |
39 | 66 | | |
| |||
71 | 98 | | |
72 | 99 | | |
73 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
74 | 105 | | |
75 | 106 | | |
76 | 107 | | |
| |||
85 | 116 | | |
86 | 117 | | |
87 | 118 | | |
88 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
89 | 122 | | |
90 | 123 | | |
91 | 124 | | |
| |||
136 | 169 | | |
137 | 170 | | |
138 | 171 | | |
139 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
140 | 175 | | |
141 | 176 | | |
142 | 177 | | |
| |||
165 | 200 | | |
166 | 201 | | |
167 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
640 | 640 | | |
641 | 641 | | |
642 | 642 | | |
643 | | - | |
| 643 | + | |
644 | 644 | | |
645 | 645 | | |
646 | 646 | | |
| |||
0 commit comments