@@ -1573,34 +1573,79 @@ impl Statement<'_> {
1573
1573
/// causing an ICE if they are violated.
1574
1574
#[ derive( Clone , Debug , PartialEq , TyEncodable , TyDecodable , Hash , HashStable , TypeFoldable ) ]
1575
1575
pub enum StatementKind < ' tcx > {
1576
- /// Write the RHS Rvalue to the LHS Place.
1576
+ /// Assign statements roughly correspond to an assignment in Rust proper (`x = ...`) except
1577
+ /// without the possibility of dropping the previous value (that must be done separately, if at
1578
+ /// all). The *exact* way this works is undecided. It probably does something like evaluating
1579
+ /// the LHS and RHS, and then doing the inverse of a place to value conversion to write the
1580
+ /// resulting value into memory. Various parts of this may do type specific things that are more
1581
+ /// complicated than simply copying over the bytes depending on the types.
1577
1582
///
1578
- /// The LHS place may not overlap with any memory accessed on the RHS.
1583
+ /// **Needs clarification**: The implication of the above idea would be that assignment implies
1584
+ /// that the resulting value is initialized. I believe we could commit to this separately from
1585
+ /// committing to whatever part of the memory model we would need to decide on to make the above
1586
+ /// paragragh precise. Do we want to?
1587
+ ///
1588
+ /// Assignments in which the types of the place and rvalue differ are not well-formed.
1589
+ ///
1590
+ /// **Needs clarification**: Do we ever want to worry about non-free (in the body) lifetimes for
1591
+ /// the typing requirement in post drop-elaboration MIR? I think probably not - I'm not sure we
1592
+ /// could meaningfully require this anyway. How about free lifetimes? Is ignoring this
1593
+ /// interesting for optimizations? Do we want to allow such optimizations?
1594
+ ///
1595
+ /// **Needs clarification**: We currently require that the LHS place not overlap with any place
1596
+ /// read as part of computation of the RHS. This requirement is under discussion in [#68364]. As
1597
+ /// a part of this discussion, it is also unclear in what order the components are evaluated.
1598
+ ///
1599
+ /// [#68364]: https://github.com/rust-lang/rust/issues/68364
1600
+ ///
1601
+ /// See [`Rvalue`] documentation for details on each of those.
1579
1602
Assign ( Box < ( Place < ' tcx > , Rvalue < ' tcx > ) > ) ,
1580
1603
1581
- /// This represents all the reading that a pattern match may do
1582
- /// (e.g., inspecting constants and discriminant values), and the
1583
- /// kind of pattern it comes from. This is in order to adapt potential
1584
- /// error messages to these specific patterns.
1604
+ /// This represents all the reading that a pattern match may do (e.g., inspecting constants and
1605
+ /// discriminant values), and the kind of pattern it comes from. This is in order to adapt
1606
+ /// potential error messages to these specific patterns.
1585
1607
///
1586
1608
/// Note that this also is emitted for regular `let` bindings to ensure that locals that are
1587
1609
/// never accessed still get some sanity checks for, e.g., `let x: ! = ..;`
1610
+ ///
1611
+ /// When executed at runtime this is a nop.
1612
+ ///
1613
+ /// Disallowed after drop elaboration.
1588
1614
FakeRead ( Box < ( FakeReadCause , Place < ' tcx > ) > ) ,
1589
1615
1590
1616
/// Write the discriminant for a variant to the enum Place.
1591
1617
SetDiscriminant { place : Box < Place < ' tcx > > , variant_index : VariantIdx } ,
1592
1618
1593
- /// Start a live range for the storage of the local.
1619
+ /// `StorageLive` and `StorageDead` statements mark the live range of a local.
1620
+ ///
1621
+ /// Using a local before a `StorageLive` or after a `StorageDead` is not well-formed. These
1622
+ /// statements are not required. If the entire MIR body contains no `StorageLive`/`StorageDead`
1623
+ /// statements for a particular local, the local is always considered live.
1624
+ ///
1625
+ /// More precisely, the MIR validator currently does a `MaybeLiveLocals` analysis to check
1626
+ /// validity of each use of a local. I believe this is equivalent to requiring for every use of
1627
+ /// a local, there exist at least one path from the root to that use that contains a
1628
+ /// `StorageLive` more recently than a `StorageDead`.
1629
+ ///
1630
+ /// **Needs clarification**: Is it permitted to `StorageLive` a local for which we previously
1631
+ /// executed `StorageDead`? How about two `StorageLive`s without an intervening `StorageDead`?
1632
+ /// Two `StorageDead`s without an intervening `StorageLive`? LLVM says yes, poison, yes. If the
1633
+ /// answer to any of these is "no," is breaking that rule UB or is it an error to have a path in
1634
+ /// the CFG that might do this?
1594
1635
StorageLive ( Local ) ,
1595
1636
1596
- /// End the current live range for the storage of the local .
1637
+ /// See `StorageLive` above .
1597
1638
StorageDead ( Local ) ,
1598
1639
1599
- /// Retag references in the given place, ensuring they got fresh tags. This is
1600
- /// part of the Stacked Borrows model. These statements are currently only interpreted
1601
- /// by miri and only generated when "-Z mir-emit-retag" is passed.
1602
- /// See <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/>
1603
- /// for more details.
1640
+ /// Retag references in the given place, ensuring they got fresh tags.
1641
+ ///
1642
+ /// This is part of the Stacked Borrows model. These statements are currently only interpreted
1643
+ /// by miri and only generated when `-Z mir-emit-retag` is passed. See
1644
+ /// <https://internals.rust-lang.org/t/stacked-borrows-an-aliasing-model-for-rust/8153/> for
1645
+ /// more details.
1646
+ ///
1647
+ /// For code that is not specific to stacked borrows, you should consider statements to read
1648
+ /// and modify the place in an opaque way.
1604
1649
Retag ( RetagKind , Box < Place < ' tcx > > ) ,
1605
1650
1606
1651
/// Encodes a user's type ascription. These need to be preserved
@@ -1615,6 +1660,10 @@ pub enum StatementKind<'tcx> {
1615
1660
/// - `Contravariant` -- requires that `T_y :> T`
1616
1661
/// - `Invariant` -- requires that `T_y == T`
1617
1662
/// - `Bivariant` -- no effect
1663
+ ///
1664
+ /// When executed at runtime this is a nop.
1665
+ ///
1666
+ /// Disallowed after drop elaboration.
1618
1667
AscribeUserType ( Box < ( Place < ' tcx > , UserTypeProjection ) > , ty:: Variance ) ,
1619
1668
1620
1669
/// Marks the start of a "coverage region", injected with '-Cinstrument-coverage'. A
@@ -1624,9 +1673,20 @@ pub enum StatementKind<'tcx> {
1624
1673
/// executed.
1625
1674
Coverage ( Box < Coverage > ) ,
1626
1675
1627
- /// Denotes a call to the intrinsic function copy_overlapping, where `src_dst` denotes the
1628
- /// memory being read from and written to(one field to save memory), and size
1629
- /// indicates how many bytes are being copied over.
1676
+ /// Denotes a call to the intrinsic function `copy_overlapping`.
1677
+ ///
1678
+ /// First, all three operands are evaluated. `src` and `dest` must each be a reference, pointer,
1679
+ /// or `Box` pointing to the same type `T`. `count` must evaluate to a `usize`. Then, `src` and
1680
+ /// `dest` are dereferenced, and `count * size_of::<T>()` bytes beginning with the first byte of
1681
+ /// the `src` place are copied to the continguous range of bytes beginning with the first byte
1682
+ /// of `dest`.
1683
+ ///
1684
+ /// **Needs clarification**: In what order are operands computed and dereferenced? It should
1685
+ /// probably match the order for assignment, but that is also undecided.
1686
+ ///
1687
+ /// **Needs clarification**: Is this typed or not, ie is there a place to value and back
1688
+ /// conversion involved? I vaguely remember Ralf saying somewhere that he thought it should not
1689
+ /// be.
1630
1690
CopyNonOverlapping ( Box < CopyNonOverlapping < ' tcx > > ) ,
1631
1691
1632
1692
/// No-op. Useful for deleting instructions without affecting statement indices.
0 commit comments