Commit bc9101e
authored
#### Context
Motivated by
[iterator-simple-fail.rs](https://github.com/runtimeverification/mir-semantics/blob/3d763c00389dcdb45a68523d6515c6d6fc8b2928/kmir/src/tests/integration/data/prove-rs/iterator-simple-fail.rs#L1-L7)
(which should pass).
The type
[std::mem::MaybeUninit](https://doc.rust-lang.org/std/mem/union.MaybeUninit.html)
is a union that represents a potentially uninitialised location in
memory. This union has two fields, first `()`, and second
[std::mem::ManuallyDrop<T>](https://doc.rust-lang.org/std/mem/struct.ManuallyDrop.html)
which represents the initialised data. When [converting an array to an
iterator](https://github.com/rust-lang/rust/blob/a2545fd6fc66b4323f555223a860c451885d1d2b/library/core/src/array/iter.rs#L57-L70)
a `Transmute` cast is invoked for the array element type (`T` from `[T;
N]`) into `std::mem::MaybeUninit<T>`.
#### This PR
This PR implements the cast `CastKind::Transmute` of `T` into
`std::mem:MaybeUninit<T>`.
The logic of the semantics and saftey of this cast for us is:
- that there is a `Value` to be cast as we cannot construct a `Value`
that is not initialised;
- that the type being cast from `T` is the same as the type of the
unions second field `std::mem::ManuallyDrop<T>`;
- we can then then create a union that is constructed with the second
field, instantiating the `Value` in a struct;
- otherwise we error so that the cast does not `thunk`.
Tests are added to show the passing cases for `transmute` and
`transmute_unchecked`, and the failing case where the types are not
valid for the transmute as explained above.
A follow up PR will handle converting the elements of the array when an
array, this PR is just for a single element.
1 parent b4182cd commit bc9101e
File tree
7 files changed
+113
-6
lines changed- kmir/src
- kmir/kdist/mir-semantics/rt
- tests/integration
- data/prove-rs
- show
7 files changed
+113
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1017 | 1017 | | |
1018 | 1018 | | |
1019 | 1019 | | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
1020 | 1026 | | |
1021 | 1027 | | |
1022 | 1028 | | |
| |||
1628 | 1634 | | |
1629 | 1635 | | |
1630 | 1636 | | |
1631 | | - | |
1632 | | - | |
| 1637 | + | |
1633 | 1638 | | |
1634 | 1639 | | |
1635 | 1640 | | |
| |||
1664 | 1669 | | |
1665 | 1670 | | |
1666 | 1671 | | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
1667 | 1705 | | |
1668 | 1706 | | |
1669 | 1707 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
123 | 144 | | |
| 145 | + | |
| 146 | + | |
124 | 147 | | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
128 | | - | |
| 151 | + | |
129 | 152 | | |
130 | 153 | | |
131 | 154 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
0 commit comments