-
Notifications
You must be signed in to change notification settings - Fork 547
Add stub about the THIR #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add stub about the THIR #1076
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# The THIR | ||
|
||
<!-- toc --> | ||
|
||
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 | ||
[type checking]. It is (as of <!-- date: 2021-03 --> March 2021) only used for | ||
[MIR construction] and [exhaustiveness checking], but | ||
[it may also soon be used for unsafety checking][thir-unsafeck] as a replacement | ||
for the current MIR unsafety checker. | ||
|
||
[type checking]: ./type-checking.md | ||
[MIR construction]: ./mir/construction.md | ||
[exhaustiveness checking]: ./pat-exhaustive-checking.md | ||
[thir-unsafeck]: https://github.com/rust-lang/compiler-team/issues/402 | ||
|
||
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. | ||
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 | ||
function bodies, but also `const` initializers, for example. Consequently, the THIR | ||
has no representation for items like `struct`s or `trait`s. | ||
|
||
- 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 | ||
is what is done with the HIR). | ||
|
||
- Besides making the types of all nodes available, the THIR also has additional | ||
desugaring compared to the HIR. For example, automatic references and dereferences | ||
are made explicit, and method calls and overloaded operators are converted into | ||
plain function calls. Destruction scopes are also made explicit. | ||
|
||
[HIR]: ./hir.md | ||
|
||
The THIR lives in [`rustc_mir_build::thir`][thir-docs]. To construct a [`thir::Expr`], | ||
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, | ||
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. | ||
|
||
[thir-docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/index.html | ||
[`thir::Expr`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/struct.Expr.html | ||
[`build_thir`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/fn.build_thir.html |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.