Skip to content

Commit 8bda557

Browse files
authored
Merge pull request #2 from nikomatsakis/ucg-1
[WIP] First status report for Unsafe Code Guidelines
2 parents 88ac262 + b2a7d4a commit 8bda557

File tree

1 file changed

+92
-0
lines changed
  • working-groups/unsafe-code-guidelines

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,95 @@
11
This file will contain summaries from the meetings where the
22
unsafe-code-guidelines WG synchronizes with the lang team and broader
33
community. That hasn't happened yet. =)
4+
5+
# First meeting agenda (Date TBD)
6+
7+
## Review of how UCG has operated thus far
8+
9+
- The UCG reference lives on the repository
10+
- At any given time we have an "active area of discussion":
11+
- This is proposed in a PR which describes an initial set of discussion topics
12+
([example](https://github.com/rust-lang/unsafe-code-guidelines/pull/54)).
13+
- When an issue seems to reach consensus, somebody writes up a
14+
summary in the form of a PR that edits the reference
15+
([example](https://github.com/rust-lang/unsafe-code-guidelines/pull/57)).
16+
- Sometimes, the consensus contains further points of contention
17+
-- in this case, we open up new issues representing just those
18+
points (and reference them from the reference).
19+
- Weekly meetings on Zulip; mostly try to look for issues that
20+
seem to have reached consensus and assign work, don't usually involve
21+
a lot of technical discussion.
22+
23+
Experience with this system? It seems to be working reasonably well,
24+
though we've not had as much participation as I had hoped, and we've
25+
been moving a bit slower than I might've thought. I think this is
26+
largely because these discussions are nobody's top priority right
27+
now. -nikomatsakis
28+
29+
## General roadmap
30+
31+
Our immediate goal is to produce an "RFC" covering two inter-related areas:
32+
33+
- [**Layout:**](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/active_discussion/layout.md)
34+
- What are the layout rules that unsafe code authors can rely on?
35+
- When do we guarantee ABI compatibility between Rust types and C types?
36+
- When can you rely on "enum layout" optimizations?
37+
- [**Validity invariants:**](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/active_discussion/validity.md)
38+
- Which invariants derived from types are there that the compiler
39+
expects to be always maintained, and (equivalently) that unsafe
40+
code must always uphold (or else cause undefined behavior)?
41+
42+
## Current status
43+
44+
We've finished up the **layout** conversation. Some of the key points:
45+
46+
- [Struct layout](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/structs-and-tuples.md)
47+
- The layout of tuples `(T1..Tn)` is defined "as if" there were a corresonding struct
48+
in libcore `struct TupleN<P1..Pn>(P1..Pn)`.
49+
- **cramertj notes:** sgrif and I have discussed lots of times
50+
that the easiest path towards variadic generics would preclude
51+
this, and I'd like to make sure we've fully evaluated that
52+
consequence.
53+
- The layout of (Rust) structs is generally undefined, but there are some open questions
54+
around possible exceptions:
55+
- [homogeneous structs](https://github.com/rust-lang/unsafe-code-guidelines/issues/36)
56+
- [single-field structs](https://github.com/rust-lang/unsafe-code-guidelines/issues/34)
57+
- [zero-sized structs](https://github.com/rust-lang/unsafe-code-guidelines/issues/37)
58+
- repr(C) structs are [laid out in a C-compatible
59+
fashion](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/structs-and-tuples.md#c-compatible-layout-repr-c),
60+
and we identified some subtle points around zero-sized types and
61+
C++ compatibility
62+
- [Enum layout](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/enums.md)
63+
- repr(C) enums were specified in [RFC 2195](https://rust-lang.github.io/rfcs/2195-really-tagged-unions.html)
64+
- We described a [conservative version of "discriminant
65+
elision"](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/enums.md#discriminant-elision-on-option-like-enums)
66+
-- aka, "the option optimization" -- that people can rely on
67+
- Layout of other enums is not defined
68+
- Unions tagged with `#[repr(C)]` behave like C unions. repr(rust)
69+
unions are not specified -- in particular, some of the fields may
70+
not be laid out at offset 0.
71+
- [Function
72+
pointers](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/function-pointers.md)
73+
are defined as being laid out the same way as their C counterparts,
74+
though they cannot be NULL.
75+
- [Integers and
76+
booleans](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/integers-floatingpoint.md)
77+
and [SIMD vector
78+
types](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/vectors.md)
79+
are basically defined as C compatible; we did not revisit the "great bool debate".
80+
- [References and raw
81+
pointers](https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/pointers.md)
82+
are largely specified as behaving as they do in rustc
83+
today. However, we do not specify the layout of `&dyn (Trait1 +
84+
Trait2)`, to leave room for multi-trait objects.
85+
86+
We are currently discussing **validity invariants**. Key points and
87+
open questions so far:
88+
89+
- XXX
90+
91+
## Points to consider and places for feedback
92+
93+
- What form should an RFC take here?
94+
- After validity invariants, what is a good next area for us to focus on?
95+

0 commit comments

Comments
 (0)