-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
lazily "compute" anon const default substs #87280
Conversation
Some changes occured to rustc_codegen_cranelift cc @bjorn3 Some changes occurred in src/tools/clippy. cc @rust-lang/clippy Some changes occured to the CTFE / Miri engine cc @rust-lang/miri Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
ddae395
to
78a2a47
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 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 has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9aac53b
to
ae49d01
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit ae49d0183a9a652553f901f75932d78af30c3483 with merge e38962e0c798b6fd647d7306b9f7904a89a4fe6c... |
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
Queued e38962e0c798b6fd647d7306b9f7904a89a4fe6c with parent c9aa259, future comparison URL. |
ae49d01
to
892e471
Compare
Finished benchmarking try commit (e38962e0c798b6fd647d7306b9f7904a89a4fe6c): comparison url. Summary: This change led to significant regressions 😿 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @bors rollup=never |
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Prevent duplicate caller bounds candidates by exposing default substs in Unevaluated Fixes rust-lang#89334 The changes introduced in rust-lang#87280 allowed for "duplicate" caller bounds candidates to be assembled that only differed in their default substs having been "exposed" or not and resulted in an ambiguity error during trait selection. To fix this we expose the defaults substs during the creation of the ParamEnv. r? `@lcnr`
This manifistated in rust-lang#90195 with compiler being unable to keep one candidate for a trait impl, if where is a global impl and more than one trait bound in the where clause. Before rust-lang#87280 `candidate_should_be_dropped_in_favor_of` was using `TypeFoldable::is_global()` that was enough to discard the two `ParamCandidate`s. But rust-lang#87280 changed it to use `TypeFoldable::is_known_global()` instead, which is pessimistic, so now the compiler drops the global impl instead (because `is_known_global` is not sure) and then can't decide between the two `ParamCandidate`s. Switching it to use `is_global` again solves the issue. Fixes rust-lang#90195.
Use `is_global` in `candidate_should_be_dropped_in_favor_of` This manifistated in rust-lang#90195 with compiler being unable to keep one candidate for a trait impl, if where is a global impl and more than one trait bound in the where clause. Before rust-lang#87280 `candidate_should_be_dropped_in_favor_of` was using `TypeFoldable::is_global()` that was enough to discard the two `ParamCandidate`s. But rust-lang#87280 changed it to use `TypeFoldable::is_known_global()` instead, which is pessimistic, so now the compiler drops the global impl instead (because `is_known_global` is not sure) and then can't decide between the two `ParamCandidate`s. Switching it to use `is_global` again solves the issue. Fixes rust-lang#90195.
…, r=lcnr partially revertish `lazily "compute" anon const default substs` reverts rust-lang#87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted why revert: <rust-lang#92805 (comment)> r? `@lcnr`
…, r=lcnr partially revertish `lazily "compute" anon const default substs` reverts rust-lang#87280 except for some of the changes around `ty::Unevaluated` having a visitor and a generic for promoted why revert: <rust-lang#92805 (comment)> r? `@lcnr`
Continuing the work of #83086, this implements the discussed solution for the unused substs problem. As of now, anonymous constants inherit all of their parents generics, even if they do not use them, e.g. in
fn foo<T, const N: usize>() -> [T; N + 1]
, the array length hasT
as a generic parameter even though it doesn't use it. These unused substs cause some backwards incompatible, and imo incorrect behavior, e.g. #78369.We do not actually filter any generic parameters here and the
default_anon_const_substs
query still a dummy which only checks thatpredicates_of(parent)
when computing the substs of anonymous constantsImplementing that filtering will be left as future work.
The idea of this PR is to delay the creation of the anon const substs until after we've computed
predicates_of
for the parent of the anon const. As the predicates of the parent can however contain the anon const we still have to create aty::Const
for it.We do this by changing the substs field of
ty::Unevaluated
to an option and modifying accesses to instead call the methodunevaluated.substs(tcx)
which returns the substs as before. If the substs - nowsubsts_
- ofty::Unevaluated
areNone
, it means that the anon const currently has its default substs, i.e. the substs it has when first constructed, which are the generic parameters it has available. To be able to callunevaluated.substs(tcx)
in aTypeVisitor
, we add the non-defaulted methodfn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>
. In casetcx_for_anon_const_substs
returnsNone
, unknown anon const default substs are skipped entirely.Even when
substs_
isNone
we still have to treat the constant as if it has its default substs. To do this,TypeFlags
are modified so that it is clear whether they can still change when exposing any anon const default substs. A new flag,HAS_UNKNOWN_DEFAULT_CONST_SUBSTS
, is added in case some default flags are missing.The rest of this PR are some smaller changes to either not cause cycles by trying to access the default anon const substs too early or to be able to access the
tcx
in previously unused locations.cc @rust-lang/project-const-generics
r? @nikomatsakis