Move typeck logically in the module tree out to the root and clamp

down on its exports. Remove some dead code that is revealed.
This commit is contained in:
Niko Matsakis 2014-11-26 05:48:57 -05:00
parent 55470abe72
commit 1e112e94c3
19 changed files with 89 additions and 107 deletions

View file

@ -95,10 +95,12 @@ pub mod middle {
pub mod traits;
pub mod ty;
pub mod ty_fold;
pub mod typeck;
pub mod weak_lang_items;
}
#[path="middle/typeck/mod.rs"]
pub mod typeck;
pub mod metadata;
pub mod session;

View file

@ -6192,3 +6192,29 @@ impl<'tcx> Repr<'tcx> for vtable_origin<'tcx> {
}
}
}
pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>,
trait_ref: &ty::TraitRef<'tcx>,
method: &ty::Method<'tcx>)
-> subst::Substs<'tcx>
{
/*!
* Substitutes the values for the receiver's type parameters
* that are found in method, leaving the method's type parameters
* intact.
*/
let meth_tps: Vec<Ty> =
method.generics.types.get_slice(subst::FnSpace)
.iter()
.map(|def| ty::mk_param_from_def(tcx, def))
.collect();
let meth_regions: Vec<ty::Region> =
method.generics.regions.get_slice(subst::FnSpace)
.iter()
.map(|def| ty::ReEarlyBound(def.def_id.node, def.space,
def.index, def.name))
.collect();
trait_ref.substs.clone().with_method(meth_tps, meth_regions)
}

View file

@ -54,11 +54,10 @@ use middle::resolve_lifetime as rl;
use middle::subst::{FnSpace, TypeSpace, AssocSpace, SelfSpace, Subst, Substs};
use middle::subst::{VecPerParamSpace};
use middle::ty::{mod, Ty};
use middle::typeck::lookup_def_tcx;
use middle::typeck::rscope::{UnelidableRscope, RegionScope, SpecificRscope,
ShiftedRscope, BindingRscope};
use middle::typeck::rscope;
use middle::typeck::TypeAndSubsts;
use typeck::lookup_def_tcx;
use typeck::rscope::{mod, UnelidableRscope, RegionScope, SpecificRscope,
ShiftedRscope, BindingRscope};
use typeck::TypeAndSubsts;
use util::common::ErrorReported;
use util::nodemap::DefIdMap;
use util::ppaux::{mod, Repr, UserString};

View file

@ -12,10 +12,10 @@ use middle::def;
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding, pat_is_const};
use middle::subst::{Subst, Substs};
use middle::ty::{mod, Ty};
use middle::typeck::check::{check_expr, check_expr_has_type, demand, FnCtxt};
use middle::typeck::check::{instantiate_path, structurally_resolved_type, valid_range_bounds};
use typeck::check::{check_expr, check_expr_has_type, demand, FnCtxt};
use typeck::check::{instantiate_path, structurally_resolved_type, valid_range_bounds};
use middle::infer::{mod, resolve};
use middle::typeck::require_same_types;
use typeck::require_same_types;
use util::nodemap::FnvHashMap;
use std::cmp;

View file

@ -17,8 +17,8 @@ use super::FnCtxt;
use middle::infer;
use middle::subst;
use middle::ty::{mod, Ty};
use middle::typeck::astconv;
use middle::typeck::rscope::RegionScope;
use typeck::astconv;
use typeck::rscope::RegionScope;
use syntax::abi;
use syntax::ast;
use syntax::ast_util;

View file

@ -10,7 +10,7 @@
use middle::ty::{mod, Ty};
use middle::typeck::check::FnCtxt;
use typeck::check::FnCtxt;
use middle::infer;
use middle::infer::resolve_type;
use middle::infer::resolve::try_resolve_tvar_shallow;
@ -29,12 +29,6 @@ pub fn suptype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
}
pub fn subtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
expected: Ty<'tcx>, actual: Ty<'tcx>) {
suptype_with_fn(fcx, sp, true, actual, expected,
|sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) })
}
pub fn suptype_with_fn<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
sp: Span,
b_is_expected: bool,

View file

