Skip to content

Commit

Permalink
Rename AstConv to HIR ty lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Feb 27, 2024
1 parent 7b0ef5b commit 46e1c6b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
- [Feature Gate Checking](./feature-gate-ck.md)
- [Lang Items](./lang-items.md)
- [The HIR (High-level IR)](./hir.md)
- [Lowering AST to HIR](./lowering.md)
- [Lowering AST to HIR](./ast-lowering.md)
- [Debugging](./hir-debugging.md)
- [The THIR (Typed High-level IR)](./thir.md)
- [The MIR (Mid-level IR)](./mir/index.md)
Expand Down
4 changes: 2 additions & 2 deletions src/lowering.md → src/ast-lowering.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Lowering
# AST lowering

The lowering step converts AST to [HIR](hir.html).
The AST lowering step converts AST to [HIR](hir.html).
This means many structures are removed if they are irrelevant
for type analysis or similar syntax agnostic analyses. Examples
of such structures include but are not limited to
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ are:
macros.

- Early lint pass: Works on [AST nodes] after [macro expansion] and name
resolution, just before [HIR lowering]. These lints are for purely
resolution, just before [AST lowering]. These lints are for purely
syntactical lints.
- Example: The [`unused_parens`] lint checks for parenthesized-expressions
in situations where they are not needed, like an `if` condition.
Expand Down Expand Up @@ -550,7 +550,7 @@ compiler](#linting-early-in-the-compiler).


[AST nodes]: the-parser.md
[HIR lowering]: lowering.md
[AST lowering]: ast-lowering.md
[HIR nodes]: hir.md
[MIR nodes]: mir/index.md
[macro expansion]: macro-expansion.md
Expand Down
4 changes: 2 additions & 2 deletions src/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The parser uses the standard `DiagnosticBuilder` API for error handling, but we
try to recover, parsing a superset of Rust's grammar, while also emitting an error.
`rustc_ast::ast::{Crate, Mod, Expr, Pat, ...}` AST nodes are returned from the parser.

### HIR lowering
### AST lowering

Next, we take the AST and convert it to [High-Level Intermediate
Representation (HIR)][hir], a more compiler-friendly representation of the
Expand Down Expand Up @@ -394,7 +394,7 @@ For more details on bootstrapping, see
- Guide: [The HIR](hir.md)
- Guide: [Identifiers in the HIR](hir.md#identifiers-in-the-hir)
- Guide: [The HIR Map](hir.md#the-hir-map)
- Guide: [Lowering AST to HIR](lowering.md)
- Guide: [Lowering AST to HIR](ast-lowering.md)
- How to view HIR representation for your code `cargo rustc -- -Z unpretty=hir-tree`
- Rustc HIR definition: [`rustc_hir`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/index.html)
- Main entry point: **TODO**
Expand Down
23 changes: 13 additions & 10 deletions src/return-position-impl-trait-in-trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ by T-lang.

## How does it work?

This doc is ordered mostly via the compilation pipeline. AST -> HIR ->
astconv -> typeck.
This doc is ordered mostly via the compilation pipeline:

### AST and HIR
1. AST lowering (AST -> HIR)
2. HIR ty lowering (HIR -> rustc_middle::ty data types)
3. typeck

AST -> HIR lowering for RPITITs is almost the same as lowering RPITs. We
### AST lowering

AST lowering for RPITITs is almost the same as lowering RPITs. We
still lower them as
[`hir::ItemKind::OpaqueTy`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html).
The two differences are that:

We record `in_trait` for the opaque. This will signify that the opaque
is an RPITIT for astconv, diagnostics that deal with HIR, etc.
is an RPITIT for HIR ty lowering, diagnostics that deal with HIR, etc.

We record `lifetime_mapping`s for the opaque type, described below.

Expand All @@ -49,7 +52,7 @@ bounds that enforce equality between these duplicated lifetimes and
their source lifetimes in order to properly typecheck these GATs, which
will be discussed below.

##### note:
##### Note

It may be better if we were able to lower without duplicates and for
that I think we would need to stop distinguishing between early and late
Expand All @@ -59,14 +62,14 @@ late-bound lifetimes in generics
PR similar to [Inherit function lifetimes for impl-trait
#103449](https://github.com/rust-lang/rust/pull/103449).

### Astconv
### HIR ty lowering

The main change to astconv is that we lower `hir::TyKind::OpaqueDef` for
an RPITIT to a projection instead of an opaque, using a newly
The main change to HIR ty lowering is that we lower `hir::TyKind::OpaqueDef`
for an RPITIT to a projection instead of an opaque, using a newly
synthesized def-id for a new associated type in the trait. We'll
describe how exactly we get this def-id in the next section.

This means that any time we call `ast_ty_to_ty` on the RPITIT, we end up
This means that any time we call `lower_ty` on the RPITIT, we end up
getting a projection back instead of an opaque. This projection can then
be normalized to the right value -- either the original opaque if we're
in the trait, or the inferred type of the RPITIT if we're in an impl.
Expand Down
10 changes: 5 additions & 5 deletions src/turbofishing-and-early-late-bound.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fn main() {
accepts_fn(f);
}
```
Maybe we can just special case astconv for `_`/`'_` arguments for late bound parameters somehow
and have it not mean the same thing as `_` for early bound parameters. Regardless I think we
would need a solution that would allow writing the above code even if it was done by some new
syntax such as havign to write `late::<k#no_argument, 'static>` (naturally `k#no_argument`
would only make sense as an argument to late bound parameters).
Maybe we can just special case HIR ty lowering for `_`/`'_` arguments for late bound
parameters somehow and have it not mean the same thing as `_` for early bound parameters.
Regardless I think we would need a solution that would allow writing the above code even
if it was done by some new syntax such as havign to write `late::<k#no_argument, 'static>`
(naturally `k#no_argument` would only make sense as an argument to late bound parameters).
8 changes: 4 additions & 4 deletions src/ty.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ HIR is built directly from the AST, so it happens before any `ty::Ty` is produce
HIR is built, some basic type inference and type checking is done. During the type inference, we
figure out what the `ty::Ty` of everything is and we also check if the type of something is
ambiguous. The `ty::Ty` is then used for type checking while making sure everything has the
expected type. The [`astconv` module][astconv] is where the code responsible for converting a
`rustc_hir::Ty` into a `ty::Ty` is located. The main routine used is `ast_ty_to_ty`. This occurs
during the type-checking phase, but also in other parts of the compiler that want to ask
expected type. The [`hir_ty_lowering` module][hir_ty_lowering] is where the code responsible for
lowering a `rustc_hir::Ty` to a `ty::Ty` is located. The main routine used is `lower_ty`.
This occurs during the type-checking phase, but also in other parts of the compiler that want to ask
questions like "what argument types does this function expect?"

[astconv]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/astconv/index.html
[hir_ty_lowering]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/hir_ty_lowering/index.html

**How semantics drive the two instances of `Ty`**

Expand Down

0 comments on commit 46e1c6b

Please sign in to comment.