Skip to content

Commit 7eb2a48

Browse files
committed
RFC #30: give Signature.annotations() access to interface objects.
In some cases such as SoC memory maps, the contents of an annotation originates from mutable objects, which cannot be attached to a signature.
1 parent da1082e commit 7eb2a48

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

text/0000-component-metadata.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,18 @@ class AsyncSerialAnnotation(Annotation):
211211
return instance
212212
```
213213

214-
We can attach annotations to a `Signature` subclass by overriding its `.annotations` property:
214+
We can attach annotations to a `Signature` subclass by overriding its `.annotations()` method:
215215

216216
```python3
217217
class AsyncSerialSignature(Signature):
218218
# ...
219219

220-
@property
221-
def annotations(self):
222-
return (*super().annotations, AsyncSerialAnnotation(self))
220+
def annotations(self, obj):
221+
return (*super().annotations(obj), AsyncSerialAnnotation(self))
223222
```
224223

224+
In this case, `AsyncSerialAnnotation` depends on immutable metadata attached to `AsyncSerialSignature` (`.data_bits` and `.parity`).
225+
225226
The JSON object returned by ``serial.metadata.as_json()`` will now use this annotation:
226227

227228
```json
@@ -353,7 +354,7 @@ Changes to schema definitions hosted at https://amaranth-lang.org should follow
353354
* a `.as_json()` abstract method, which must return a JSON instance, as a dict. This instance must be compliant with `.schema`, i.e. `self.validate(self.as_json())` must succeed.
354355

355356
The following changes are made to `amaranth.lib.wiring`:
356-
- add a `.annotations` property to `Signature`, which returns an empty tuple. If overriden, it must return an iterable of `Annotation` objects.
357+
- add a `.annotations(self, obj)` method to `Signature`, which returns an empty tuple. If overriden, it must return an iterable of `Annotation` objects. `obj` is an interface object that complies with this signature, i.e. `self.is_compliant(obj)` must succeed.
357358

358359
### Component metadata
359360

0 commit comments

Comments
 (0)