Skip to content

Commit a7c2365

Browse files
oli-obkmark-i-m
authored andcommitted
Link to docs and address some review comments
1 parent 80b656f commit a7c2365

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/mir/construction.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,22 @@ list of items:
1111
* Drop code (the `Drop::drop` function is not called directly)
1212
* Drop implementations of types without an explicit `Drop` implementation
1313

14-
The lowering is triggered by calling the `mir_built` query. The entire lowering
15-
code lives in `src/librustc_mir/build`. There is an intermediate representation
16-
between [HIR] and [MIR] called the `HAIR` that is only used during the lowering.
17-
The `HAIR` has datatypes that mirror the [HIR] datatypes, but instead of e.g. `-x`
14+
The lowering is triggered by calling the [`mir_built`] query.
15+
There is an intermediate representation
16+
between [HIR] and [MIR] called the [HAIR] that is only used during the lowering.
17+
The [HAIR]'s most important feature is that the various adjustments that happen
18+
without explicit syntax (coercion, autoderef, autoref, ...) have become explicit
19+
casts, deref operations or reference expressions.
20+
21+
The [HAIR] has datatypes that mirror the [HIR] datatypes, but instead of e.g. `-x`
1822
being a `hair::ExprKind::Neg(hair::Expr)` it is a `hair::ExprKind::Neg(hir::Expr)`.
19-
2023
This shallowness enables the `HAIR` to represent all datatypes that [HIR] has, but
21-
without having to create an in-memory copy of the entire [HIR]. The `HAIR` also
24+
without having to create an in-memory copy of the entire [HIR]. The [HAIR] also
2225
does a few simplifications, e.g. method calls and function calls have been merged
23-
into a single variant.
26+
into a single variant. [MIR] lowering will first convert the topmost expression from
27+
[HIR] to [HAIR] (in
28+
[https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/hair/cx/expr/index.html])
29+
and then process the [HAIR] expressions recursively.
2430

2531
The lowering creates local variables for every argument as specified in the signature.
2632
Next it creates local variables for every binding specified (e.g. `(a, b): (i32, String)`)
@@ -35,7 +41,7 @@ writes the result into the `RETURN_PLACE`.
3541
## `unpack!` all the things
3642

3743
One important thing of note is the `unpack!` macro, which accompanies all recursive
38-
calls. The macro ensures, that you get the result of the recursive call while updating
44+
calls. The macro ensures that you get the result of the recursive call while updating
3945
the basic block that you are now in. As an example: lowering `a + b` will need to do
4046
three somewhat independent things:
4147

@@ -108,4 +114,6 @@ statement per aggregate field plus an assignment to the discriminant in the
108114
case of `enum`s.
109115

110116
[MIR]: ./index.html
111-
[HIR]: ../hir.html
117+
[HIR]: ../hir.html
118+
[HAIR]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/hair/index.html
119+
[`mir_built`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/fn.mir_built.html

0 commit comments

Comments
 (0)