Split out instantiate_nested_goals
This commit is contained in:
parent
13825dcc15
commit
7597d1504e
1 changed files with 43 additions and 36 deletions
|
@ -57,6 +57,10 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
||||||
self.result.map(|c| c.value.certainty)
|
self.result.map(|c| c.value.certainty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn goal(&self) -> &'a InspectGoal<'a, 'tcx> {
|
||||||
|
self.goal
|
||||||
|
}
|
||||||
|
|
||||||
/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
|
/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
|
||||||
///
|
///
|
||||||
/// If this certainty is `Yes`, then we must be confident that the candidate
|
/// If this certainty is `Yes`, then we must be confident that the candidate
|
||||||
|
@ -74,46 +78,55 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
||||||
/// the state of the `infcx`.
|
/// the state of the `infcx`.
|
||||||
pub fn visit_nested_no_probe<V: ProofTreeVisitor<'tcx>>(&self, visitor: &mut V) -> V::Result {
|
pub fn visit_nested_no_probe<V: ProofTreeVisitor<'tcx>>(&self, visitor: &mut V) -> V::Result {
|
||||||
if self.goal.depth < visitor.config().max_depth {
|
if self.goal.depth < visitor.config().max_depth {
|
||||||
|
for goal in self.instantiate_nested_goals(visitor.span()) {
|
||||||
|
try_visit!(visitor.visit_goal(&goal));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
V::Result::output()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiate the nested goals for the candidate without rolling back their
|
||||||
|
/// inference constraints. This function modifies the state of the `infcx`.
|
||||||
|
pub fn instantiate_nested_goals(&self, span: Span) -> Vec<InspectGoal<'a, 'tcx>> {
|
||||||
let infcx = self.goal.infcx;
|
let infcx = self.goal.infcx;
|
||||||
let param_env = self.goal.goal.param_env;
|
let param_env = self.goal.goal.param_env;
|
||||||
let mut orig_values = self.goal.orig_values.to_vec();
|
let mut orig_values = self.goal.orig_values.to_vec();
|
||||||
let mut instantiated_goals = vec![];
|
let instantiated_goals: Vec<_> = self
|
||||||
for goal in &self.nested_goals {
|
.nested_goals
|
||||||
let goal = canonical::instantiate_canonical_state(
|
.iter()
|
||||||
|
.map(|goal| {
|
||||||
|
canonical::instantiate_canonical_state(
|
||||||
infcx,
|
infcx,
|
||||||
visitor.span(),
|
span,
|
||||||
param_env,
|
param_env,
|
||||||
&mut orig_values,
|
&mut orig_values,
|
||||||
*goal,
|
*goal,
|
||||||
);
|
)
|
||||||
instantiated_goals.push(goal);
|
})
|
||||||
}
|
.collect();
|
||||||
|
|
||||||
let () = canonical::instantiate_canonical_state(
|
let () = canonical::instantiate_canonical_state(
|
||||||
infcx,
|
infcx,
|
||||||
visitor.span(),
|
span,
|
||||||
param_env,
|
param_env,
|
||||||
&mut orig_values,
|
&mut orig_values,
|
||||||
self.final_state,
|
self.final_state,
|
||||||
);
|
);
|
||||||
|
|
||||||
for &goal in &instantiated_goals {
|
instantiated_goals
|
||||||
|
.into_iter()
|
||||||
|
.map(|goal| {
|
||||||
let proof_tree = match goal.predicate.kind().no_bound_vars() {
|
let proof_tree = match goal.predicate.kind().no_bound_vars() {
|
||||||
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
|
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
|
||||||
let unconstrained_term = match term.unpack() {
|
let unconstrained_term = match term.unpack() {
|
||||||
ty::TermKind::Ty(_) => infcx
|
ty::TermKind::Ty(_) => infcx
|
||||||
.next_ty_var(TypeVariableOrigin {
|
.next_ty_var(TypeVariableOrigin { param_def_id: None, span })
|
||||||
param_def_id: None,
|
|
||||||
span: visitor.span(),
|
|
||||||
})
|
|
||||||
.into(),
|
.into(),
|
||||||
ty::TermKind::Const(ct) => infcx
|
ty::TermKind::Const(ct) => infcx
|
||||||
.next_const_var(
|
.next_const_var(
|
||||||
ct.ty(),
|
ct.ty(),
|
||||||
ConstVariableOrigin {
|
ConstVariableOrigin { param_def_id: None, span },
|
||||||
param_def_id: None,
|
|
||||||
span: visitor.span(),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
};
|
};
|
||||||
|
@ -129,22 +142,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
|
||||||
})
|
})
|
||||||
.1;
|
.1;
|
||||||
let InferOk { value: (), obligations: _ } = infcx
|
let InferOk { value: (), obligations: _ } = infcx
|
||||||
.at(&ObligationCause::dummy(), param_env)
|
.at(&ObligationCause::dummy_with_span(span), param_env)
|
||||||
.eq(DefineOpaqueTypes::Yes, term, unconstrained_term)
|
.eq(DefineOpaqueTypes::Yes, term, unconstrained_term)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
proof_tree
|
proof_tree
|
||||||
}
|
}
|
||||||
_ => infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1,
|
_ => infcx.evaluate_root_goal(goal, GenerateProofTree::Yes).1,
|
||||||
};
|
};
|
||||||
try_visit!(visitor.visit_goal(&InspectGoal::new(
|
InspectGoal::new(infcx, self.goal.depth + 1, proof_tree.unwrap())
|
||||||
infcx,
|
})
|
||||||
self.goal.depth + 1,
|
.collect()
|
||||||
proof_tree.unwrap(),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
V::Result::output()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Visit all nested goals of this candidate, rolling back
|
/// Visit all nested goals of this candidate, rolling back
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue