2
2
3
3
<!-- toc -->
4
4
5
- The THIR ("Typed High-Level Intermediate Representation"), previously HAIR for
5
+ The THIR ("Typed High-Level Intermediate Representation"), previously called HAIR for
6
6
"High-Level Abstract IR", is another IR used by rustc that is generated after
7
7
[ type checking] . It is (as of <!-- date: 2021-03 --> March 2021) only used for
8
8
[ MIR construction] and [ exhaustiveness checking] , but
@@ -16,14 +16,17 @@ for the current MIR unsafety checker.
16
16
17
17
As the name might suggest, the THIR is a lowered version of the [ HIR] where all
18
18
the types have been filled in, which is possible after type checking has completed.
19
- But it has some other interesting features that distinguish it from HIR:
20
- - like the MIR, the THIR only represents bodies, i.e. "executable code"; this includes
19
+ But it has some other interesting features that distinguish it from the HIR:
20
+
21
+ - Like the MIR, the THIR only represents bodies, i.e. "executable code"; this includes
21
22
function bodies, but also ` const ` initializers, for example. Consequently, the THIR
22
23
has no representation for items like ` struct ` s or ` trait ` s.
23
- - a body of THIR is only stored temporarily and is dropped as soon as it's no longer
24
+
25
+ - Each body of THIR is only stored temporarily and is dropped as soon as it's no longer
24
26
needed, as opposed to being stored until the end of the compilation process (which
25
27
is what is done with the HIR).
26
- - besides making the types of all nodes available, the THIR also has additional
28
+
29
+ - Besides making the types of all nodes available, the THIR also has additional
27
30
desugaring compared to the HIR. For example, automatic references and dereferences
28
31
are made explicit, and method calls and overloaded operators are converted into
29
32
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:
32
35
33
36
The THIR lives in [ ` rustc_mir_build::thir ` ] [ thir ] . To construct a ` thir::Expr ` ,
34
37
you can use the ` build_thir ` function, passing in the memory arena where the THIR
35
- will be allocated. Dropping this arena will result in the THIR being destroyed:
36
- this is useful to keep peak memory in check, as having a THIR representation of
38
+ will be allocated. Dropping this arena will result in the THIR being destroyed,
39
+ which is useful to keep peak memory in check. Having a THIR representation of
37
40
all bodies of a crate in memory at the same time would be very heavy.
38
41
39
42
[ thir ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/index.html
0 commit comments