Skip to content

Rename HAIR to THIR #818

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 2 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
- [Lowering AST to HIR](./lowering.md)
- [Debugging](./hir-debugging.md)
- [The MIR (Mid-level IR)](./mir/index.md)
- [HAIR and MIR construction](./mir/construction.md)
- [THIR and MIR construction](./mir/construction.md)
- [MIR visitor and traversal](./mir/visitor.md)
- [MIR passes: getting the MIR for a function](./mir/passes.md)
- [Closure expansion](./closure.md)
Expand Down
2 changes: 1 addition & 1 deletion src/borrow_check/two_phase_borrows.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The activation points are found using the [`GatherBorrows`] visitor. The
borrow.

[`AutoBorrow`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adjustment/enum.AutoBorrow.html
[converted]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/hair/cx/expr/trait.ToBorrowKind.html#method.to_borrow_kind
[converted]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/cx/expr/trait.ToBorrowKind.html#method.to_borrow_kind
[`BorrowKind`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BorrowKind.html
[`GatherBorrows`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/visit/trait.Visitor.html#method.visit_local
[`BorrowData`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/borrow_check/borrow_set/struct.BorrowData.html
Expand Down
20 changes: 10 additions & 10 deletions src/mir/construction.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# HAIR and MIR construction
# THIR and MIR construction

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a note that THIR used to be called HAIR? That way people that come across comments or old discussions have some context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Addressed via 19832d5.

The lowering of [HIR] to [MIR] occurs for the following (probably incomplete)
list of items:
Expand All @@ -13,19 +13,19 @@ list of items:

The lowering is triggered by calling the [`mir_built`] query.
There is an intermediate representation
between [HIR] and [MIR] called the [HAIR] that is only used during the lowering.
The [HAIR]'s most important feature is that the various adjustments (which happen
between [HIR] and [MIR] called the [THIR] that is only used during the lowering.
The [THIR]'s most important feature is that the various adjustments (which happen
without explicit syntax) like coercions, autoderef, autoref and overloaded method
calls have become explicit casts, deref operations, reference expressions or
concrete function calls.

The [HAIR] has datatypes that mirror the [HIR] datatypes, but instead of e.g. `-x`
being a `hair::ExprKind::Neg(hair::Expr)` it is a `hair::ExprKind::Neg(hir::Expr)`.
This shallowness enables the `HAIR` to represent all datatypes that [HIR] has, but
The [THIR] has datatypes that mirror the [HIR] datatypes, but instead of e.g. `-x`
being a `thir::ExprKind::Neg(thir::Expr)` it is a `thir::ExprKind::Neg(hir::Expr)`.
This shallowness enables the `THIR` to represent all datatypes that [HIR] has, but
without having to create an in-memory copy of the entire [HIR].
[MIR] lowering will first convert the topmost expression from
[HIR] to [HAIR] (in [`rustc_mir_build::hair::cx::expr`]) and then process
the [HAIR] expressions recursively.
[HIR] to [THIR] (in [`rustc_mir_build::thir::cx::expr`]) and then process
the [THIR] expressions recursively.

The lowering creates local variables for every argument as specified in the signature.
Next it creates local variables for every binding specified (e.g. `(a, b): (i32, String)`)
Expand Down Expand Up @@ -152,7 +152,7 @@ case of `enum`s.

[MIR]: ./index.html
[HIR]: ../hir.html
[HAIR]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/hair/index.html
[THIR]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/index.html

[`rustc_mir_build::hair::cx::expr`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/hair/cx/expr/index.html
[`rustc_mir_build::thir::cx::expr`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/thir/cx/expr/index.html
[`mir_built`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir_build/build/fn.mir_built.html
12 changes: 6 additions & 6 deletions src/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ we'll talk about that later.
- `stmt.rs`
- This naming scheme is used across many compiler stages. You will find
either a file or directory with the same name across the parsing, lowering,
type checking, HAIR lowering, and MIR building sources.
type checking, THIR lowering, and MIR building sources.
- Macro expansion, AST validation, name resolution, and early linting takes place
during this stage of the compile process.
- The parser uses the standard `DiagnosticBuilder` API for error handling, but we
Expand All @@ -69,8 +69,8 @@ we'll talk about that later.
- **TODO: Maybe some other things are done here? I think initial type checking
happens here? And trait solving?**
- The HIR is then [lowered to Mid-Level Intermediate Representation (MIR)][mir].
- Along the way, we construct the HAIR, which is an even more desugared HIR.
HAIR is used for pattern and exhaustiveness checking. It is also more
- Along the way, we construct the THIR, which is an even more desugared HIR.
THIR is used for pattern and exhaustiveness checking. It is also more
convenient to convert into MIR than HIR is.
- The MIR is used for [borrow checking].
- We (want to) do [many optimizations on the MIR][mir-opt] because it is still
Expand Down Expand Up @@ -187,10 +187,10 @@ for different purposes:
- High-level IR (HIR): This is a sort of desugared AST. It's still close
to what the user wrote syntactically, but it includes some implicit things
such as some elided lifetimes, etc. This IR is amenable to type checking.
- HAIR: This is an intermediate between HIR and MIR. It is like the HIR but it
is fully typed and a bit more desugared (e.g. method calls and implicit
- Typed HIR (THIR): This is an intermediate between HIR and MIR. It is like the HIR
but it is fully typed and a bit more desugared (e.g. method calls and implicit
dereferences are made fully explicit). Moreover, it is easier to lower to MIR
from HAIR than from HIR.
from THIR than from HIR.
- Middle-level IR (MIR): This IR is basically a Control-Flow Graph (CFG). A CFG
is a type of diagram that shows the basic blocks of a program and how control
flow can go between them. Likewise, MIR also has a bunch of basic blocks with
Expand Down