Skip to content

Commit 8c1c9f2

Browse files
committed
docs: begin building the documentation style guide.
1 parent 877a106 commit 8c1c9f2

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

amaranth/hdl/_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def __invert__(self):
875875
876876
The shape of the result is the same as the shape of :py:`self`, even for unsigned values.
877877
878-
.. important::
878+
.. warning::
879879
880880
In Python, :py:`~0` equals :py:`-1`. In Amaranth, :py:`~C(0)` equals :py:`C(1)`.
881881
This is the only case where an Amaranth operator deviates from the Python operator

amaranth/hdl/_mem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@final
1616
class FrozenMemory(Exception):
17-
"""This exception is raised when a memory array is being modified after elaboration."""
17+
"""Exception raised when a memory array is being modified after elaboration."""
1818

1919

2020
@final
@@ -194,7 +194,7 @@ def __getitem__(self, index):
194194
value that can be used to read and write the selected memory row in a simulation testbench,
195195
without having to create a memory port.
196196
197-
.. important::
197+
.. tip::
198198
199199
Even in a simulation, the value returned by this function cannot be used in a module;
200200
it can only be used with :py:`sim.get()` and :py:`sim.set()`.

amaranth/lib/wiring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ class Signature(metaclass=SignatureMeta):
689689
:class:`Signature` can be used as a base class to define :ref:`customized <wiring-customizing>`
690690
signatures and interface objects.
691691
692-
.. important::
692+
.. warning::
693693
694694
:class:`Signature` objects are immutable. Classes inheriting from :class:`Signature` must
695695
ensure this remains the case when additional functionality is added.
@@ -1143,7 +1143,7 @@ class PureInterface:
11431143
:meth:`Signature.create`, but it can also be used in any other context where an interface
11441144
object needs to be created without the overhead of defining a class for it.
11451145
1146-
.. important::
1146+
.. tip::
11471147
11481148
Any object can be an interface object; it only needs a :py:`signature` property containing
11491149
a compliant signature. It is **not** necessary to use :class:`PureInterface` in order to
@@ -1678,7 +1678,7 @@ def __init__(self, signature=None, *, src_loc_at=0):
16781678
def signature(self):
16791679
"""The signature of the component.
16801680
1681-
.. important::
1681+
.. warning::
16821682
16831683
Do not override this property. Once a component is constructed, its :attr:`signature`
16841684
property must always return the same :class:`Signature` instance. The constructor

docs/contrib.rst

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,49 @@ Occasionally, the documentation builder will persist in rendering an incorrect o
103103
$ pdm run document-live -a
104104
105105
106+
Documentation style guide
107+
=========================
108+
109+
.. warning::
110+
111+
Our documentation style guidelines are evolving, and this section is incomplete.
112+
113+
Some of the fundamental guidelines are:
114+
115+
* **Document the contract and the affordances,** not the implementation. This is especially important because the Amaranth documentation is *the* source of truth for its semantics; the tests and the implementation source code are secondary to it, and the RFCs exist to record the process rather than document the outcome.
116+
* **Shape the code to be documentable.** This is a corollary to the previous guideline. If an interface is difficult to describe in a way that is readily understood, then it may need to be changed. Many breaking changes in Amaranth were done to make the language and libraries easier to understand.
117+
* **Be consistent.** Take inspiration from existing documentation for similar modules. However, don't be consistent at the expense of clarity.
118+
* **Be concise.** It is easy to write boilerplate, and difficult to navigate through it.
119+
120+
* In particular, if the `Parameters` section of the class docstring describes a parameter, it is expected that the same parameter will be available as a class attribute (usually, but not always, read-only), and there is no need to additionally document this fact. If there isn't a corresponding attribute it should likely be added.
121+
* There is no need to individually document every argument and every return value of every method. This mainly creates clutter. The goal in writing documentation is transferring knowledge, not ticking boxes.
122+
123+
Some of the formatting guidelines are:
124+
125+
* Limit code (including docstrings, where possible--some of the Sphinx syntax does not allow wrapping) to 100 columns in ``.py`` files, but do not break paragraphs in ``.rst`` files.
126+
* Use ``###...#`` for first-level headings, ``===...=`` for second-level headings, ``---...-`` for third-level headings.
127+
* Use the ``:py:`...``` syntax for inline Python code references (even trivial ones, e.g. ``:py:`var_name```), ``.. testcode::`` for most Python code blocks (use ``.. code::`` where the code cannot or should not be tested), ``.. doctest::`` for doctests.
128+
* Use admonitions sparingly, and only of the following kinds:
129+
130+
* ``.. warning::`` for text which MUST be paid attention to, or else unexpected bad things may happen. This is the most noticeable kind, rendered in yellow at the moment.
131+
* ``.. tip::`` for text which SHOULD be paid attention to, otherwise annoyance may happen. This is the second most noticeable kind, rendered in bright blue-green at the moment.
132+
* ``.. note::`` for text which MAY be paid attention to, but which is not key for understanding of the topic as a whole. This is the least noticeable kind, rendered in faint blue at the moment.
133+
* ``.. todo::`` may also be used for incomplete sections.
134+
135+
* For methods, phrase the short description (first line of docstring) like ``Do the thing.``, i.e. as an imperative sentence.
136+
* For properties, phrase the short description (first line of docstring) like ``Value of thing.``, i.e. as a declarative sentence.
137+
* When documenting signatures of interfaces, as well as components, use the (non-standard) `Members` section to document their interface members, and only that section; do not document them in an `Attributes` section.
138+
* If an anchor for a section is needed, namespace it, e.g. the ``.. _lang-assignable:`` anchor is a part of the ``lang`` namespace. Anchor names are global.
139+
140+
106141
Contributing your changes
107142
=========================
108143

109-
.. attention::
144+
.. warning::
110145

111-
Our code style guidelines are evolving, and we will eventually have a formal document listing them.
146+
Our code style guidelines are evolving, and we do not yet have a formal document listing them.
112147

113-
At the moment there is no formal style guide for source code. We ask that you do your best effort to keep the code that you add or modify similar in style as well as in spirit to the code surrounding it, and we may ask you to change it during review. When in doubt, submit your code as-is.
148+
We ask that you do your best effort to keep the code that you add or modify similar in style as well as in spirit to the code surrounding it, and we may ask you to change it during review. When in doubt, submit your code as-is.
114149

115150

116151
Weekly meetings

docs/guide.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,9 @@ Crucially, this means that any Python object can be added to an array; the only
811811

812812
An array becomes immutable after it is indexed for the first time. The elements of the array do not themselves become immutable, but it is not recommended to mutate them as the behavior can become unpredictable.
813813

814-
.. important::
814+
.. warning::
815815

816-
Each time an array proxy object with ``n`` elements is used in an expression, it generates a multiplexer with ``n`` branches. However, using ``k`` of such array proxy objects in an expression generates a multiplexer with ``n**k`` branches. This can generate extremely large circuits that may quickly exhaust the resources of the synthesis target or even the available RAM.
816+
Each time an array proxy object with :py:`n` elements is used in an expression, it generates a multiplexer with :py:`n` branches. However, using :py:`k` of such array proxy objects in an expression generates a multiplexer with :py:`n**k` branches. This can generate extremely large circuits that may quickly exhaust the resources of the synthesis target or even the available RAM.
817817

818818

819819
.. _lang-data:
@@ -1499,7 +1499,7 @@ The :meth:`~Elaboratable.elaborate` method must either return an instance of :cl
14991499

15001500
The :py:`platform` argument received by the :meth:`~Elaboratable.elaborate` method can be :py:`None`, an instance of :ref:`a built-in platform <platform>`, or a custom object. It is used for `dependency injection <https://en.wikipedia.org/wiki/Dependency_injection>`_ and to contain the state of a design while it is being elaborated.
15011501

1502-
.. important::
1502+
.. warning::
15031503

15041504
The :meth:`~Elaboratable.elaborate` method should not modify the ``self`` object it receives other than for debugging and experimentation. Elaborating the same design twice with two identical platform objects should produce two identical netlists. If the design needs to be modified after construction, this should happen before elaboration.
15051505

@@ -1665,7 +1665,7 @@ The renaming of the ``sync`` clock domain in it causes the behavior of the final
16651665
m.d.video += count.eq(count + 1)
16661666
m.d.comb += zero.eq(count == 0)
16671667

1668-
.. tip::
1668+
.. warning::
16691669

16701670
A combinatorial signal can change synchronously to a clock domain, as in the example above, in which case it may only be sampled from the same clock domain unless explicitly synchronized. Renaming a clock domain must be assumed to potentially affect any output of an elaboratable.
16711671

0 commit comments

Comments
 (0)