-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Represent type-level consts with new-and-improved hir::ConstArg
#125915
Commits on Jul 17, 2024
-
Add
current_def_id_parent
toLoweringContext
This is needed to track anon const parents properly once we implement `ConstArgKind::Path` (which requires moving anon const def-creation outside of `DefCollector`): Why do we need this in addition to [`Self::current_hir_id_owner`]? Currently (as of June 2024), anonymous constants are not HIR owners; however, they do get their own DefIds. Some of these DefIds have to be created during AST lowering, rather than def collection, because we can't tell until after name resolution whether an anonymous constant will end up instead being a [`rustc_hir::ConstArgKind::Path`]. However, to compute which generics are available to an anonymous constant nested inside another, we need to make sure that the parent is recorded as the parent anon const, not the enclosing item. So we need to track parent defs differently from HIR owners, since they will be finer-grained in the case of anon consts.
Configuration menu - View commit details
-
Copy full SHA for 71f8aed - Browse repository at this point
Copy the full SHA 71f8aedView commit details -
hir: Create
hir::ConstArgKind
enumThis will allow lowering const params to a dedicated enum variant, rather than to an `AnonConst` that is later examined during `ty` lowering.
Configuration menu - View commit details
-
Copy full SHA for 11b144a - Browse repository at this point
Copy the full SHA 11b144aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7d7be2f - Browse repository at this point
Copy the full SHA 7d7be2fView commit details -
Configuration menu - View commit details
-
Copy full SHA for e7c85cb - Browse repository at this point
Copy the full SHA e7c85cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8818708 - Browse repository at this point
Copy the full SHA 8818708View commit details -
Configuration menu - View commit details
-
Copy full SHA for 67fccb7 - Browse repository at this point
Copy the full SHA 67fccb7View commit details -
Use
ConstArg
for const param defaultsNow everything that actually affects the type system (i.e., excluding const blocks, enum variant discriminants, etc.) *should* be using `ConstArg`.
Configuration menu - View commit details
-
Copy full SHA for 1c49d40 - Browse repository at this point
Copy the full SHA 1c49d40View commit details -
Add
ConstArgKind::Path
and makeConstArg
its own HIR nodeThis is a very large commit since a lot needs to be changed in order to make the tests pass. The salient changes are: - `ConstArgKind` gets a new `Path` variant, and all const params are now represented using it. Non-param paths still use `ConstArgKind::Anon` to prevent this change from getting too large, but they will soon use the `Path` variant too. - `ConstArg` gets a distinct `hir_id` field and its own variant in `hir::Node`. This affected many parts of the compiler that expected the parent of an `AnonConst` to be the containing context (e.g., an array repeat expression). They have been changed to check the "grandparent" where necessary. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at rust-lang#127009.
Configuration menu - View commit details
-
Copy full SHA for 37ed7a4 - Browse repository at this point
Copy the full SHA 37ed7a4View commit details
Commits on Jul 18, 2024
-
Clarify docs explaining purpose of
ConstArg
Co-authored-by: Boxy <rust@boxyuwu.dev>
Configuration menu - View commit details
-
Copy full SHA for 2e4a0e3 - Browse repository at this point
Copy the full SHA 2e4a0e3View commit details -
Configuration menu - View commit details
-
Copy full SHA for c8457e6 - Browse repository at this point
Copy the full SHA c8457e6View commit details