@ -15,7 +15,7 @@ use middle::traits;
use middle::ty::{mod, Ty};
use middle::ty::{MethodCall, MethodCallee, MethodObject, MethodOrigin,
MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam};
use middle::typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue};
use typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue};
use middle::infer;
use middle::infer::InferCtxt;
use middle::ty_fold::HigherRankedFoldable;

View file

@ -15,11 +15,11 @@ use middle::subst::{Subst};
use middle::traits;
use middle::ty::*;
use middle::ty;
use middle::typeck::astconv::AstConv;
use middle::typeck::check::{FnCtxt};
use middle::typeck::check::{impl_self_ty};
use middle::typeck::check::vtable;
use middle::typeck::check::vtable::select_new_fcx_obligations;
use typeck::astconv::AstConv;
use typeck::check::{FnCtxt};
use typeck::check::{impl_self_ty};
use typeck::check::vtable;
use typeck::check::vtable::select_new_fcx_obligations;
use middle::infer;
use util::ppaux::{Repr, UserString};

View file

@ -19,8 +19,8 @@ use middle::traits;
use middle::ty::{mod, Ty};
use middle::ty::{MethodObject};
use middle::ty_fold::HigherRankedFoldable;
use middle::typeck::check;
use middle::typeck::check::{FnCtxt, NoPreference};
use typeck::check;
use typeck::check::{FnCtxt, NoPreference};
use middle::infer;
use middle::infer::InferCtxt;
use syntax::ast;

View file

