Remove Typer + ClosureTyper impls for ParameterEnv

This commit is contained in:
Jared Roesch 2015-06-28 23:03:47 -07:00
parent fb295a60b3
commit e2d7e904ca
18 changed files with 60 additions and 117 deletions

View file

@ -111,13 +111,16 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
fn with_euv<'b, F, R>(&'b mut self, item_id: Option<ast::NodeId>, f: F) -> R where
F: for<'t> FnOnce(&mut euv::ExprUseVisitor<'b, 't, 'tcx,
ty::ParameterEnvironment<'a, 'tcx>>) -> R,
infer::InferCtxt<'a, 'tcx>>) -> R,
{
let param_env = match item_id {
Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
None => self.tcx.empty_parameter_environment()
};
f(&mut euv::ExprUseVisitor::new(self, &param_env))
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false);
f(&mut euv::ExprUseVisitor::new(self, &infcx))
}
fn global_expr(&mut self, mode: Mode, expr: &ast::Expr) -> ConstQualif {
@ -287,7 +290,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
match fulfill_cx.select_all_or_error(&infcx, &infcx.parameter_environment) {
match fulfill_cx.select_all_or_error(&infcx, &infcx) {
Ok(()) => { },
Err(ref errors) => {
traits::report_fulfillment_errors(&infcx, errors);

View file

@ -20,6 +20,7 @@ use middle::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Init};
use middle::expr_use_visitor::{JustWrite, LoanCause, MutateMode};
use middle::expr_use_visitor::WriteAndRead;
use middle::expr_use_visitor as euv;
use middle::infer;
use middle::mem_categorization::{cmt, Typer};
use middle::pat_util::*;
use middle::ty::*;
@ -1111,7 +1112,9 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
match p.node {
ast::PatIdent(ast::BindByValue(_), _, ref sub) => {
let pat_ty = tcx.node_id_to_type(p.id);
if cx.param_env.type_moves_by_default(pat_ty, pat.span) {
//FIXME: (@jroesch) this code should be floated up as well
let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, Some(cx.param_env.clone()), false);
if infcx.type_moves_by_default(pat_ty, pat.span) {
check_move(p, sub.as_ref().map(|p| &**p));
}
}
@ -1139,8 +1142,9 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
let mut checker = MutationChecker {
cx: cx,
};
let mut visitor = ExprUseVisitor::new(&mut checker,
&checker.cx.param_env);
let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, Some(checker.cx.param_env.clone()), false);
let mut visitor = ExprUseVisitor::new(&mut checker, &infcx);
visitor.walk_expr(guard);
}

View file

@ -12,6 +12,7 @@
// is the public starting point.
use middle::expr_use_visitor as euv;
use middle::infer;
use middle::mem_categorization as mc;
use middle::ty::ParameterEnvironment;
use middle::ty;
@ -38,9 +39,11 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
s: Span,
fn_id: ast::NodeId) {
{
// FIXME (@jroesch) change this to be an inference context
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &param_env };
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &param_env);
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false);
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &infcx.parameter_environment };
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx);
euv.walk_fn(fd, b);
}
visit::walk_fn(self, fk, fd, b, s)

View file

