|
| 1 | +- Start Date: 2024-02-05 |
| 2 | +- RFC PR: [amaranth-lang/rfcs#42](https://github.com/amaranth-lang/rfcs/pull/42) |
| 3 | +- Amaranth Issue: [amaranth-lang/amaranth#1084](https://github.com/amaranth-lang/amaranth/issues/1084) |
| 4 | + |
| 5 | +# `Const` from shape-castable |
| 6 | + |
| 7 | +## Summary |
| 8 | +[summary]: #summary |
| 9 | + |
| 10 | +Allow passing a shape-castable to `Const`. |
| 11 | + |
| 12 | +## Motivation |
| 13 | +[motivation]: #motivation |
| 14 | + |
| 15 | +We currently have two incompatible syntaxes for making a constant, depending on whether it's made from a `Shape` or a shape-castable. |
| 16 | +The former uses `Const(value, shape)`, while the latter requires `shape.const(value)`. |
| 17 | + |
| 18 | +Making `Const` accept shape-castables means we'll have a syntax that works for all shape-likes, reducing the need to special case for shape-castables. |
| 19 | + |
| 20 | +## Guide- and reference-level explanation |
| 21 | +[guide-level-explanation]: #guide-level-explanation |
| 22 | + |
| 23 | +`Const(value, shape)` checks whether `shape` is a shape-castable and returns `shape.const(value)` when this is the case. |
| 24 | + |
| 25 | +## Drawbacks |
| 26 | +[drawbacks]: #drawbacks |
| 27 | + |
| 28 | +- A `Const()` constructor sometimes returning non-`Const` objects can be confusing. |
| 29 | + - `Signal()` already behaves this way. |
| 30 | + |
| 31 | +## Rationale and alternatives |
| 32 | +[rationale-and-alternatives]: #rationale-and-alternatives |
| 33 | + |
| 34 | +- This is consistent with how `Signal()` handles shape-castables. |
| 35 | + |
| 36 | +Alternatives: |
| 37 | +- Do not do this. Require code that makes constants from a passed shape-like to check whether it got passed a shape-castable or not and pick the appropriate syntax. |
| 38 | + |
| 39 | +## Prior art |
| 40 | +[prior-art]: #prior-art |
| 41 | + |
| 42 | +[RFC #15](0015-lifting-shape-castables.md) added the equivalent behavior to `Signal()`. |
| 43 | + |
| 44 | +## Unresolved questions |
| 45 | +[unresolved-questions]: #unresolved-questions |
| 46 | + |
| 47 | +None. |
| 48 | + |
| 49 | +## Future possibilities |
| 50 | +[future-possibilities]: #future-possibilities |
| 51 | + |
| 52 | +None. |
0 commit comments