Skip to content

Commit 738567c

Browse files
authored
Merge pull request rust-lang#15 from Rust-zh/background
Sync with upstream. Background translated.
2 parents ceaa606 + 29515fa commit 738567c

28 files changed

+1791
-560
lines changed

ci/install.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ function cargo_install() {
2020
fi
2121
}
2222

23-
cargo_install mdbook 0.2.3
24-
cargo_install mdbook-linkcheck 0.2.3
23+
cargo_install mdbook 0.3.0
24+
cargo_install mdbook-linkcheck 0.3.0

src-zh/appendix/background.md

+95
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1+
<!--
12
# Appendix B: Background topics
3+
-->
24

5+
# 附录 B:背景话题
6+
7+
<!--
38
This section covers a numbers of common compiler terms that arise in
49
this guide. We try to give the general definition while providing some
510
Rust-specific context.
11+
-->
12+
13+
本节涵盖了本指南中出现的常见编译器术语。我们会在某些特定于 Rust
14+
的上下文中给出这些术语的一般定义。
615

716
<a name="cfg"></a>
817

18+
<!--
919
## What is a control-flow graph?
20+
-->
21+
22+
## 什么是控制流图?
1023

24+
<!--
1125
A control-flow graph is a common term from compilers. If you've ever
1226
used a flow-chart, then the concept of a control-flow graph will be
1327
pretty familiar to you. It's a representation of your program that
1428
exposes the underlying control flow in a very clear way.
29+
-->
1530

31+
控制流图(control-flow graph)是编译器中常见的术语。如果你曾使用过流程图,
32+
那么控制流图的概念对你来说会很熟悉。它是程序的一种表示方式,
33+
能够以非常清晰的方式展现底层控制流。
34+
35+
<!--
1636
A control-flow graph is structured as a set of **basic blocks**
1737
connected by edges. The key idea of a basic block is that it is a set
1838
of statements that execute "together" – that is, whenever you branch
1939
to a basic block, you start at the first statement and then execute
2040
all the remainder. Only at the end of the block is there the
2141
possibility of branching to more than one place (in MIR, we call that
2242
final statement the **terminator**):
43+
-->
44+
45+
控制流图由以边相连的一组**基本块(basic block)**构成。基本块的主要概念是
46+
一组「一起」执行的语句,也就是说,只要你的分支跳到了基本块,
47+
它就会从头到尾依次执行所有的语句。只有到基本块的最后才有可能分支到更多地方
48+
(在 MIR 中,我们将最后一条语句称作**终止句(terminator)**):
2349

2450
```mir
2551
bb0: {
@@ -31,8 +57,12 @@ bb0: {
3157
}
3258
```
3359

60+
<!--
3461
Many expressions that you are used to in Rust compile down to multiple
3562
basic blocks. For example, consider an if statement:
63+
-->
64+
65+
你在 Rust 中使用的很多表达式都会编译成多个基本块。例如,考虑以下 if 语句:
3666

3767
```rust,ignore
3868
a = 1;
@@ -44,7 +74,11 @@ if some_variable {
4474
d = 1;
4575
```
4676

77+
<!--
4778
This would compile into four basic blocks:
79+
-->
80+
81+
它会被编译成四个基本块
4882

4983
```mir
5084
BB0: {
@@ -68,39 +102,76 @@ BB3: {
68102
}
69103
```
70104

105+
<!--
71106
When using a control-flow graph, a loop simply appears as a cycle in
72107
the graph, and the `break` keyword translates into a path out of that
73108
cycle.
109+
-->
110+
111+
在使用控制流图时,循环会简单地作为一个图中的环路出现,而 `break`
112+
关键字则会被翻译成跳出此环路的一条路径。
74113

75114
<a name="dataflow"></a>
76115

116+
<!--
77117
## What is a dataflow analysis?
118+
-->
78119

