Skip to content

Commit edb29ec

Browse files
committed
futz with headers more
1 parent 7d41c95 commit edb29ec

File tree

5 files changed

+61
-33
lines changed

5 files changed

+61
-33
lines changed

concurrency.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
% Concurrency and Paralellism
22

3-
```Not sure if I want this
4-
Safe Rust features *a ton* of tooling to make concurrency and parallelism totally
5-
safe, easy, and fearless. This is a case where we'll really just
6-
[defer to TRPL][trpl-conc] for the basics.
7-
8-
TL;DR: The `Send` and `Sync` traits in conjunction with Rust's ownership model and
9-
normal generic bounds make using concurrent APIs really easy and painless for
10-
a user of Safe Rust.
11-
```
123

13-
## Data Races and Race Conditions
4+
5+
# Data Races and Race Conditions
146

157
Safe Rust guarantees an absence of data races, which are defined as:
168

@@ -77,7 +69,10 @@ if idx.load(Ordering::SeqCst) < data.len() {
7769
}
7870
```
7971

80-
## Send and Sync
72+
73+
74+
75+
# Send and Sync
8176

8277
Not everything obeys inherited mutability, though. Some types allow you to multiply
8378
alias a location in memory while mutating it. Unless these types use synchronization
@@ -153,7 +148,10 @@ into the collection.
153148
TODO: better explain what can or can't be Send or Sync. Sufficient to appeal
154149
only to data races?
155150

156-
## Atomics
151+
152+
153+
154+
# Atomics
157155

158156
Rust pretty blatantly just inherits LLVM's model for atomics, which in turn is
159157
largely based off of the C11 model for atomics. This is not due these models
@@ -165,7 +163,10 @@ least, we can benefit from existing tooling and research around C's model.
165163
Trying to fully explain these models is fairly hopeless, so we're just going to
166164
drop that problem in LLVM's lap.
167165

168-
## Actually Doing Things Concurrently
166+
167+
168+
169+
# Actually Doing Things Concurrently
169170

170171
Rust as a language doesn't *really* have an opinion on how to do concurrency or
171172
parallelism. The standard library exposes OS threads and blocking sys-calls

data.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Low-level programming cares a lot about data layout. It's a big deal. It also pe
44
influences the rest of the language, so we're going to start by digging into how data is
55
represented in Rust.
66

7-
## The rust repr
7+
8+
9+
10+
# The rust repr
811

912
Rust gives you the following ways to lay out composite data:
1013

@@ -124,7 +127,7 @@ In principle enums can use fairly elaborate algorithms to cache bits throughout
124127
with special constrained representations. As such it is *especially* desirable that we leave
125128
enum layout unspecified today.
126129

127-
## Dynamically Sized Types (DSTs)
130+
# Dynamically Sized Types (DSTs)
128131

129132
Rust also supports types without a statically known size. On the surface,
130133
this is a bit nonsensical: Rust must know the size of something in order to
@@ -150,6 +153,9 @@ struct Foo {
150153
}
151154
```
152155

156+
157+
158+
153159
# Zero Sized Types (ZSTs)
154160

155161
Rust actually allows types to be specified that occupy *no* space:
@@ -182,6 +188,9 @@ consequence of types with no size. In particular, pointer offsets are no-ops, an
182188
standard allocators (including jemalloc, the one used by Rust) generally consider
183189
passing in `0` as Undefined Behaviour.
184190

191+
192+
193+
185194
# Drop Flags
186195

