Skip to content

Commit 3bdfa23

Browse files
committed
[SIL.rst] Add docs explaining how Move Only Types can be copied in Raw SIL, but not in later SIL stages.
Since I am going to start enforcing this invariant more broadly, I want to document it in SIL.rst. I also included a discussion explaining why we maintain this invariant: it enables SILGen to use a simple algorithm to insert copies/us to clean that up using a diagnostic guaranteed optimization pass which runs on Raw SIL.
1 parent 64a984b commit 3bdfa23

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/SIL.rst

+26
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,32 @@ sil-opt, one will see that we actually have an ownership violation due to the
27622762
two uses of "value", one for initializing value2 and the other for the return
27632763
value.
27642764

2765+
Move Only Types
2766+
---------------
2767+
2768+
NOTE: This is experimental and is just an attempt to describe where the design
2769+
is currently for others reading SIL today. It should not be interpreted as
2770+
final.
2771+
2772+
Currently there are two kinds of "move only types" in SIL: pure move only types
2773+
that are always move only and move only wrapped types that are move only
2774+
versions of copyable types. The invariant that values of Move Only type obey is
2775+
that they can only be copied (e.x.: operand to a `copy_value`_, ``copy_addr [init]``) during the
2776+
guaranteed passes when we are in Raw SIL. Once we are in non-Raw SIL though
2777+
(i.e. Canonical and later SIL stages), a program is ill formed if one copies a
2778+
move only type.
2779+
2780+
The reason why we have this special rule for move only types is that this allows
2781+
for SIL code generators to insert copies and then have a later guaranteed
2782+
checker optimization pass recover the underlying move only semantics by
2783+
reconstructing needed copies and removing unneeded copies using Ownership
2784+
SSA. If any such copies are actually needed according to Ownership SSA, the
2785+
checker pass emits a diagnostic stating that move semantics have been
2786+
violated. If such a diagnostic is emitted then the checker pass transforms all
2787+
copies on move only types to their explicit copy forms to ensure that once we
2788+
leave the diagnostic passes and enter canonical SIL, our "copy" invariant is
2789+
maintained.
2790+
27652791
Runtime Failure
27662792
---------------
27672793

0 commit comments

Comments
 (0)