Apply suggestions from code review
Co-authored-by: Camelid <camelidcamel@gmail.com>
This commit is contained in:
parent
d29b1c39cb
commit
9692e9e9a1
17
src/thir.md
17
src/thir.md
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<!-- toc -->
|
<!-- toc -->
|
||||||
|
|
||||||
The THIR ("Typed High-Level Intermediate Representation"), previously HAIR for
|
The THIR ("Typed High-Level Intermediate Representation"), previously called HAIR for
|
||||||
"High-Level Abstract IR", is another IR used by rustc that is generated after
|
"High-Level Abstract IR", is another IR used by rustc that is generated after
|
||||||
[type checking]. It is (as of <!-- date: 2021-03 --> March 2021) only used for
|
[type checking]. It is (as of <!-- date: 2021-03 --> March 2021) only used for
|
||||||
[MIR construction] and [exhaustiveness checking], but
|
[MIR construction] and [exhaustiveness checking], but
|
||||||
|
|
@ -16,14 +16,17 @@ for the current MIR unsafety checker.
|
||||||
|
|
||||||
As the name might suggest, the THIR is a lowered version of the [HIR] where all
|
As the name might suggest, the THIR is a lowered version of the [HIR] where all
|
||||||
the types have been filled in, which is possible after type checking has completed.
|
the types have been filled in, which is possible after type checking has completed.
|
||||||
But it has some other interesting features that distinguish it from HIR:
|
But it has some other interesting features that distinguish it from the HIR:
|
||||||
- like the MIR, the THIR only represents bodies, i.e. "executable code"; this includes
|
|
||||||
|
- Like the MIR, the THIR only represents bodies, i.e. "executable code"; this includes
|
||||||
function bodies, but also `const` initializers, for example. Consequently, the THIR
|
function bodies, but also `const` initializers, for example. Consequently, the THIR
|
||||||
has no representation for items like `struct`s or `trait`s.
|
has no representation for items like `struct`s or `trait`s.
|
||||||
- a body of THIR is only stored temporarily and is dropped as soon as it's no longer
|
|
||||||
|
- Each body of THIR is only stored temporarily and is dropped as soon as it's no longer
|
||||||
needed, as opposed to being stored until the end of the compilation process (which
|
needed, as opposed to being stored until the end of the compilation process (which
|
||||||
is what is done with the HIR).
|
is what is done with the HIR).
|
||||||
- besides making the types of all nodes available, the THIR also has additional
|
|
||||||
|
- Besides making the types of all nodes available, the THIR also has additional
|
||||||
desugaring compared to the HIR. For example, automatic references and dereferences
|
desugaring compared to the HIR. For example, automatic references and dereferences
|
||||||
are made explicit, and method calls and overloaded operators are converted into
|
are made explicit, and method calls and overloaded operators are converted into
|
||||||
plain function calls. Destruction scopes are also made explicit.
|
plain function calls. Destruction scopes are also made explicit.
|
||||||
|
|
@ -32,8 +35,8 @@ But it has some other interesting features that distinguish it from HIR:
|
||||||
|
|
||||||
The THIR lives in [`rustc_mir_build::thir`][thir]. To construct a `thir::Expr`,
|
The THIR lives in [`rustc_mir_build::thir`][thir]. To construct a `thir::Expr`,
|
||||||
you can use the `build_thir` function, passing in the memory arena where the THIR
|
you can use the `build_thir` function, passing in the memory arena where the THIR
|
||||||
will be allocated. Dropping this arena will result in the THIR being destroyed:
|
will be allocated. Dropping this arena will result in the THIR being destroyed,
|
||||||
this is useful to keep peak memory in check, as having a THIR representation of
|
which is useful to keep peak memory in check. Having a THIR representation of
|
||||||
all bodies of a crate in memory at the same time would be very heavy.
|
all bodies of a crate in memory at the same time would be very heavy.
|
||||||
|
|
||||||
[thir]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/index.html
|
[thir]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/index.html
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue