Skip to content

Commit 73a4e8d

Browse files
committed
apply various nits
1 parent 44e45d9 commit 73a4e8d

File tree

5 files changed

+46
-43
lines changed

5 files changed

+46
-43
lines changed

src/librustc/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ rustc_trans rustc_borrowck ... rustc_metadata
5757
syntax_pos syntax_ext
5858
```
5959
60-
61-
The idea is that `rustc_driver`, at the top of this lattice, basically
62-
defines the overall control-flow of the compiler. It doesn't have much
63-
"real code", but instead ties together all of the code defined in the
64-
other crates and defines the overall flow of execution.
60+
The `rustc_driver` crate, at the top of this lattice, is effectively
61+
the "main" function for the rust compiler. It doesn't have much "real
62+
code", but instead ties together all of the code defined in the other
63+
crates and defines the overall flow of execution. (As we transition
64+
more and more to the [query model](ty/maps/README.md), however, the
65+
"flow" of compilation is becoming less centrally defined.)
6566
6667
At the other extreme, the `rustc` crate defines the common and
6768
pervasive data structures that all the rest of the compiler uses

src/librustc/hir/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ The other reason to setup the representation this way is for better
4545
integration with incremental compilation. This way, if you gain access
4646
to a `&hir::Item` (e.g. for the mod `foo`), you do not immediately
4747
gain access to the contents of the function `bar()`. Instead, you only
48-
gain access to the **id** for `bar()`, and you must some function to
49-
lookup the contents of `bar()` given its id; this gives us a change to
50-
observe that you accessed the data for `bar()` and record the
51-
dependency.
48+
gain access to the **id** for `bar()`, and you must invoke some
49+
function to lookup the contents of `bar()` given its id; this gives us
50+
a chance to observe that you accessed the data for `bar()` and record
51+
the dependency.
5252

5353
### Identifiers in the HIR
5454

@@ -117,7 +117,3 @@ associated with an **owner**, which is typically some kind of item
117117
(e.g., `|x, y| x + y`). You can use the HIR map to find find the body
118118
associated with a given def-id (`maybe_body_owned_by()`) or to find
119119
the owner of a body (`body_owner_def_id()`).
120-
121-
122-
123-

src/librustc/hir/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ pub type CrateConfig = HirVec<P<MetaItem>>;
416416
/// The top-level data structure that stores the entire contents of
417417
/// the crate currently being compiled.
418418
///
419+
/// For more details, see [the module-level README](README.md).
419420
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)]
420421
pub struct Crate {
421422
pub module: Mod,
@@ -935,9 +936,9 @@ pub struct BodyId {
935936
/// (which is an expression), but also the argument patterns, since
936937
/// those are something that the caller doesn't really care about.
937938
///
938-
/// Example:
939+
/// # Examples
939940
///
940-
/// ```rust
941+
/// ```
941942
/// fn foo((x, y): (u32, u32)) -> u32 {
942943
/// x + y
943944
/// }

src/librustc/ty/README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tcx: TyCtxt<'a, 'gcx, 'tcx>
2121

