Skip to content

Commit 6e3c582

Browse files
committed
Merge RFC #22: Add ValueCastable.shape()
2 parents e8c4807 + 675b7c4 commit 6e3c582

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

text/0022-valuecastable-shape.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
- Start Date: 2023-08-22
2+
- RFC PR: [amaranth-lang/rfcs#22](https://github.com/amaranth-lang/rfcs/pull/22)
3+
- Amaranth Issue: [amaranth-lang/amaranth#876](https://github.com/amaranth-lang/amaranth/issues/876)
4+
5+
# Define `ValueCastable.shape()`
6+
7+
## Summary
8+
[summary]: #summary
9+
10+
Require value-castable objects to have a method that returns their high-level shape.
11+
12+
## Motivation
13+
[motivation]: #motivation
14+
15+
[RFC #15][] advanced the extensibility of the language significantly, but broke constructs like `Signal.like(Signal(data.StructLayout(...)))`. In addition, not having a well-defined point for returning the high-level shape (i.e. a shape-castable object from which this value-castable object was creaed rather than a `Shape` instance) causes workarounds such as `data.Layout.of` to be added to the language and standard library.
16+
17+
[RFC #15]: 0015-lifting-shape-castables.md
18+
19+
## Explanation
20+
[guide-level-explanation]: #guide-level-explanation
21+
22+
The `ValueCastable` interface has a method `.shape()`. This method returns a shape-castable object. Where possibe, this object should, when passed to `Signal`, create a value-castable object of the same type.
23+
24+
`amaranth.lib.data.Layout.of` is removed immediately.
25+
26+
## Drawbacks
27+
[drawbacks]: #drawbacks
28+
29+
- Increased API surface area
30+
- At one point a commitment was made that the only method `ValueCastable` will ever define will be `as_value`. However, radical changes to the language such as [RFC #15][] make it reasonable to revisit this.
31+
32+
## Rationale and alternatives
33+
[rationale-and-alternatives]: #rationale-and-alternatives
34+
35+
This change is the minimal possible one that fixes the problem systemically. Some minor variations in the design are possible:
36+
- Instead of requiring `shape()` to be defined (which is a breaking change), this method can be added optionally in the next release and be required in the release after that.
37+
- This is difficult to do with `ValueCastable` and will require workarounds both in the core language implementation and in downstream code that operates on `ValueCastable` objects.
38+
- `ValueCastable` is not very widely used yet and the breakage will likely be minimal.
39+
40+
## Prior art
41+
[prior-art]: #prior-art
42+
43+
It is typical for a programming language to have a way of retrieving the type of a value. The mechanism being added here is equivalent.
44+
45+
## Unresolved questions
46+
[unresolved-questions]: #unresolved-questions
47+
48+
None.
49+
50+
## Future possibilities
51+
[future-possibilities]: #future-possibilities
52+
53+
None.

0 commit comments

Comments
 (0)