From 46e1c6bc5d5f7fe6e7a5474c4cc4eae208eca3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Tue, 27 Feb 2024 11:51:05 +0100 Subject: [PATCH] Rename AstConv to HIR ty lowering --- src/SUMMARY.md | 2 +- src/{lowering.md => ast-lowering.md} | 4 ++-- src/diagnostics.md | 4 ++-- src/overview.md | 4 ++-- src/return-position-impl-trait-in-trait.md | 23 ++++++++++++---------- src/turbofishing-and-early-late-bound.md | 10 +++++----- src/ty.md | 8 ++++---- 7 files changed, 29 insertions(+), 26 deletions(-) rename src/{lowering.md => ast-lowering.md} (97%) diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 82e0d79aa7..ab0962af24 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) diff --git a/src/lowering.md b/src/ast-lowering.md similarity index 97% rename from src/lowering.md rename to src/ast-lowering.md index f6885b9229..033fd4b76f 100644 --- a/src/lowering.md +++ b/src/ast-lowering.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 for type analysis or similar syntax agnostic analyses. Examples of such structures include but are not limited to diff --git a/src/diagnostics.md b/src/diagnostics.md index 39c6c8aa52..9b34ba829f 100644 --- a/src/diagnostics.md +++ b/src/diagnostics.md @@ -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. @@ -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 diff --git a/src/overview.md b/src/overview.md index fb0b07e630..30c39b0e6b 100644 --- a/src/overview.md +++ b/src/overview.md @@ -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 @@ -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** diff --git a/src/return-position-impl-trait-in-trait.md b/src/return-position-impl-trait-in-trait.md index 9ed62c87cc..8da7857896 100644 --- a/src/return-position-impl-trait-in-trait.md +++ b/src/return-position-impl-trait-in-trait.md @@ -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. @@ -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 @@ -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. diff --git a/src/turbofishing-and-early-late-bound.md b/src/turbofishing-and-early-late-bound.md index a1d8a64e8e..ad9064f56e 100644 --- a/src/turbofishing-and-early-late-bound.md +++ b/src/turbofishing-and-early-late-bound.md @@ -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::` (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::` +(naturally `k#no_argument` would only make sense as an argument to late bound parameters). diff --git a/src/ty.md b/src/ty.md index 80a72b1167..da6651a99d 100644 --- a/src/ty.md +++ b/src/ty.md @@ -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`**