2222
As you can see, the `TyCtxt` type takes three lifetime parameters.
2323
These lifetimes are perhaps the most complex thing to understand about
24-
the tcx. During rust compilation, we allocate most of our memory in
24+
the tcx. During Rust compilation, we allocate most of our memory in
2525
**arenas**, which are basically pools of memory that get freed all at
2626
once. When you see a reference with a lifetime like `'tcx` or `'gcx`,
2727
you know that it refers to arena-allocated data (or data that lives as
@@ -70,18 +70,24 @@ fn maybe_in_inference<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId
7070

7171
### Allocating and working with types
7272

73-
Rust types are represented using the `ty::Ty<'tcx>` type. This is in fact a simple type alias
74-
for a reference with `'tcx` lifetime:
73+
Rust types are represented using the `Ty<'tcx>` defined in the `ty`
74+
module (not to be confused with the `Ty` struct from [the HIR]). This
75+
is in fact a simple type alias for a reference with `'tcx` lifetime:
7576

7677
```rust
7778
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
7879
```
7980

80-
The `TyS` struct defines the actual details of how a type is
81-
represented. The most interesting part of it is the `sty` field, which
82-
contains an enum that lets us test what sort of type this is. For
83-
example, it is very common to see code that tests what sort of type you have
84-
that looks roughly like so:
81+
[the HIR]: ../hir/README.md
82+
83+
You can basically ignore the `TyS` struct -- you will basically never
84+
access it explicitly. We always pass it by reference using the
85+
`Ty<'tcx>` alias -- the only exception I think is to define inherent
86+
methods on types. Instances of `TyS` are only ever allocated in one of
87+
the rustc arenas (never e.g. on the stack).
88+
89+
One common operation on types is to **match** and see what kinds of
90+
types they are. This is done by doing `match ty.sty`, sort of like this:
8591

8692
```rust
8793
fn test_type<'tcx>(ty: Ty<'tcx>) {
@@ -92,10 +98,14 @@ fn test_type<'tcx>(ty: Ty<'tcx>) {
9298
}
9399
```
94100

95-
(Note though that doing such low-level tests on types during inference
96-
can be risky, as there are may be inference variables and other things
97-
to consider, or sometimes types are not yet known that will become
98-
known later.).
101+
The `sty` field (the origin of this name is unclear to me; perhaps
102+
structural type?) is of type `TypeVariants<'tcx>`, which is an enum
103+
definined all of the different kinds of types in the compiler.
104+
105+
> NB: inspecting the `sty` field on types during type inference can be
106+
> risky, as there are may be inference variables and other things to
107+
> consider, or sometimes types are not yet known that will become
108+
> known later.).
99109
100110
To allocate a new type, you can use the various `mk_` methods defined
101111
on the `tcx`. These have names that correpond mostly to the various kinds
@@ -114,13 +124,13 @@ any inference variables or other "temporary" types, they will be
114124
allocated in the global arena). However, the lifetime `'tcx` is always
115125
a safe approximation, so that is what you get back.
116126

117-
NB. Because types are interned, it is possible to compare them for
118-
equality efficiently using `==` -- however, this is almost never what
119-
you want to do unless you happen to be hashing and looking for
120-
duplicates. This is because often in Rust there are multiple ways to
121-
represent the same type, particularly once inference is involved. If
122-
you are going to be testing for type equality, you probably need to
123-
start looking into the inference code to do it right.
127+
> NB. Because types are interned, it is possible to compare them for
128+
> equality efficiently using `==` -- however, this is almost never what
129+
> you want to do unless you happen to be hashing and looking for
130+
> duplicates. This is because often in Rust there are multiple ways to
131+
> represent the same type, particularly once inference is involved. If
132+
> you are going to be testing for type equality, you probably need to
133+
> start looking into the inference code to do it right.
124134
125135
You can also find various common types in the tcx itself by accessing
126136
`tcx.types.bool`, `tcx.types.char`, etc (see `CommonTypes` for more).
@@ -153,7 +163,3 @@ In particular, since they are so common, the `Ty` and `TyCtxt` types
153163
are imported directly. Other types are often referenced with an
154164
explicit `ty::` prefix (e.g., `ty::TraitRef<'tcx>`). But some modules
155165
choose to import a larger or smaller set of names explicitly.
156-
157-
158-
159-

src/librustc/ty/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,10 @@ impl<'tcx> CommonTypes<'tcx> {
793793
}
794794
}
795795

796-
/// The central data structure of the compiler. Keeps track of all the
797-
/// information that typechecker generates so that so that it can be
798-
/// reused and doesn't have to be redone later on.
799-
///
800-
/// See [the README](README.md) for more deatils.
796+
/// The central data structure of the compiler. It stores references
797+
/// to the various **arenas** and also houses the results of the
798+
/// various **compiler queries** that have been performed. See [the
799+
/// README](README.md) for more deatils.
801800
#[derive(Copy, Clone)]
802801
pub struct TyCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
803802
gcx: &'a GlobalCtxt<'gcx>,

0 commit comments

Comments
 (0)