120+
## 什么是数据流分析?
121+
122+
<!--
79123
[*Static Program Analysis*](https://cs.au.dk/~amoeller/spa/) by Anders Møller
80124
and Michael I. Schwartzbach is an incredible resource!
125+
-->
126+
127+
[**静态程序分析(Static Program Analysis)**](https://cs.au.dk/~amoeller/spa/)
128+
作者 Anders Møller 和 Michael I. Schwartzbach,它是一个绝佳的资源。
81129

82130
*to be written*
83131

84132
<a name="quantified"></a>
85133

134+
<!--
86135
## What is "universally quantified"? What about "existentially quantified"?
136+
-->
137+
138+
## 什么是「全称量化」?「存在量化」呢?
87139

88140
*to be written*
89141

90142
<a name="variance"></a>
91143

144+
<!--
92145
## What is co- and contra-variance?
146+
-->
147+
148+
## 什么是协变和逆变?
93149

150+
<!--
94151
Check out the subtyping chapter from the
95152
[Rust Nomicon](https://doc.rust-lang.org/nomicon/subtyping.html).
153+
-->
154+
155+
详见 [Rust 秘典](https://doc.rust-lang.org/nomicon/subtyping.html)
156+
中的子定型(Subtyping)一章。
96157

158+
<!--
97159
See the [variance](../variance.html) chapter of this guide for more info on how
98160
the type checker handles variance.
161+
-->
162+
163+
关于类型检查器如何处理型变的更多信息见本指南的
164+
[型变(variance)](../variance.html)一章。
99165

100166
<a name="free-vs-bound"></a>
101167

168+
<!--
102169
## What is a "free region" or a "free variable"? What about "bound region"?
170+
-->
171+
172+
## 什么是「自由生存域」和「自由变量」?「约束生存域」呢?
103173

174+
<!--
104175
Let's describe the concepts of free vs bound in terms of program
105176
variables, since that's the thing we're most familiar with.
106177
@@ -115,14 +186,38 @@ variables, since that's the thing we're most familiar with.
115186
refer to local variables that are defined *outside* of the
116187
expression. We say that those variables **appear free** in the
117188
expression (i.e., they are **free**, not **bound** (tied up)).
189+
-->
118190

191+
我们来描述一下程序变量的自由和约束的概念,因为它们是我们最熟悉的概念。
192+
193+
- 考虑此表达式,它创建了一个闭包:`|a, b| a + b`。在这里,`a + b` 中的 `a`
194+
`b` 指代该闭包被调用会时传入的参数。我们称 `a``b` 在该闭包中是
195+
**被约束(bound)**的,而闭包签名 `|a, b|` 是名字 `a``b`**约束位(binder)**
196+
(因为对 `a``b` 的任何引用都是指代它引入的变量)。
197+
198+
- 考虑此表达式 `a + b`。在该表达式中,`a``b` 均指代定义在该表达式**之外**
199+
的局部变量。我们称这些变量在该表达式中**自由出现(appear free)**
200+
(即它们是**自由(free)**的,而非**被约束(bound)**的(被束缚的))。
201+
202+
<!--
119203
So there you have it: a variable "appears free" in some
120204
expression/statement/whatever if it refers to something defined
121205
outside of that expressions/statement/whatever. Equivalently, we can
122206
then refer to the "free variables" of an expression – which is just
123207
the set of variables that "appear free".
208+
-->
124209

210+
所以现在你理解了:在某些「表达式、语句、还是别的什么」中的变量,
211+
如果指代的是定义在该「表达式、语句、还是别的什么」之外的东西,那么它们就是
212+
「自由出现」的。我们可以等价地称之为表达式中的「自由变量」,
213+
毕竟它们就是一组「自由出现」的变量而已。
214+
215+
<!--
125216
So what does this have to do with regions? Well, we can apply the
126217
analogous concept to type and regions. For example, in the type `&'a
127218
u32`, `'a` appears free. But in the type `for<'a> fn(&'a u32)`, it
128219
does not.
220+
-->
221+
222+
那么,它们与生存域(region)有什么关系呢?我们可以将类似的概念应用到类型和生存域上来。
223+
例如,在类型 `&'a u32` 中,`'a` 是自由出现的。但在类型 `for<'a> fn(&'a u32)` 中则不是。

src/SUMMARY.md

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [The HIR (High-level IR)](./hir.md)
4040
- [Lowering AST to HIR](./lowering.md)
4141
- [Debugging](./hir-debugging.md)
42+
- [Closure expansion](./closure.md)
4243
- [The `ty` module: representing types](./ty.md)
4344
- [Kinds](./kinds.md)
4445
- [Type inference](./type-inference.md)
@@ -75,6 +76,12 @@
7576
- [Move paths](./borrow_check/moves_and_initialization/move_paths.md)
7677
- [MIR type checker](./borrow_check/type_check.md)
7778
- [Region inference](./borrow_check/region_inference.md)
79+
- [Constraint propagation](./borrow_check/region_inference/constraint_propagation.md)
80+
- [Lifetime parameters](./borrow_check/region_inference/lifetime_parameters.md)
81+
- [Member constraints](./borrow_check/region_inference/member_constraints.md)
82+
- [Placeholders and universes][pau]
83+
- [Closure constraints](./borrow_check/region_inference/closure_constraints.md)
84+
- [Errror reporting](./borrow_check/region_inference/error_reporting.md)
7885
- [Two-phase-borrows](./borrow_check/two_phase_borrows.md)
7986
- [Constant evaluation](./const-eval.md)
8087
- [miri const evaluator](./miri.md)
@@ -83,11 +90,15 @@
8390
- [Updating LLVM](./codegen/updating-llvm.md)
8491
- [Debugging LLVM](./codegen/debugging.md)
8592
- [Profile-guided Optimization](./profile-guided-optimization.md)
93+
- [Debugging Support in Rust Compiler](./debugging-support-in-rustc.md)
8694

8795
---
8896

8997
[Appendix A: Stupid Stats](./appendix/stupid-stats.md)
9098
[Appendix B: Background material](./appendix/background.md)
9199
[Appendix C: Glossary](./appendix/glossary.md)
92100
[Appendix D: Code Index](./appendix/code-index.md)
101+
[Appendix E: Bibliography](./appendix/bibliography.md)
93102
[](./important-links.md)
103+
104+
[pau]: ./borrow_check/region_inference/placeholders_and_universes.md

src/appendix/bibliography.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Rust Bibliography
2+
3+
This is a reading list of material relevant to Rust. It includes prior
4+
research that has - at one time or another - influenced the design of
5+
Rust, as well as publications about Rust.
6+
7+
## Type system
8+
9+
* [Region based memory management in Cyclone](https://www.cs.umd.edu/projects/cyclone/papers/cyclone-regions.pdf)
10+
* [Safe manual memory management in Cyclone](http://www.cs.umd.edu/projects/PL/cyclone/scp.pdf)
11+
* [Typeclasses: making ad-hoc polymorphism less ad hoc](http://www.ps.uni-sb.de/courses/typen-ws99/class.ps.gz)
12+
* [Macros that work together](https://www.cs.utah.edu/plt/publications/jfp12-draft-fcdf.pdf)
13+
* [Traits: composable units of behavior](http://scg.unibe.ch/archive/papers/Scha03aTraits.pdf)
14+
* [Alias burying](http://www.cs.uwm.edu/faculty/boyland/papers/unique-preprint.ps) - We tried something similar and abandoned it.
15+
* [External uniqueness is unique enough](http://www.cs.uu.nl/research/techreps/UU-CS-2002-048.html)
16+
* [Uniqueness and Reference Immutability for Safe Parallelism](https://research.microsoft.com/pubs/170528/msr-tr-2012-79.pdf)
17+
* [Region Based Memory Management](http://www.cs.ucla.edu/~palsberg/tba/papers/tofte-talpin-iandc97.pdf)
18+
19+
## Concurrency
20+
21+
* [Singularity: rethinking the software stack](https://research.microsoft.com/pubs/69431/osr2007_rethinkingsoftwarestack.pdf)
22+
* [Language support for fast and reliable message passing in singularity OS](https://research.microsoft.com/pubs/67482/singsharp.pdf)
23+
* [Scheduling multithreaded computations by work stealing](http://supertech.csail.mit.edu/papers/steal.pdf)
24+
* [Thread scheduling for multiprogramming multiprocessors](http://www.eecis.udel.edu/%7Ecavazos/cisc879-spring2008/papers/arora98thread.pdf)
25+
* [The data locality of work stealing](http://www.aladdin.cs.cmu.edu/papers/pdfs/y2000/locality_spaa00.pdf)
26+
* [Dynamic circular work stealing deque](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.170.1097&rep=rep1&type=pdf) - The Chase/Lev deque
27+
* [Work-first and help-first scheduling policies for async-finish task parallelism](http://www.cs.rice.edu/%7Eyguo/pubs/PID824943.pdf) - More general than fully-strict work stealing
28+
* [A Java fork/join calamity](http://www.coopsoft.com/ar/CalamityArticle.html) - critique of Java's fork/join library, particularly its application of work stealing to non-strict computation
29+
* [Scheduling techniques for concurrent systems](http://www.stanford.edu/~ouster/cgi-bin/papers/coscheduling.pdf)
30+
* [Contention aware scheduling](http://www.blagodurov.net/files/a8-blagodurov.pdf)
31+
* [Balanced work stealing for time-sharing multicores](http://www.cse.ohio-state.edu/hpcs/WWW/HTML/publications/papers/TR-12-1.pdf)
32+
* [Three layer cake for shared-memory programming](http://dl.acm.org/citation.cfm?id=1953616&dl=ACM&coll=DL&CFID=524387192&CFTOKEN=44362705)
33+
* [Non-blocking steal-half work queues](http://www.cs.bgu.ac.il/%7Ehendlerd/papers/p280-hendler.pdf)
34+
* [Reagents: expressing and composing fine-grained concurrency](http://aturon.github.io/academic/reagents.pdf)
35+
* [Algorithms for scalable synchronization of shared-memory multiprocessors](https://www.cs.rochester.edu/u/scott/papers/1991_TOCS_synch.pdf)
36+
* [Epoch-based reclamation](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-579.pdf).
37+
38+
## Others
39+
40+
* [Crash-only software](https://www.usenix.org/legacy/events/hotos03/tech/full_papers/candea/candea.pdf)
41+
* [Composing High-Performance Memory Allocators](http://people.cs.umass.edu/~emery/pubs/berger-pldi2001.pdf)
42+
* [Reconsidering Custom Memory Allocation](http://people.cs.umass.edu/~emery/pubs/berger-oopsla2002.pdf)
43+
44+
## Papers *about* Rust
45+
46+
* [GPU Programming in Rust: Implementing High Level Abstractions in a Systems
47+
Level
48+
Language](https://www.cs.indiana.edu/~achauhan/Publications/Pubs/2013-hips-holk-rust.pdf).
49+
Early GPU work by Eric Holk.
50+
* [Parallel closures: a new twist on an old
51+
idea](https://www.usenix.org/conference/hotpar12/parallel-closures-new-twist-old-idea)
52+
- not exactly about Rust, but by nmatsakis
53+
* [Patina: A Formalization of the Rust Programming
54+
Language](http://dada.cs.washington.edu/research/tr/2015/03/UW-CSE-15-03-02.pdf).
55+
Early formalization of a subset of the type system, by Eric Reed.
56+
* [Experience Report: Developing the Servo Web Browser Engine using
57+
Rust](http://arxiv.org/abs/1505.07383). By Lars Bergstrom.
58+
* [Implementing a Generic Radix Trie in
59+
Rust](https://michaelsproul.github.io/rust_radix_paper/rust-radix-sproul.pdf). Undergrad
60+
paper by Michael Sproul.
61+
* [Reenix: Implementing a Unix-Like Operating System in
62+
Rust](http://scialex.github.io/reenix.pdf). Undergrad paper by Alex
63+
Light.
64+
* [Evaluation of performance and productivity metrics of potential programming languages in the HPC environment](http://octarineparrot.com/assets/mrfloya-thesis-ba.pdf).
65+
Bachelor's thesis by Florian Wilkens. Compares C, Go and Rust.
66+
* [Nom, a byte oriented, streaming, zero copy, parser combinators library
67+
in Rust](http://spw15.langsec.org/papers/couprie-nom.pdf). By
68+
Geoffroy Couprie, research for VLC.
69+
* [Graph-Based Higher-Order Intermediate
70+
Representation](http://compilers.cs.uni-saarland.de/papers/lkh15_cgo.pdf). An
71+
experimental IR implemented in Impala, a Rust-like language.
72+
* [Code Refinement of Stencil
73+
Codes](http://compilers.cs.uni-saarland.de/papers/ppl14_web.pdf). Another
74+
paper using Impala.
75+
* [Parallelization in Rust with fork-join and
76+
friends](http://publications.lib.chalmers.se/records/fulltext/219016/219016.pdf). Linus
77+
Farnstrand's master's thesis.
78+
* [Session Types for
79+
Rust](http://munksgaard.me/papers/laumann-munksgaard-larsen.pdf). Philip
80+
Munksgaard's master's thesis. Research for Servo.
81+
* [Ownership is Theft: Experiences Building an Embedded OS in Rust - Amit Levy, et. al.](http://amitlevy.com/papers/tock-plos2015.pdf)
82+
* [You can't spell trust without Rust](https://raw.githubusercontent.com/Gankro/thesis/master/thesis.pdf). Alexis Beingessner's master's thesis.
83+
* [Rust-Bio: a fast and safe bioinformatics library](http://bioinformatics.oxfordjournals.org/content/early/2015/10/06/bioinformatics.btv573). Johannes Köster
84+
* [Safe, Correct, and Fast Low-Level Networking](https://octarineparrot.com/assets/msci_paper.pdf). Robert Clipsham's master's thesis.
85+
* [Formalizing Rust traits](http://hdl.handle.net/2429/55609). Jonatan Milewski's master's thesis.
86+
* [Rust as a Language for High Performance GC Implementation](http://users.cecs.anu.edu.au/~steveb/downloads/pdf/rust-ismm-2016.pdf)
87+
* [Simple Verification of Rust Programs via Functional Purification](https://github.com/Kha/electrolysis). Sebastian Ullrich's master's thesis.
88+
* [Writing parsers like it is 2017](http://spw17.langsec.org/papers/chifflier-parsing-in-2017.pdf) Pierre Chifflier and Geoffroy Couprie for the Langsec Workshop
89+
* [The Case for Writing a Kernel in Rust](https://www.tockos.org/assets/papers/rust-kernel-apsys2017.pdf)
90+
* [RustBelt: Securing the Foundations of the Rust Programming Language](https://plv.mpi-sws.org/rustbelt/popl18/)

src/appendix/code-index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Item | Kind | Short description | Chapter |
2929
`TraitDef` | struct | This struct contains a trait's definition with type information | [The `ty` modules] | [src/librustc/ty/trait_def.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/trait_def/struct.TraitDef.html)
3030
`TraitRef` | struct | The combination of a trait and its input types (e.g. `P0: Trait<P1...Pn>`) | [Trait Solving: Goals and Clauses], [Trait Solving: Lowering impls] | [src/librustc/ty/sty.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TraitRef.html)
3131
`Ty<'tcx>` | struct | This is the internal representation of a type used for type checking | [Type checking] | [src/librustc/ty/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/type.Ty.html)
32-
`TyCtxt<'cx, 'tcx, 'tcx>` | struct | The "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queries | [The `ty` modules] | [src/librustc/ty/context.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html)
32+
`TyCtxt<'tcx>` | struct | The "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queries | [The `ty` modules] | [src/librustc/ty/context.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html)
3333

3434
[The HIR]: ../hir.html
3535
[Identifiers in the HIR]: ../hir.html#hir-id

0 commit comments

Comments
 (0)