Skip to content

Commit 8672f74

Browse files
Mitchell KemberCQ Bot
authored andcommitted
[fidlc] Implement @available argument 'renamed'
This implements the @available argument 'renamed' from the design document "FIDL versioning: Renaming". The `renamed` argument can only be used on members, not declarations. It must be used together with either `replaced` or `removed`. For example, here is how you rename a table field: type Foo = table { @available(replaced=2, renamed="good_name") 1: bad_name string; @available(added=2) 1: good_name string; }; Here is how you remove a table field and use a different name for it post-removal, e.g. when targeting multiple versions {1,2}: type Foo = table { @available(removed=2, renamed="deprecated_name") 1: name string; }; In both cases the original name is free to be reused. A follow-up will add ordinal validation (https://fxbug.dev/335716034). This will make the system much more useful since the compiler will enforce using the correct removed/replaced/renamed combination. Test: fx test fidlc-test Bug: 42085274 Change-Id: Ibcf4dff225776a6ec604fa9a169f1aef52f36631 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1042482 Commit-Queue: Mitchell Kember <mkember@google.com> API-Review: Ian McKellar <ianloic@google.com> Reviewed-by: Ian McKellar <ianloic@google.com>
1 parent 4baef7c commit 8672f74

34 files changed

+807
-65
lines changed

docs/error/_redirects.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,13 @@ redirects:
422422
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0209
423423
- from: /fuchsia-src/error/fi-0210
424424
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0210
425+
- from: /fuchsia-src/error/fi-0211
426+
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0211
427+
- from: /fuchsia-src/error/fi-0212
428+
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0212
429+
- from: /fuchsia-src/error/fi-0213
430+
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0213
431+
- from: /fuchsia-src/error/fi-0214
432+
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0214
433+
- from: /fuchsia-src/error/fi-0215
434+
to: /fuchsia-src/reference/fidl/language/errcat.md#fi-0215

docs/reference/fidl/language/errcat.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,14 @@ This document lists all errors emitted by the [FIDL compiler][docs-fidlc],
418418

419419
<<error-catalog/_fi-0210.md>>
420420

421+
<<error-catalog/_fi-0211.md>>
422+
423+
<<error-catalog/_fi-0212.md>>
424+
425+
<<error-catalog/_fi-0213.md>>
426+
427+
<<error-catalog/_fi-0214.md>>
428+
429+
<<error-catalog/_fi-0215.md>>
430+
421431
[docs-fidlc]: ../language/fidlc.md

docs/reference/fidl/language/error-catalog/_fi-0205.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
1-
## fi-0205: Removed element must not have a replacement {:#fi-0205}
1+
## fi-0205: Invalid `@available(removed=N)` {:#fi-0205}
22

3-
When an element is marked `@available(removed=N)`, it indicates that the element
4-
can no longer be used at version `N`. It should not merely be replaced by a new
5-
definition marked `@available(added=N)`:
3+
When an element is marked `@available(removed=N)`, it means the element can no
4+
longer be used at version `N`. You cannot reuse its name:
65

76
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
87

98
```fidl
109
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0205.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
1110
```
1211

13-
If the replacement is intentional, make it explicit by using the `replaced`
14-
argument instead of the `removed` argument:
12+
If you want to replace the element with a new definition (same API and ABI), use
13+
the `replaced` argument instead of the `removed` argument:
1514

1615
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
1716

1817
```fidl
1918
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0205-a.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
2019
```
2120

22-
If the replacement is unintentional, remove or rename the other element:
21+
If you want to remove the element and define a new, unrelated element (different
22+
API and ABI), choose a different name for the new element:
2323

2424
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
2525

2626
```fidl
2727
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0205-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
2828
```
2929

30-
The `removed` and `replaced` arguments both have the same effect on the
31-
generated bindings, but they represent different points in API lifecycle. The
32-
`removed` argument indicates the end of an API, while the `replaced` argument
33-
indicates a transition to a new definition.
30+
If you really want to reuse the name (same API, different ABI), use the
31+
`renamed` argument to rename the old element post-removal, freeing up its
32+
original name:
33+
34+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
35+
36+
```fidl
37+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0205-c.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
38+
```
39+
40+
Notice that in this case you must use `@selector` to ensure the new method has a
41+
different ABI.
3442

3543
See [FIDL versioning][fidl-versioning] to learn more about versioning.
3644

docs/reference/fidl/language/error-catalog/_fi-0206.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## fi-0206: Replaced element has no replacement {:#fi-0206}
1+
## fi-0206: Invalid `@available(replaced=N)` {:#fi-0206}
22

3-
When an element is marked `@available(replaced=N)`, it indicates that the
4-
element is replaced by a new definition marked `@available(added=N)`. The FIDL
5-
compiler will report an error if it cannot find such a definition:
3+
When an element is marked `@available(replaced=N)`, it means the element is
4+
replaced by a new definition marked `@available(added=N)`. The FIDL compiler
5+
will report an error if it cannot find such a definition:
66

77
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
88

@@ -27,11 +27,6 @@ If you intended to replace the element, add a replacement definition:
2727
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0206-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
2828
```
2929

30-
The `removed` and `replaced` arguments both have the same effect on the
31-
generated bindings, but they represent different points in API lifecycle. The
32-
`removed` argument indicates the end of an API, while the `replaced` argument
33-
indicates a transition to a new definition.
34-
3530
See [FIDL versioning][fidl-versioning] to learn more about versioning.
3631

3732
[fidl-versioning]: /docs/reference/fidl/language/versioning.md
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## fi-0211: Element cannot be renamed {:#fi-0211}
2+
3+
The `@available` attribute's `renamed` argument can only be used on members of
4+
declarations, not on declarations themselves:
5+
6+
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
7+
8+
```fidl
9+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0211.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
10+
```
11+
12+
Instead of renaming a declaration, remove the old one and add a new one:
13+
14+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
15+
16+
```fidl
17+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0211.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
18+
```
19+
20+
Renaming is only supported on members because the FIDL compiler can compare
21+
their ABI identity (e.g. table ordinal) to ensure it is done correctly.
22+
23+
The `renamed` argument is also not allowed on the following elements either:
24+
25+
* `library`: You can't rename a library from within because the FIDL toolchain
26+
assumes each library has a single name. Instead, you should create a new
27+
library with the desired name and migrate users to it.
28+
* `compose`: You can't rename a protocol composition because compositions are
29+
not named to begin with.
30+
31+
See [FIDL versioning][fidl-versioning] to learn more about versioning.
32+
33+
[fidl-versioning]: /docs/reference/fidl/language/versioning.md
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## fi-0212: Renamed without replaced or removed {:#fi-0212}
2+
3+
The `@available` argument `renamed` is not allowed on its own. It must be used
4+
together with the `replaced` or `removed` argument:
5+
6+
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
7+
8+
```fidl
9+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0212.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
10+
```
11+
12+
If you just want to rename the element at version `N`, use `replaced=N` and
13+
define a replacement with the new name marked `added=N`:
14+
15+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
16+
17+
```fidl
18+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0212-a.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
19+
```
20+
21+
In this case, the replacement method must override `@selector` for ABI
22+
compatibility.
23+
24+
Alternatively, if you want to remove the element at version `N` and refer to it
25+
by a different name after its removal, use `removed=N`:
26+
27+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
28+
29+
```fidl
30+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0212-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
31+
```
32+
33+
In this case, the new name will only be used when targeting multiple versions
34+
(e.g. `--available test:1,2`) since that is the only way to include the element
35+
while also targeting a version past its removal.
36+
37+
See [FIDL versioning][fidl-versioning] to learn more about versioning.
38+
39+
[fidl-versioning]: /docs/reference/fidl/language/versioning.md
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## fi-0213: Renamed to same name {:#fi-0213}
2+
3+
When renaming an element with the `@available` argument `renamed`, the new name
4+
cannot be the same as the element's original name:
5+
6+
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
7+
8+
```fidl
9+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0213.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
10+
```
11+
12+
To fix the error, remove the `renamed` argument:
13+
14+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
15+
16+
```fidl
17+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0213-a.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
18+
```
19+
20+
Alternatively, keep the `renamed` argument but choose a different name:
21+
22+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
23+
24+
```fidl
25+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0213-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
26+
```
27+
28+
See [FIDL versioning][fidl-versioning] to learn more about versioning.
29+
30+
[fidl-versioning]: /docs/reference/fidl/language/versioning.md
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## fi-0214: Invalid `@available(removed=N, renamed="NewName")` {:#fi-0214}
2+
3+
This is like [fi-0205: Invalid `@available(removed=N)`](#fi-0205), but for when
4+
the `renamed` argument is involved.
5+
6+
When an element is marked `@available(removed=N, renamed="NewName")`, it means
7+
the element can no longer be used at version `N`, and is renamed to "NewName"
8+
post-removal. You cannot use "NewName" for something else:
9+
10+
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
11+
12+
```fidl
13+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0214.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
14+
```
15+
16+
If you want to rename the element while keeping its ABI, use the `replaced`
17+
argument instead of the `removed` argument:
18+
19+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
20+
21+
```fidl
22+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0214-a.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
23+
```
24+
25+
Notice that in this case you must use `@selector` to ensure the renamed method
26+
has the same ABI.
27+
28+
If you want the new element to have a different ABI, then keep `removed` and
29+
ensure that the `renamed` argument and the new element use different names:
30+
31+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
32+
33+
```fidl
34+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0214-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
35+
```
36+
37+
See [FIDL versioning][fidl-versioning] to learn more about versioning.
38+
39+
[fidl-versioning]: /docs/reference/fidl/language/versioning.md
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## fi-0215: Invalid `@available(replaced=N, renamed="NewName")` {:#fi-0215}
2+
3+
This is like [fi-0206: Invalid `@available(replaced=N)`](#fi-0206), but for when
4+
the `renamed` argument is involved.
5+
6+
When an element is marked `@available(replaced=N, renamed="NewName")`, it means
7+
the element is replaced by a new definition named "NewName" and marked with
8+
`@available(added=N)`. The FIDL compiler will report an error if it cannot find
9+
such a definition:
10+
11+
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
12+
13+
```fidl
14+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0215.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
15+
```
16+
17+
To fix the error, define an element with the new name:
18+
19+
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
20+
21+
```fidl
22+
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0215.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
23+
```
24+
25+
Notice that you must use `@selector` to ensure the renamed method has the same
26+
ABI.
27+
28+
See [FIDL versioning][fidl-versioning] to learn more about versioning.
29+
30+
[fidl-versioning]: /docs/reference/fidl/language/versioning.md

docs/reference/fidl/language/error-catalog/_files.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,8 @@ _fi-0207.md
205205
_fi-0208.md
206206
_fi-0209.md
207207
_fi-0210.md
208+
_fi-0211.md
209+
_fi-0212.md
210+
_fi-0213.md
211+
_fi-0214.md
212+
_fi-0215.md

0 commit comments

Comments
 (0)