1
Fork 0

Change list of predicates in ParameterEnvironment to a Vec.

This commit is contained in:
Niko Matsakis 2015-01-26 16:37:45 -05:00
parent a530cc9706
commit c73a1d0a2c
7 changed files with 17 additions and 18 deletions

View file

@ -126,7 +126,7 @@ fn trait_has_sized_self<'tcx>(tcx: &ty::ctxt<'tcx>,
let param_env = ty::construct_parameter_environment(tcx, let param_env = ty::construct_parameter_environment(tcx,
&trait_def.generics, &trait_def.generics,
ast::DUMMY_NODE_ID); ast::DUMMY_NODE_ID);
let predicates = param_env.caller_bounds.predicates.as_slice().to_vec(); let predicates = param_env.caller_bounds.clone();
let sized_def_id = match tcx.lang_items.sized_trait() { let sized_def_id = match tcx.lang_items.sized_trait() {
Some(def_id) => def_id, Some(def_id) => def_id,
None => { return false; /* No Sized trait, can't require it! */ } None => { return false; /* No Sized trait, can't require it! */ }

View file

@ -440,8 +440,7 @@ fn assemble_candidates_from_param_env<'cx,'tcx>(
obligation_trait_ref: &Rc<ty::TraitRef<'tcx>>, obligation_trait_ref: &Rc<ty::TraitRef<'tcx>>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>) candidate_set: &mut ProjectionTyCandidateSet<'tcx>)
{ {
let env_predicates = selcx.param_env().caller_bounds.predicates.clone(); let env_predicates = selcx.param_env().caller_bounds.clone();
let env_predicates = env_predicates.iter().cloned().collect();
assemble_candidates_from_predicates(selcx, obligation, obligation_trait_ref, assemble_candidates_from_predicates(selcx, obligation, obligation_trait_ref,
candidate_set, env_predicates); candidate_set, env_predicates);
} }

View file

@ -951,7 +951,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
stack.obligation.repr(self.tcx())); stack.obligation.repr(self.tcx()));
let caller_trait_refs: Vec<_> = let caller_trait_refs: Vec<_> =
self.param_env().caller_bounds.predicates.iter() self.param_env().caller_bounds.iter()
.filter_map(|o| o.to_opt_poly_trait_ref()) .filter_map(|o| o.to_opt_poly_trait_ref())
.collect(); .collect();

View file