@ -96,11 +96,11 @@ use middle::ty::{mod, Ty};
use middle::ty::liberate_late_bound_regions;
use middle::ty::{MethodCall, MethodCallee, MethodMap, ObjectCastMap};
use middle::ty_fold::TypeFolder;
use middle::typeck::astconv::{mod, ast_region_to_region, ast_ty_to_ty, AstConv};
use middle::typeck::check::_match::pat_ctxt;
use middle::typeck::rscope::RegionScope;
use middle::typeck::{CrateCtxt, lookup_def_ccx, no_params, require_same_types};
use middle::typeck::TypeAndSubsts;
use typeck::astconv::{mod, ast_region_to_region, ast_ty_to_ty, AstConv};
use typeck::check::_match::pat_ctxt;
use typeck::rscope::RegionScope;
use typeck::{CrateCtxt, lookup_def_ccx, no_params, require_same_types};
use typeck::TypeAndSubsts;
use middle::lang_items::TypeIdLangItem;
use lint;
use util::common::{block_query, indenter, loop_query};
@ -1873,13 +1873,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
/// Fetch type of `expr` after applying adjustments that have been recorded in the fcx.
pub fn expr_ty_adjusted(&self, expr: &ast::Expr) -> Ty<'tcx> {
let adjustments = self.inh.adjustments.borrow();
let adjustment = adjustments.get(&expr.id);
self.adjust_expr_ty(expr, adjustment)
}
/// Apply `adjustment` to the type of `expr`
pub fn adjust_expr_ty(&self,
expr: &ast::Expr,
@ -1932,16 +1925,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
infer::mk_subty(self.infcx(), a_is_expected, origin, sub, sup)
}
pub fn can_mk_subty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>)
-> Result<(), ty::type_err<'tcx>> {
infer::can_mk_subty(self.infcx(), sub, sup)
}
pub fn can_mk_eqty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>)
-> Result<(), ty::type_err<'tcx>> {
infer::can_mk_eqty(self.infcx(), sub, sup)
}
pub fn mk_assignty(&self,
expr: &ast::Expr,
sub: Ty<'tcx>,

View file

@ -120,10 +120,10 @@ use middle::region::CodeExtent;
use middle::traits;
use middle::ty::{ReScope};
use middle::ty::{mod, Ty, MethodCall};
use middle::typeck::astconv::AstConv;
use middle::typeck::check::FnCtxt;
use middle::typeck::check::regionmanip;
use middle::typeck::check::vtable;
use typeck::astconv::AstConv;
use typeck::check::FnCtxt;
use typeck::check::regionmanip;
use typeck::check::vtable;
use middle::infer::resolve_and_force_all_but_regions;
use middle::infer::resolve_type;
use middle::infer;

View file

@ -15,7 +15,7 @@ use middle::traits::{Obligation, obligation_for_builtin_bound};
use middle::traits::{FulfillmentError, CodeSelectionError, CodeAmbiguity};
use middle::traits::{ObligationCause};
use middle::ty::{mod, Ty};
use middle::typeck::check::{FnCtxt,
use typeck::check::{FnCtxt,
structurally_resolved_type};
use middle::infer;
use std::rc::Rc;

View file

@ -15,9 +15,9 @@ use middle::traits;
use middle::ty::{mod, Ty};
use middle::ty::liberate_late_bound_regions;
use middle::ty_fold::{TypeFolder, TypeFoldable};
use middle::typeck::astconv::AstConv;
use middle::typeck::check::{FnCtxt, Inherited, blank_fn_ctxt, vtable, regionck};
use middle::typeck::CrateCtxt;
use typeck::astconv::AstConv;
use typeck::check::{FnCtxt, Inherited, blank_fn_ctxt, vtable, regionck};
use typeck::CrateCtxt;
use util::ppaux::Repr;
use std::collections::HashSet;

View file

@ -17,13 +17,13 @@ use middle::def;
use middle::pat_util;
use middle::ty::{mod, Ty, MethodCall, MethodCallee};
use middle::ty_fold::{TypeFolder,TypeFoldable};
use middle::typeck::astconv::AstConv;
use middle::typeck::check::FnCtxt;
use typeck::astconv::AstConv;
use typeck::check::FnCtxt;
use middle::infer::{force_all, resolve_all, resolve_region};
use middle::infer::resolve_type;
use middle::infer;
use middle::typeck::write_substs_to_tcx;
use middle::typeck::write_ty_to_tcx;
use typeck::write_substs_to_tcx;
use typeck::write_ty_to_tcx;
use util::ppaux::Repr;
use std::cell::Cell;

View file

@ -19,7 +19,6 @@
use metadata::csearch::{each_impl, get_impl_trait};
use metadata::csearch;
use middle::subst;
use middle::subst::{Substs};
use middle::ty::{ImplContainer, ImplOrTraitItemId, MethodTraitItemId};
use middle::ty::{TypeTraitItemId, lookup_item_type};
use middle::ty::{Ty, ty_bool, ty_char, ty_enum, ty_err};
@ -31,7 +30,7 @@ use middle::ty::{ty_closure};
use middle::ty::type_is_ty_var;
use middle::subst::Subst;
use middle::ty;
use middle::typeck::CrateCtxt;
use typeck::CrateCtxt;
use middle::infer::combine::Combine;
use middle::infer::InferCtxt;
use middle::infer::{new_infer_ctxt, resolve_ivar, resolve_type};
@ -477,27 +476,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
}
}
/// Substitutes the values for the receiver's type parameters that are found in method, leaving the
/// method's type parameters intact.
pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>,
trait_ref: &ty::TraitRef<'tcx>,
method: &ty::Method<'tcx>)
-> subst::Substs<'tcx>
{
let meth_tps: Vec<Ty> =
method.generics.types.get_slice(subst::FnSpace)
.iter()
.map(|def| ty::mk_param_from_def(tcx, def))
.collect();
let meth_regions: Vec<ty::Region> =
method.generics.regions.get_slice(subst::FnSpace)
.iter()
.map(|def| ty::ReEarlyBound(def.def_id.node, def.space,
def.index, def.name))
.collect();
trait_ref.substs.clone().with_method(meth_tps, meth_regions)
}
fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
impl_id: ast::DefId,
impl_poly_type: &ty::Polytype<'tcx>,
@ -507,7 +485,7 @@ fn subst_receiver_types_in_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
provided_source: Option<ast::DefId>)
-> ty::Method<'tcx>
{
let combined_substs = make_substs_for_receiver_types(tcx, trait_ref, method);
let combined_substs = ty::make_substs_for_receiver_types(tcx, trait_ref, method);
debug!("subst_receiver_types_in_method_ty: combined_substs={}",
combined_substs.repr(tcx));

View file

@ -43,13 +43,13 @@ use middle::ty::{ImplContainer, ImplOrTraitItemContainer, TraitContainer};
use middle::ty::{Polytype};
use middle::ty::{mod, Ty};
use middle::ty_fold::TypeFolder;
use middle::typeck::astconv::{AstConv, ty_of_arg};
use middle::typeck::astconv::{ast_ty_to_ty, ast_region_to_region};
use middle::typeck::astconv;
use typeck::astconv::{AstConv, ty_of_arg};
use typeck::astconv::{ast_ty_to_ty, ast_region_to_region};
use typeck::astconv;
use middle::infer;
use middle::typeck::rscope::*;
use middle::typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
use middle::typeck;
use typeck::rscope::*;
use typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
use typeck;
use util::nodemap::{FnvHashMap, FnvHashSet};
use util::ppaux;
use util::ppaux::{Repr,UserString};

View file

@ -76,32 +76,32 @@ use syntax::codemap::Span;
use syntax::print::pprust::*;
use syntax::{ast, ast_map, abi};
pub mod check;
pub mod rscope;
pub mod astconv;
pub mod collect;
pub mod coherence;
pub mod variance;
mod check;
mod rscope;
mod astconv;
mod collect;
mod coherence;
mod variance;
pub struct TypeAndSubsts<'tcx> {
struct TypeAndSubsts<'tcx> {
pub substs: subst::Substs<'tcx>,
pub ty: Ty<'tcx>,
}
pub struct CrateCtxt<'a, 'tcx: 'a> {
struct CrateCtxt<'a, 'tcx: 'a> {
// A mapping from method call sites to traits that have that method.
trait_map: resolve::TraitMap,
tcx: &'a ty::ctxt<'tcx>
}
// Functions that write types into the node type table
pub fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) {
fn write_ty_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>, node_id: ast::NodeId, ty: Ty<'tcx>) {
debug!("write_ty_to_tcx({}, {})", node_id, ppaux::ty_to_string(tcx, ty));
assert!(!ty::type_needs_infer(ty));
tcx.node_types.borrow_mut().insert(node_id, ty);
}
pub fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
node_id: ast::NodeId,
item_substs: ty::ItemSubsts<'tcx>) {
if !item_substs.is_noop() {
@ -114,7 +114,7 @@ pub fn write_substs_to_tcx<'tcx>(tcx: &ty::ctxt<'tcx>,
tcx.item_substs.borrow_mut().insert(node_id, item_substs);
}
}
pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
match tcx.def_map.borrow().get(&id) {
Some(x) => x.clone(),
_ => {
@ -123,12 +123,12 @@ pub fn lookup_def_tcx(tcx:&ty::ctxt, sp: Span, id: ast::NodeId) -> def::Def {
}
}
pub fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
fn lookup_def_ccx(ccx: &CrateCtxt, sp: Span, id: ast::NodeId)
-> def::Def {
lookup_def_tcx(ccx.tcx, sp, id)
}
pub fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> {
fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> {
ty::Polytype {
generics: ty::Generics {types: VecPerParamSpace::empty(),
regions: VecPerParamSpace::empty()},
@ -136,7 +136,7 @@ pub fn no_params<'tcx>(t: Ty<'tcx>) -> ty::Polytype<'tcx> {
}
}
pub fn require_same_types<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
fn require_same_types<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
maybe_infcx: Option<&infer::InferCtxt<'a, 'tcx>>,
t1_is_expected: bool,
span: Span,

View file

@ -18,12 +18,13 @@ use lint;
use llvm::{ContextRef, ModuleRef};
use metadata::common::LinkMeta;
use metadata::creader;
use middle::{stability, ty, typeck, reachable};
use middle::{stability, ty, reachable};
use middle::dependency_format;
use middle;
use plugin::load::Plugins;
use plugin::registry::Registry;
use plugin;
use rustc::typeck;
use trans;
use util::common::time;

View file

@ -50,7 +50,6 @@ use trans::type_::Type;
use trans::type_of;
use middle::ty::{mod, Ty};
use middle::ty::MethodCall;
use middle::typeck::coherence::make_substs_for_receiver_types;
use util::ppaux::Repr;
use util::ppaux::ty_to_string;
@ -573,7 +572,7 @@ pub fn trans_fn_ref_with_substs<'blk, 'tcx>(
// Compute the first substitution
let first_subst =
make_substs_for_receiver_types(tcx, &*trait_ref, &*method)
ty::make_substs_for_receiver_types(tcx, &*trait_ref, &*method)
.erase_regions();
// And compose them