Add new alias kind Ambiguous and renormalize instantiated binders#156453
Add new alias kind Ambiguous and renormalize instantiated binders#156453adwinwhite wants to merge 13 commits into
Ambiguous and renormalize instantiated binders#156453Conversation
|
@bors try @rust-timer queue |
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
This comment has been minimized.
This comment has been minimized.
Add new alias kind `Ambiguous` and renormalize instantiated binders
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@bors try cancel |
|
Try build cancelled. Cancelled workflows: |
|
Ignore tools failures for now. @bors try @rust-timer queue |
|
This pull request is already queued and waiting for a try build to finish. |
This comment has been minimized.
This comment has been minimized.
Add new alias kind `Ambiguous` and renormalize instantiated binders
|
💔 Test for 1c015e6 failed: CI. Failed job:
|
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
|
||
| // Placeholders (all printed as `_` to uniformize them). | ||
| ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => { | ||
| ty::Alias(ty::AliasTy { kind: ty::Ambiguous { .. }, .. }) |
There was a problem hiding this comment.
unreachable
| Unnormalized::new_wip(unnormalized_external_impl_sig), | ||
| ); | ||
| let external_impl_sig = | ||
| ocx.normalize(&norm_cause, param_env, Unnormalized::new(unnormalized_external_impl_sig)); |
There was a problem hiding this comment.
| ocx.normalize(&norm_cause, param_env, Unnormalized::new(unnormalized_external_impl_sig)); | |
| ocx.normalize(&norm_cause, param_env, Unnormalized::new_wip(unnormalized_external_impl_sig)); |
ideally this should be a map_unnormalized call in which we instantiate the binder
| ty::Alias(ty::AliasTy { kind: ty::Ambiguous { .. }, .. }) => { | ||
| let sp = tcx.def_span(impl_def_id); | ||
| span_bug!(sp, "weird self type for autotrait impl") | ||
| } |
There was a problem hiding this comment.
redundant?
|
|
||
| // Placeholders (all printed as `_` to uniformize them). | ||
| ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => { | ||
| ty::Alias(ty::AliasTy { kind: ty::Ambiguous { .. }, .. }) |
There was a problem hiding this comment.
unreachable
There was a problem hiding this comment.
can you also make ty::Infer unreachable?
| // Now that we perform eager normalization inside the solver in some places, | ||
| // The aliases might be normalized away. |
There was a problem hiding this comment.
when do we do eager norm for the inputs of alias relate goals? 🤔
| /// next solver. See `NormalizationFolder`. | ||
| /// | ||
| /// The def_id and args are the same as the original alias. | ||
| AmbiguousTy { def_id: I::DefId }, |
There was a problem hiding this comment.
why does this contain the def_id
| } | ||
| } | ||
|
|
||
| pub fn instantiate_binder_with_fresh_vars_and_normalize_with<T, F>( |
There was a problem hiding this comment.
hmm, this is different from what I'd imagine 🤔
I would expect us to have
fn instantiate_binder_no_ambig_aliases(x: Binder<T>) -> T {
instantiate_binder_renormalize_ambig_aliases(x, |_| unreachable!())
}
fn instantiate_binder_renormalize_ambig_aliases(x: Binder<T>, normalize: impl FnMut(AliasTerm<'tcx>) -> Term<'tcx>) -> T {
instantiate binder
walk with renormalize ambig aliases folder
}I'd then keep the borrowck code etc the same as rn while using instantiate_binder_no_ambig_aliases and use instantiate_binder_renormalize_ambig_aliases only in the places that can encounter ambig aliases
There was a problem hiding this comment.
where all the old solver exclusive code can just use instantiate_binder_no_ambig_aliases
There was a problem hiding this comment.
and the new solver places that currently can't easily use a normalization routine can just recreate the ty::Alias or ConstKind::Alias with a FIXME that they should instead normalize
| self.print_def_path(def_id, args)?; | ||
| ty::Alias(ref data @ ty::AliasTy { kind, args, .. }) => match kind | ||
| .reveal_ambiguous(self.tcx()) | ||
| { |
There was a problem hiding this comment.
hmm, instead of reeal_ambiguous Ambiguous aliases can just forward to their contained alias?
| // Convert `AmbiguousTy` into its original kind. | ||
| pub fn reveal_ambiguous(self, interner: I) -> Self { | ||
| if let AliasTermKind::AmbiguousTy { def_id } = self { | ||
| interner.alias_term_kind_from_def_id(def_id) | ||
| } else { | ||
| self | ||
| } | ||
| } |
There was a problem hiding this comment.
ah, so what you do is ty::Alias(Projection { def_id }, [Self, T]) to ty::Alias(Ambiguous { def_id }, [Self, T]) instead of
ty::Alias(Projection { def_id }, [Self, T]) to ty::Alias(Ambiguous, ty::Alias(Projection { def_id }, [Self, T])]) which is what I would have expected 🤔
| ) -> InferOk<'tcx, T> { | ||
| if self.infcx.next_trait_solver() { | ||
| let Normalized { value, obligations } = | ||
| crate::solve::normalize(*self, value, NormalizationScope::AmbiguousAlias); |
There was a problem hiding this comment.
i would not add support for this to the old trait solver at all 🤔 i would only ever use ambiguous aliases in the new solver, so here ambiguous aliases should be unreachable
| &self, | ||
| value: ty::Binder<Self::Interner, T>, | ||
| f: impl FnOnce(T) -> U, | ||
| f: impl FnOnce(ty::Unnormalized<Self::Interner, T>) -> U, |
There was a problem hiding this comment.
| f: impl FnOnce(ty::Unnormalized<Self::Interner, T>) -> U, | |
| normalize_ambiguous_aliases: impl FnMut(ALiasTerm<'tcx>) -> Term<'tcx> | |
| f: impl FnOnce(T) -> U, |
is what I would have liked🤔 I personally feel like Unnormalized for both being fully unnormalized and only having to renormalize ambiguous aliases feels suboptimal to me
Still WIP.
- fix rustdoc
- also normalize for diagnostics and assert the remaining instantiation doesn't need renormalization.
- remove the accidental staged
cargosubmoduleBut maybe you wanna have a quick look first.
r? lcnr