@ -2100,7 +2100,7 @@ pub struct ParameterEnvironment<'a, 'tcx:'a> {
/// Obligations that the caller must satisfy. This is basically /// Obligations that the caller must satisfy. This is basically
/// the set of bounds on the in-scope type parameters, translated /// the set of bounds on the in-scope type parameters, translated
/// into Obligations. /// into Obligations.
pub caller_bounds: ty::GenericBounds<'tcx>, pub caller_bounds: Vec<ty::Predicate<'tcx>>,
/// Caches the results of trait selection. This cache is used /// Caches the results of trait selection. This cache is used
/// for things that have to do with the parameters in scope. /// for things that have to do with the parameters in scope.
@ -6258,7 +6258,7 @@ impl Variance {
pub fn empty_parameter_environment<'a,'tcx>(cx: &'a ctxt<'tcx>) -> ParameterEnvironment<'a,'tcx> { pub fn empty_parameter_environment<'a,'tcx>(cx: &'a ctxt<'tcx>) -> ParameterEnvironment<'a,'tcx> {
ty::ParameterEnvironment { tcx: cx, ty::ParameterEnvironment { tcx: cx,
free_substs: Substs::empty(), free_substs: Substs::empty(),
caller_bounds: GenericBounds::empty(), caller_bounds: Vec::new(),
implicit_region_bound: ty::ReEmpty, implicit_region_bound: ty::ReEmpty,
selection_cache: traits::SelectionCache::new(), } selection_cache: traits::SelectionCache::new(), }
} }
@ -6296,6 +6296,7 @@ pub fn construct_parameter_environment<'a,'tcx>(
let bounds = generics.to_bounds(tcx, &free_substs); let bounds = generics.to_bounds(tcx, &free_substs);
let bounds = liberate_late_bound_regions(tcx, free_id_scope, &ty::Binder(bounds)); let bounds = liberate_late_bound_regions(tcx, free_id_scope, &ty::Binder(bounds));
let predicates = bounds.predicates.into_vec();
// //
// Compute region bounds. For now, these relations are stored in a // Compute region bounds. For now, these relations are stored in a
@ -6303,18 +6304,18 @@ pub fn construct_parameter_environment<'a,'tcx>(
// crazy about this scheme, but it's convenient, at least. // crazy about this scheme, but it's convenient, at least.
// //
record_region_bounds(tcx, &bounds); record_region_bounds(tcx, &*predicates);
debug!("construct_parameter_environment: free_id={:?} free_subst={:?} bounds={:?}", debug!("construct_parameter_environment: free_id={:?} free_subst={:?} predicates={:?}",
free_id, free_id,
free_substs.repr(tcx), free_substs.repr(tcx),
bounds.repr(tcx)); predicates.repr(tcx));
return ty::ParameterEnvironment { return ty::ParameterEnvironment {
tcx: tcx, tcx: tcx,
free_substs: free_substs, free_substs: free_substs,
implicit_region_bound: ty::ReScope(free_id_scope), implicit_region_bound: ty::ReScope(free_id_scope),
caller_bounds: bounds, caller_bounds: predicates,
selection_cache: traits::SelectionCache::new(), selection_cache: traits::SelectionCache::new(),
}; };
@ -6338,10 +6339,10 @@ pub fn construct_parameter_environment<'a,'tcx>(
} }
} }
fn record_region_bounds<'tcx>(tcx: &ty::ctxt<'tcx>, bounds: &GenericBounds<'tcx>) { fn record_region_bounds<'tcx>(tcx: &ty::ctxt<'tcx>, predicates: &[ty::Predicate<'tcx>]) {
debug!("record_region_bounds(bounds={:?})", bounds.repr(tcx)); debug!("record_region_bounds(predicates={:?})", predicates.repr(tcx));
for predicate in bounds.predicates.iter() { for predicate in predicates.iter() {
match *predicate { match *predicate {
Predicate::Projection(..) | Predicate::Projection(..) |
Predicate::Trait(..) | Predicate::Trait(..) |

View file

@ -245,7 +245,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
let mut trait_param_env = impl_param_env.clone(); let mut trait_param_env = impl_param_env.clone();
// The key step here is to update the caller_bounds's predicates to be // The key step here is to update the caller_bounds's predicates to be
// the new hybrid bounds we computed. // the new hybrid bounds we computed.
trait_param_env.caller_bounds.predicates = hybrid_preds; trait_param_env.caller_bounds = hybrid_preds.into_vec();
debug!("compare_impl_method: trait_bounds={}", debug!("compare_impl_method: trait_bounds={}",
trait_param_env.caller_bounds.repr(tcx)); trait_param_env.caller_bounds.repr(tcx));

View file

@ -343,7 +343,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
// FIXME -- Do we want to commit to this behavior for param bounds? // FIXME -- Do we want to commit to this behavior for param bounds?
let bounds: Vec<_> = let bounds: Vec<_> =
self.fcx.inh.param_env.caller_bounds.predicates self.fcx.inh.param_env.caller_bounds
.iter() .iter()
.filter_map(|predicate| { .filter_map(|predicate| {
match *predicate { match *predicate {
@ -697,8 +697,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
debug!("assemble_where_clause_candidates(trait_def_id={})", debug!("assemble_where_clause_candidates(trait_def_id={})",
trait_def_id.repr(self.tcx())); trait_def_id.repr(self.tcx()));
let caller_predicates = let caller_predicates = self.fcx.inh.param_env.caller_bounds.clone();
self.fcx.inh.param_env.caller_bounds.predicates.as_slice().to_vec();
for poly_bound in traits::elaborate_predicates(self.tcx(), caller_predicates) for poly_bound in traits::elaborate_predicates(self.tcx(), caller_predicates)
.filter_map(|p| p.to_opt_poly_trait_ref()) .filter_map(|p| p.to_opt_poly_trait_ref())
.filter(|b| b.def_id() == trait_def_id) .filter(|b| b.def_id() == trait_def_id)

View file

@ -1482,7 +1482,7 @@ fn generic_must_outlive<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
let mut param_bounds = let mut param_bounds =
ty::required_region_bounds(rcx.tcx(), ty::required_region_bounds(rcx.tcx(),
generic.to_ty(rcx.tcx()), generic.to_ty(rcx.tcx()),
param_env.caller_bounds.predicates.as_slice().to_vec()); param_env.caller_bounds.clone());
// In the case of a projection T::Foo, we may be able to extract bounds from the trait def: // In the case of a projection T::Foo, we may be able to extract bounds from the trait def:
match *generic { match *generic {