Skip to content

Commit f3f9bb6

Browse files
committed
Addressing aturon's nits
1 parent 97c3bee commit f3f9bb6

File tree

1 file changed

+27
-46
lines changed

1 file changed

+27
-46
lines changed

_posts/2017-06-08-Rust-1.18.md

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ appropriate page on our website, and check out the [detailed release notes for
2222

2323
### What's in 1.18.0 stable
2424

25-
Rust 1.18.0 is similar to many of our releases: no big surprises, just a number
26-
of improvements, cleanups, and new features.
25+
As usual, Rust 1.18.0 is a collection of improvements, cleanups, and new
26+
features.
2727

2828
One of the largest changes is a long time coming: core team members Carol
2929
Nichols and Steve Klabnik have been writing a new edition of "The Rust
@@ -35,11 +35,13 @@ edition in our online documentation](https://doc.rust-lang.org/stable/book/).
3535
1.19. When the book is done, a print version will be made available through [No
3636
Starch Press](https://www.nostarch.com/Rust), if you'd like a paper copy. We're
3737
still working with the editors at No Starch to improve the text, but we wanted
38-
to start getting a wider audience now. The new edition is a complete re-write
39-
from the ground up, using the last two years of knowledge we've gained from
40-
teaching people Rust. You'll find brand-new explanations for a lot of Rust's
41-
core concepts, new projects to build, and all kinds of other good stuff. Please
42-
check it out and [let us know what you think](https://github.com/rust-lang/book/issues/new)!
38+
to start getting a wider audience now.
39+
40+
The new edition is a complete re-write from the ground up, using the last two
41+
years of knowledge we've gained from teaching people Rust. You'll find
42+
brand-new explanations for a lot of Rust's core concepts, new projects to
43+
build, and all kinds of other good stuff. Please check it out and [let us know
44+
what you think](https://github.com/rust-lang/book/issues/new)!
4345

4446
As for the language itself, an old feature has learned some new tricks: the
4547
`pub` keyword has been expanded a bit. Experienced Rustaceans will know that
@@ -55,7 +57,8 @@ The bit inside of `()` is a 'restriction', which refines the notion of how this
5557
is made public. Using the `crate` keyword like the example above means that
5658
`bar` would be public to the entire crate, but not outside of it. This makes it
5759
easier to declare APIs that are "public to your crate", but not exposed to your
58-
users. This was *possible* with the current module system, but often very awkward.
60+
users. This was *possible* with the existing module system, but often very
61+
awkward.
5962

6063
You can also specify a path, like this:
6164

@@ -107,44 +110,22 @@ But what if our struct looked like this?
107110
struct Optimal(u8, u8, u16);
108111
```
109112

110-
This struct is properly aligned; the `u16` lies on a two byte boundary, and so does
111-
the entire struct. No padding is needed. This gives us `1 + 1 + 2 = 4 bytes`.
112-
113-
When designing Rust, stuff like this is why we left the details here undefined.
114-
It allows for exactly this kind of thing: the compiler can optimize `Suboptimal`
115-
into `Optimal` automatically. And if you check the sizes of `Suboptimal` and
116-
`Optimal` on Rust 1.18.0, you'll see that they both have a size of four bytes.
117-
118-
We've been planning this for a while; previous versions of Rust included this
119-
optimization on the nightly channel, but some people wrote unsafe code that
120-
assumed the exact details of the representation. We rolled it back while we fixed
121-
all instances of this that we know about, but if you find some code breaks due to
122-
this, you should fix it! In the meantime, there's also a flag you can use to control
123-
this. Imagine we have `Suboptimal` in a file named `foo.rs`, along with a `main`
124-
function that prints out its size:
125-
126-
```rust
127-
> rustc foo.rs
128-
> ./foo
129-
4
130-
> rustc foo.rs -Z fuel=foo=0
131-
optimization-fuel-exhausted: Reorder fields of "Suboptimal"
132-
> ./foo
133-
6
134-
```
135-
136-
This flag is based on an idea called "[Optimization
137-
fuel](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/07/dfopt-popl10.pdf)":
113+
This struct is properly aligned; the `u16` lies on a two byte boundary, and so
114+
does the entire struct. No padding is needed. This gives us `1 + 1 + 2 = 4
115+
bytes`.
138116

139-
> It works by giving the optimizer a finite supply of optimization fuel. Each
140-
> time a rewrite function proposes to replace a node, one unit of fuel is
141-
> consumed. When the optimizer runs out of fuel, further rewrites are
142-
> suppressed.
117+
When designing Rust, we left the details of memory layout undefined for just
118+
this reason. Because we didn't commit to a particular layout, we can make
119+
improvements to it, such as in this case where the compiler can optimize
120+
`Suboptimal` into `Optimal` automatically. And if you check the sizes of
121+
`Suboptimal` and `Optimal` on Rust 1.18.0, you'll see that they both have a
122+
size of four bytes.
143123

144-
Currently, this is the only optimization that uses the "fuel" concept. By
145-
setting the fuel to zero, `rustc` will not perform the optimization. This can
146-
keep your code compiling if you run into a problem, but the longer-term fix is
147-
to use a `#[repr]` attribute to guarantee a particular layout if you rely on it.
124+
We've been planning this change for a while; previous versions of Rust included
125+
this optimization on the nightly channel, but some people wrote unsafe code
126+
that assumed the exact details of the representation. We rolled it back while
127+
we fixed all instances of this that we know about, but if you find some code
128+
breaks due to this, please let us know so we can help fix it!
148129

149130
We've been planning on moving `rustdoc` to use a CommonMark compliant markdown
150131
parser for a long time now. However, just switching over can introduce
@@ -158,8 +139,8 @@ rendered results differ!
158139

159140
Finally, compiling `rustc` itself is now [15%-20%
160141
faster](https://github.com/rust-lang/rust/pull/41469). Each commit message in
161-
this PR goes over the details, but the short of it is that there were some
162-
inefficient things, and now they've been cleaned up.
142+
this PR goes over the details; there were some inefficiencies, and now they've
143+
been cleaned up.
163144

164145
See the [detailed release notes][notes] for more.
165146

0 commit comments

Comments
 (0)