@ -1033,7 +1033,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id());
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
let mut selcx = traits::SelectionContext::new(&infcx, &infcx.parameter_environment);
let mut selcx = traits::SelectionContext::new(&infcx, &infcx);
let obligation = traits::Obligation::new(traits::ObligationCause::dummy(),
trait_ref.to_poly_trait_predicate());
let selection = match selcx.select(&obligation) {

View file

@ -525,7 +525,7 @@ impl<'a, 'tcx> mc::Typer<'tcx> for InferCtxt<'a, 'tcx> {
}
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<CodeExtent> {
self.parameter_environment.temporary_scope(rvalue_id)
self.tcx.region_maps.temporary_scope(rvalue_id)
}
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {

View file

@ -38,8 +38,7 @@ pub fn overlapping_impls(infcx: &InferCtxt,
impl1_def_id,
impl2_def_id);
let param_env = &infcx.tcx.empty_parameter_environment();
let selcx = &mut SelectionContext::intercrate(infcx, param_env);
let selcx = &mut SelectionContext::intercrate(infcx, infcx);
infcx.probe(|_| {
overlap(selcx, impl1_def_id, impl2_def_id) || overlap(selcx, impl2_def_id, impl1_def_id)
})

View file

@ -398,7 +398,7 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi
let elaborated_env = unnormalized_env.with_caller_bounds(predicates);
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env), false);
let predicates = match fully_normalize(&infcx, &infcx.parameter_environment, cause,
let predicates = match fully_normalize(&infcx, &infcx, cause,
&infcx.parameter_environment.caller_bounds) {
Ok(predicates) => predicates,
Err(errors) => {

View file

@ -52,7 +52,6 @@ use middle::dependency_format;
use middle::fast_reject;
use middle::free_region::FreeRegionMap;
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
use middle::mem_categorization as mc;
use middle::mem_categorization::Typer;
use middle::region;
use middle::resolve_lifetime;
@ -2919,11 +2918,14 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
-> Result<(),CopyImplementationError> {
let tcx = self.tcx;
// FIXME: (@jroesch) float this code up
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(self.clone()), false);
let did = match self_type.sty {
ty::TyStruct(struct_did, substs) => {
let fields = tcx.struct_fields(struct_did, substs);
for field in &fields {
if self.type_moves_by_default(field.mt.ty, span) {
if infcx.type_moves_by_default(field.mt.ty, span) {
return Err(FieldDoesNotImplementCopy(field.name))
}
}
@ -2935,7 +2937,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
for variant_arg_type in &variant.args {
let substd_arg_type =
variant_arg_type.subst(tcx, substs);
if self.type_moves_by_default(substd_arg_type, span) {
if infcx.type_moves_by_default(substd_arg_type, span) {
return Err(VariantDoesNotImplementCopy(variant.name))
}
}
@ -4272,7 +4274,8 @@ impl<'tcx> TyS<'tcx> {
TyClosure(did, substs) => {
// FIXME(#14449): `borrowed_contents` below assumes `&mut` closure.
let param_env = cx.empty_parameter_environment();
let upvars = param_env.closure_upvars(did, substs).unwrap();
let infcx = infer::new_infer_ctxt(cx, &cx.tables, Some(param_env), false);
let upvars = infcx.closure_upvars(did, substs).unwrap();
TypeContents::union(&upvars, |f| tc_ty(cx, &f.ty, cache))
}
@ -4400,10 +4403,10 @@ impl<'tcx> TyS<'tcx> {
span: Span)
-> bool
{
let tcx = param_env.tcx();
let tcx = param_env.tcx;
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env.clone()), false);
let is_impld = traits::type_known_to_meet_builtin_bound(&infcx, param_env,
let is_impld = traits::type_known_to_meet_builtin_bound(&infcx, &infcx,
self, bound, span);
debug!("Ty::impls_bound({:?}, {:?}) = {:?}",
@ -4412,7 +4415,8 @@ impl<'tcx> TyS<'tcx> {
is_impld
}
fn moves_by_default<'a>(&'tcx self, param_env: &ParameterEnvironment<'a,'tcx>,
// temp hack, probably should be private
pub fn moves_by_default<'a>(&'tcx self, param_env: &ParameterEnvironment<'a,'tcx>,
span: Span) -> bool {
if self.flags.get().intersects(TypeFlags::MOVENESS_CACHED) {
return self.flags.get().intersects(TypeFlags::MOVES_BY_DEFAULT);
@ -6711,79 +6715,6 @@ impl<'tcx> ctxt<'tcx> {
}
}
impl<'a,'tcx> Typer<'tcx> for ParameterEnvironment<'a,'tcx> {
fn node_ty(&self, id: ast::NodeId) -> mc::McResult<Ty<'tcx>> {
Ok(self.tcx.node_id_to_type(id))
}
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> mc::McResult<Ty<'tcx>> {
Ok(self.tcx.expr_ty_adjusted(expr))
}
fn node_method_ty(&self, method_call: ty::MethodCall) -> Option<Ty<'tcx>> {
self.tcx.tables.borrow().method_map.get(&method_call).map(|method| method.ty)
}
fn node_method_origin(&self, method_call: ty::MethodCall)
-> Option<ty::MethodOrigin<'tcx>>
{
self.tcx.tables.borrow().method_map.get(&method_call).map(|method| method.origin.clone())
}
fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
fn projection<'a, 'tcx>(tables: &'a Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
&tables.adjustments
}
Ref::map(self.tcx.tables.borrow(), projection)
}
fn is_method_call(&self, id: ast::NodeId) -> bool {
self.tcx.is_method_call(id)
}
fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<region::CodeExtent> {
self.tcx.region_maps.temporary_scope(rvalue_id)
}
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
self.tcx.upvar_capture(upvar_id)
}
fn type_moves_by_default(&self, ty: Ty<'tcx>, span: Span) -> bool {
ty.moves_by_default(self, span)
}
}
impl<'a,'tcx> ClosureTyper<'tcx> for ty::ParameterEnvironment<'a,'tcx> {
fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
self
}
fn closure_kind(&self,
def_id: ast::DefId)
-> Option<ty::ClosureKind>
{
Some(self.tcx.closure_kind(def_id))
}
fn closure_type(&self,
def_id: ast::DefId,
substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'tcx>
{
self.tcx.closure_type(def_id, substs)
}
fn closure_upvars(&self,
def_id: ast::DefId,
substs: &Substs<'tcx>)
-> Option<Vec<ClosureUpvar<'tcx>>> {
ctxt::closure_upvars(self, def_id, substs)
}
}
/// The category of explicit self.
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum ExplicitSelfCategory {