187196
For unfortunate legacy implementation reasons, Rust as of 1.0.0 will do a nasty trick to
@@ -212,12 +221,17 @@ struct Foo {
212221
For details as to *why* this is done, and how to make it not happen, check out
213222
[SOME OTHER SECTION].
214223

215-
## Alternative representations
224+
225+
226+
227+
# Alternative representations
216228

217229
Rust allows you to specify alternative data layout strategies from the default Rust
218230
one.
219231

220-
### repr(C)
232+
233+
234+
## repr(C)
221235

222236
This is the most important `repr`. It has fairly simple intent: do what C does.
223237
The order, size, and alignment of fields is exactly what you would expect from
@@ -241,14 +255,18 @@ still consumes a byte of space.
241255

242256
* This is equivalent to repr(u32) for enums (see below)
243257

244-
### repr(packed)
258+
259+
260+
## repr(packed)
245261

246262
`repr(packed)` forces rust to strip any padding it would normally apply.
247263
This may improve the memory footprint of a type, but will have negative
248264
side-effects from "field access is heavily penalized" to "completely breaks
249265
everything" based on target platform.
250266

251-
### repr(u8), repr(u16), repr(u32), repr(u64)
267+
268+
269+
## repr(u8), repr(u16), repr(u32), repr(u64)
252270

253271
These specify the size to make a c-like enum (one which has no values in its variants).
254272

intro.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Unsafe Rust. TURPL does not assume you have read TRPL, but does assume you know
77
the basics of the language and systems programming. We will not explain the
88
stack or heap, we will not explain the syntax.
99

10-
## Sections
10+
11+
12+
13+
# Sections
1114

1215
* [Data Layout](data.html)
1316
* [Ownership and Lifetimes](lifetimes.html)
@@ -16,7 +19,10 @@ stack or heap, we will not explain the syntax.
1619
* [Ownership-oriented resource management (RAII)](raii.html)
1720
* [Concurrency](concurrency.html)
1821

19-
## A Tale Of Two Languages
22+
23+
24+
25+
# A Tale Of Two Languages
2026

2127
Rust can be thought of as two different languages: Safe Rust, and Unsafe Rust.
2228
Any time someone opines the guarantees of Rust, they are almost surely talking about
@@ -60,7 +66,10 @@ The fact that Rust is written with a healthy spoonful of Unsafe Rust is no diffe
6066
However it *does* mean that Rust doesn't need to fall back to the pervasive unsafety of
6167
C to do the nasty things that need to get done.
6268

63-
## What does `unsafe` mean?
69+
70+
71+
72+
# What does `unsafe` mean?
6473

6574
Rust tries to model memory safety through the `unsafe` keyword. Interestingly,
6675
the meaning of `unsafe` largely revolves around what

lifetimes.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ language-design problem.
77

88

99

10-
## The Tagged Union Problem
10+
# The Tagged Union Problem
1111

1212
The core of the lifetime and mutability system derives from a simple problem:
1313
internal pointers to tagged unions. For instance, consider the following code:
@@ -68,7 +68,7 @@ For more details see Dan Grossman's Existential Types for Imperative Languages:
6868

6969

7070

71-
## Lifetimes
71+
# Lifetimes
7272

7373
Rust's static checks are managed by the *borrow checker* (borrowck), which tracks
7474
mutability and outstanding loans. This analysis can in principle be done without
@@ -101,7 +101,7 @@ more than a local lint against incorrect usage of a value.
101101

102102

103103

104-
## Weird Lifetimes
104+
# Weird Lifetimes
105105

106106
Given the following code:
107107

@@ -150,7 +150,7 @@ a bug.
150150

151151

152152

153-
## Lifetime Elision
153+
# Lifetime Elision
154154

155155
In order to make common patterns more ergonomic, Rust allows lifetimes to be
156156
*elided* in function, impl, and type signatures.
@@ -217,7 +217,7 @@ fn new<'a>(buf: &'a mut [u8]) -> BufWriter<'a> // expanded
217217

218218

219219

220-
## Unbounded Lifetimes
220+
# Unbounded Lifetimes
221221

222222
Unsafe code can often end up producing references or lifetimes out of thin air.
223223
Such lifetimes come into the world as *unbounded*. The most common source of this
@@ -258,7 +258,7 @@ these are unstable due to their awkward nature and questionable utility.
258258

259259

260260

261-
## Higher-Rank Lifetimes
261+
# Higher-Rank Lifetimes
262262

263263
Generics in Rust generally allow types to be instantiated with arbitrary
264264
associated lifetimes, but this fixes the lifetimes they work with once
@@ -328,7 +328,7 @@ maximally useful outside of the Fn traits.
328328

329329

330330

331-
## Subtyping and Variance
331+
# Subtyping and Variance
332332

333333
Although Rust doesn't have any notion of inheritance, it *does* include subtyping.
334334
In Rust, subtyping derives entirely from *lifetimes*. Since lifetimes are derived
@@ -474,7 +474,7 @@ struct Foo<'a, 'b, A, B, C, D, E, F, G, H> {
474474

475475

476476

477-
## PhantomData
477+
# PhantomData
478478

479479
When working with unsafe code, we can often end up in a situation where
480480
types or lifetimes are logically associated with a struct, but not actually
@@ -513,7 +513,7 @@ pub struct Iter<'a, T: 'a> {
513513

514514

515515

516-
## Dropck
516+
# Dropck
517517

518518
When a type is going out of scope, Rust will try to Drop it. Drop executes
519519
arbitrary code, and in fact allows us to "smuggle" arbitrary code execution
@@ -557,7 +557,7 @@ standard library made a utility for itself called `Unique<T>` which:
557557

558558

559559

560-
## Splitting Lifetimes
560+
# Splitting Lifetimes
561561

562562
The mutual exclusion property of mutable references can be very limiting when
563563
working with a composite structure. Borrowck understands some basic stuff, but

raii.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,4 @@ On balance this is an ok choice. Certainly if you're just getting started.
176176
In the future, we expect there to be a first-class way to announce that a field
177177
should be automatically dropped.
178178

179-
[uninit]:
179+
[uninit]: uninitialized.html

0 commit comments

Comments
 (0)