-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Deeply normalize param env in compare_impl_item if using the next solver
#149345
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -477,6 +477,69 @@ pub fn normalize_param_env_or_error<'tcx>( | |
| ty::ParamEnv::new(tcx.mk_clauses(&predicates)) | ||
| } | ||
|
|
||
| /// Deeply normalize the param env using the next solver ignoring | ||
| /// region errors. | ||
| /// | ||
| /// FIXME(-Zhigher-ranked-assumptions): this is a hack to work around | ||
| /// the fact that we don't support placeholder assumptions right now | ||
| /// and is necessary for `compare_method_predicate_entailment`, see the | ||
| /// use of this function for more info. We should remove this once we | ||
| /// have proper support for implied bounds on binders. | ||
| #[instrument(level = "debug", skip(tcx))] | ||
| pub fn deeply_normalize_param_env_ignoring_regions<'tcx>( | ||
| tcx: TyCtxt<'tcx>, | ||
| unnormalized_env: ty::ParamEnv<'tcx>, | ||
| cause: ObligationCause<'tcx>, | ||
| ) -> ty::ParamEnv<'tcx> { | ||
| let predicates: Vec<_> = | ||
| util::elaborate(tcx, unnormalized_env.caller_bounds().into_iter()).collect(); | ||
|
|
||
| debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); | ||
|
|
||
| let elaborated_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't think we have to create a new wanna update the new solver to just use the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we need to use the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh 😅 I am blind xd |
||
| if !elaborated_env.has_aliases() { | ||
| return elaborated_env; | ||
| } | ||
|
|
||
| let span = cause.span; | ||
| let infcx = tcx | ||
| .infer_ctxt() | ||
| .with_next_trait_solver(true) | ||
| .ignoring_regions() | ||
| .build(TypingMode::non_body_analysis()); | ||
| let predicates = match crate::solve::deeply_normalize::<_, FulfillmentError<'tcx>>( | ||
| infcx.at(&cause, elaborated_env), | ||
| predicates, | ||
| ) { | ||
| Ok(predicates) => predicates, | ||
| Err(errors) => { | ||
| infcx.err_ctxt().report_fulfillment_errors(errors); | ||
| // An unnormalized env is better than nothing. | ||
| debug!("normalize_param_env_or_error: errored resolving predicates"); | ||
| return elaborated_env; | ||
| } | ||
| }; | ||
|
|
||
| debug!("do_normalize_predicates: normalized predicates = {:?}", predicates); | ||
| // FIXME(-Zhigher-ranked-assumptions): We're ignoring region errors for now. | ||
| // There're placeholder constraints `leaking` out. | ||
| // See the fixme in the enclosing function's docs for more. | ||
| let _errors = infcx.resolve_regions(cause.body_id, elaborated_env, []); | ||
|
|
||
| let predicates = match infcx.fully_resolve(predicates) { | ||
| Ok(predicates) => predicates, | ||
| Err(fixup_err) => { | ||
| span_bug!( | ||
| span, | ||
| "inference variables in normalized parameter environment: {}", | ||
| fixup_err | ||
| ) | ||
| } | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need to split outlives vs non-outlives predicate norm in the new solver. This only matters for the old one
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that way you also don't need a separate |
||
| debug!("normalize_param_env_or_error: final predicates={:?}", predicates); | ||
| ty::ParamEnv::new(tcx.mk_clauses(&predicates)) | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum EvaluateConstErr { | ||
| /// The constant being evaluated was either a generic parameter or inference variable, *or*, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //@ check-pass | ||
| //@ compile-flags: -Znext-solver | ||
|
|
||
| // See trait-system-refactor-initiative/issues/166. | ||
| // The old solver doesn't check normalization constraints in `compare_impl_item`. | ||
| // The new solver performs lazy normalization so those region constraints may get postponed to | ||
| // an infcx that considers regions. | ||
| trait Trait { | ||
| type Assoc<'a> | ||
| where | ||
| Self: 'a; | ||
| } | ||
| impl<'b> Trait for &'b u32 { | ||
| type Assoc<'a> = &'a u32 | ||
| where | ||
| Self: 'a; | ||
| } | ||
|
|
||
| trait Bound<T> {} | ||
| trait Entailment<T: Trait> { | ||
| fn method() | ||
| where | ||
| Self: for<'a> Bound<<T as Trait>::Assoc<'a>>; | ||
| } | ||
|
|
||
| impl<'b, T> Entailment<&'b u32> for T { | ||
| // Instantiates trait where-clauses with `&'b u32` and then normalizes | ||
| // `T: for<'a> Bound<<&'b u32 as Trait>::Assoc<'a>>` in a separate infcx | ||
| // without checking region constraints. | ||
| // | ||
| // It normalizes to `T: Bound<&'a u32>`, dropping the `&'b u32: 'a` constraint. | ||
| fn method() | ||
| where | ||
| Self: for<'a> Bound<&'a u32> | ||
| {} | ||
| } | ||
|
|
||
| fn main() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elaborated a bit here