Rename AstConv to HIR ty lowering
This commit is contained in:
parent
8f6a4f62c8
commit
ffa246b7fd
|
|
@ -97,7 +97,7 @@
|
||||||
- [Feature Gate Checking](./feature-gate-ck.md)
|
- [Feature Gate Checking](./feature-gate-ck.md)
|
||||||
- [Lang Items](./lang-items.md)
|
- [Lang Items](./lang-items.md)
|
||||||
- [The HIR (High-level IR)](./hir.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)
|
- [Debugging](./hir-debugging.md)
|
||||||
- [The THIR (Typed High-level IR)](./thir.md)
|
- [The THIR (Typed High-level IR)](./thir.md)
|
||||||
- [The MIR (Mid-level IR)](./mir/index.md)
|
- [The MIR (Mid-level IR)](./mir/index.md)
|
||||||
|
|
|
||||||
|
|
@ -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
|
This means many structures are removed if they are irrelevant
|
||||||
for type analysis or similar syntax agnostic analyses. Examples
|
for type analysis or similar syntax agnostic analyses. Examples
|
||||||
of such structures include but are not limited to
|
of such structures include but are not limited to
|
||||||
|
|
@ -519,7 +519,7 @@ are:
|
||||||
macros.
|
macros.
|
||||||
|
|
||||||
- Early lint pass: Works on [AST nodes] after [macro expansion] and name
|
- 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.
|
syntactical lints.
|
||||||
- Example: The [`unused_parens`] lint checks for parenthesized-expressions
|
- Example: The [`unused_parens`] lint checks for parenthesized-expressions
|
||||||
in situations where they are not needed, like an `if` condition.
|
in situations where they are not needed, like an `if` condition.
|
||||||
|
|
@ -550,7 +550,7 @@ compiler](#linting-early-in-the-compiler).
|
||||||
|
|
||||||
|
|
||||||
[AST nodes]: the-parser.md
|
[AST nodes]: the-parser.md
|
||||||
[HIR lowering]: lowering.md
|
[AST lowering]: ast-lowering.md
|
||||||
[HIR nodes]: hir.md
|
[HIR nodes]: hir.md
|
||||||
[MIR nodes]: mir/index.md
|
[MIR nodes]: mir/index.md
|
||||||
[macro expansion]: macro-expansion.md
|
[macro expansion]: macro-expansion.md
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ returned from the parser while the standard [`Diag`] API is used
|
||||||
for error handling. Generally Rust's compiler will try to recover from errors
|
for error handling. Generally Rust's compiler will try to recover from errors
|
||||||
by parsing a superset of Rust's grammar, while also emitting an error type.
|
by parsing a superset of Rust's grammar, while also emitting an error type.
|
||||||
|
|
||||||
### `HIR` lowering
|
### `AST` lowering
|
||||||
|
|
||||||
Next the `AST` is converted into [High-Level Intermediate Representation
|
Next the `AST` is converted into [High-Level Intermediate Representation
|
||||||
(`HIR`)][hir], a more compiler-friendly representation of the `AST`. This process
|
(`HIR`)][hir], a more compiler-friendly representation of the `AST`. This process
|
||||||
|
|
@ -410,7 +410,7 @@ For more details on bootstrapping, see
|
||||||
- Guide: [The HIR](hir.md)
|
- Guide: [The HIR](hir.md)
|
||||||
- Guide: [Identifiers in the HIR](hir.md#identifiers-in-the-hir)
|
- Guide: [Identifiers in the HIR](hir.md#identifiers-in-the-hir)
|
||||||
- Guide: [The `HIR` Map](hir.md#the-hir-map)
|
- 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`
|
- 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)
|
- Rustc `HIR` definition: [`rustc_hir`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/index.html)
|
||||||
- Main entry point: **TODO**
|
- Main entry point: **TODO**
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,21 @@ by T-lang.
|
||||||
|
|
||||||
## How does it work?
|
## How does it work?
|
||||||
|
|
||||||
This doc is ordered mostly via the compilation pipeline. AST -> HIR ->
|
This doc is ordered mostly via the compilation pipeline:
|
||||||
astconv -> typeck.
|
|
||||||
|
|
||||||
### 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
|
still lower them as
|
||||||
[`hir::ItemKind::OpaqueTy`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html).
|
[`hir::ItemKind::OpaqueTy`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html).
|
||||||
The two differences are that:
|
The two differences are that:
|
||||||
|
|
||||||
We record `in_trait` for the opaque. This will signify that the opaque
|
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.
|
We record `lifetime_mapping`s for the opaque type, described below.
|
||||||
|
|
||||||
|
|
@ -49,7 +52,7 @@ bounds that enforce equality between these duplicated lifetimes and
|
||||||
their source lifetimes in order to properly typecheck these GATs, which
|
their source lifetimes in order to properly typecheck these GATs, which
|
||||||
will be discussed below.
|
will be discussed below.
|
||||||
|
|
||||||
##### note:
|
##### Note
|
||||||
|
|
||||||
It may be better if we were able to lower without duplicates and for
|
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
|
that I think we would need to stop distinguishing between early and late
|
||||||
|
|
@ -59,14 +62,14 @@ late-bound lifetimes in generics
|
||||||
PR similar to [Inherit function lifetimes for impl-trait
|
PR similar to [Inherit function lifetimes for impl-trait
|
||||||
#103449](https://github.com/rust-lang/rust/pull/103449).
|
#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
|
The main change to HIR ty lowering is that we lower `hir::TyKind::OpaqueDef`
|
||||||
an RPITIT to a projection instead of an opaque, using a newly
|
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
|
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.
|
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
|
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
|
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.
|
in the trait, or the inferred type of the RPITIT if we're in an impl.
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,8 @@ fn main() {
|
||||||
accepts_fn(f);
|
accepts_fn(f);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Maybe we can just special case astconv for `_`/`'_` arguments for late bound parameters somehow
|
Maybe we can just special case HIR ty lowering for `_`/`'_` arguments for late bound
|
||||||
and have it not mean the same thing as `_` for early bound parameters. Regardless I think we
|
parameters somehow and have it not mean the same thing as `_` for early bound parameters.
|
||||||
would need a solution that would allow writing the above code even if it was done by some new
|
Regardless I think we would need a solution that would allow writing the above code even
|
||||||
syntax such as havign to write `late::<k#no_argument, 'static>` (naturally `k#no_argument`
|
if it was done by some new syntax such as having to write `late::<k#no_argument, 'static>`
|
||||||
would only make sense as an argument to late bound parameters).
|
(naturally `k#no_argument` would only make sense as an argument to late bound parameters).
|
||||||
|
|
|
||||||
|
|
@ -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
|
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
|
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
|
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
|
expected type. The [`hir_ty_lowering` module][hir_ty_lowering] is where the code responsible for
|
||||||
`rustc_hir::Ty` into a `ty::Ty` is located. The main routine used is `ast_ty_to_ty`. This occurs
|
lowering a `rustc_hir::Ty` to a `ty::Ty` is located. The main routine used is `lower_ty`.
|
||||||
during the type-checking phase, but also in other parts of the compiler that want to ask
|
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?"
|
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`**
|
**How semantics drive the two instances of `Ty`**
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue