Skip to content
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

Separate typeck/trans into distinct crates. #19362

Merged
merged 15 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move typeck logically in the module tree out to the root and clamp
down on its exports. Remove some dead code that is revealed.
  • Loading branch information
nikomatsakis committed Dec 4, 2014
commit 1e112e94c3cd71f792e59318f7f7197999e30cf6
4 changes: 3 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

9 changes: 4 additions & 5 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions src/librustc/middle/typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/typeck/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 5 additions & 22 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/typeck/check/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 2 additions & 24 deletions src/librustc/middle/typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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};
Expand Down Expand Up @@ -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>,
Expand All @@ -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));
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
30 changes: 15 additions & 15 deletions src/librustc/middle/typeck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

pub struct TypeAndSubsts<'tcx> {
mod check;
mod rscope;
mod astconv;
mod collect;
mod coherence;
mod variance;

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() {
Expand All @@ -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(),
_ => {
Expand All @@ -123,20 +123,20 @@ 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()},
ty: t
}
}

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,
Expand Down
Loading