Represent type-level consts with new-and-improved hir::ConstArg#125915
Represent type-level consts with new-and-improved hir::ConstArg#125915bors merged 10 commits intorust-lang:masterfrom
hir::ConstArg#125915Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
5819f98 to
9d6aa97
Compare
d9dc960 to
98df547
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ConstArgKind varianthir::ConstArg
1755fdf to
4bea486
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
486af6c to
405f7de
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
|
Let's re-approve this so it enters the queue once the tree is re-opened. @bors r=BoxyUwU |
|
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (8c3a94a): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (primary 2.2%, secondary 2.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResults (primary -0.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 768.827s -> 770.782s (0.25%) |
Represent type-level consts with new-and-improved `hir::ConstArg` ### Summary This is a step toward `min_generic_const_exprs`. We now represent all const generic arguments using an enum that differentiates between const *paths* (temporarily just bare const params) and arbitrary anon consts that may perform computations. This will enable us to cleanly implement the `min_generic_const_args` plan of allowing the use of generics in paths used as const args, while disallowing their use in arbitrary anon consts. Here is a summary of the salient aspects of this change: - Add `current_def_id_parent` to `LoweringContext` This is needed to track anon const parents properly once we implement `ConstArgKind::Path` (which requires moving anon const def-creation outside of `DefCollector`). - Create `hir::ConstArgKind` enum with `Path` and `Anon` variants. Use it in the existing `hir::ConstArg` struct, replacing the previous `hir::AnonConst` field. - Use `ConstArg` for all instances of const args. Specifically, use it instead of `AnonConst` for assoc item constraints, array lengths, and const param defaults. - 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. ### Followup items post-merge - Use `ConstArgKind::Path` for all const paths, not just const params. - Fix (no github dont close this issue) rust-lang#127009 - If a path in generic args doesn't resolve as a type, try to resolve as a const instead (do this in rustc_resolve). Then remove the special-casing from `rustc_ast_lowering`, so that all params will automatically be lowered as `ConstArgKind::Path`. - (?) Consider making `const_evaluatable_unchecked` a hard error, or at least trying it in crater r? `@BoxyUwU`
Summary
This is a step toward
min_generic_const_exprs. We now represent all constgeneric arguments using an enum that differentiates between const paths
(temporarily just bare const params) and arbitrary anon consts that may perform
computations. This will enable us to cleanly implement the
min_generic_const_argsplan of allowing the use of generics in paths used as const args, while
disallowing their use in arbitrary anon consts. Here is a summary of the salient
aspects of this change:
Add
current_def_id_parenttoLoweringContextThis is needed to track anon const parents properly once we implement
ConstArgKind::Path(which requires moving anon const def-creationoutside of
DefCollector).Create
hir::ConstArgKindenum withPathandAnonvariants. Use it in theexisting
hir::ConstArgstruct, replacing the previoushir::AnonConstfield.Use
ConstArgfor all instances of const args. Specifically, use it insteadof
AnonConstfor assoc item constraints, array lengths, and const paramdefaults.
Some
ast::AnonConsts now have theirDefIds created inrustc_ast_lowering rather than
DefCollector. This is because in somecases they will end up becoming a
ConstArgKind::Pathinstead, whichhas no
DefId. We have to solve this in a hacky way where we guesswhether the
AnonConstcould end up as a path const since we can'tknow for sure until after name resolution (
Ncould refer to a freeconst or a nullary struct). If it has no chance as being a const
param, then we create a
DefIdinDefCollector-- otherwise wedecide during ast_lowering. This will have to be updated once all path
consts use
ConstArgKind::Path.We explicitly use
ConstArgHasTypefor array lengths, rather thanimplicitly 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 ICE(non_lifetime_binders): const bound params not handled correctly #127009.
Followup items post-merge
ConstArgKind::Pathfor all const paths, not just const params.r? @BoxyUwU