Move typeck into its own crate.

This commit is contained in:
Niko Matsakis 2014-11-26 06:11:29 -05:00
parent e135fa5b49
commit 93eb4333a0
26 changed files with 100 additions and 68 deletions

View File

@ -53,7 +53,7 @@ TARGET_CRATES := libc std flate arena term \
serialize getopts collections test time rand \
log regex graphviz core rbml alloc rustrt \
unicode
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
HOST_CRATES := syntax rustc rustc_typeck rustc_trans rustdoc regex_macros fmt_macros \
rustc_llvm rustc_back
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
@ -67,7 +67,9 @@ DEPS_std := core libc rand alloc collections rustrt unicode \
native:rust_builtin native:backtrace
DEPS_graphviz := std
DEPS_syntax := std term serialize log fmt_macros arena libc
DEPS_rustc_trans := rustc rustc_back rustc_llvm libc
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
rustc_typeck log syntax serialize rustc_llvm
DEPS_rustc_typeck := rustc syntax
DEPS_rustc := syntax flate arena serialize getopts rbml \
time log graphviz rustc_llvm rustc_back
DEPS_rustc_llvm := native:rustllvm libc std
@ -110,8 +112,11 @@ ONLY_RLIB_unicode := 1
# You should not need to edit below this line
################################################################################
DOC_CRATES := $(filter-out rustc, $(filter-out rustc_trans, $(filter-out syntax, $(CRATES))))
COMPILER_DOC_CRATES := rustc rustc_trans syntax
DOC_CRATES := $(filter-out rustc, \
$(filter-out rustc_trans, \
$(filter-out rustc_typeck, \
$(filter-out syntax, $(CRATES)))))
COMPILER_DOC_CRATES := rustc rustc_trans rustc_typeck syntax
# This macro creates some simple definitions for each crate being built, just
# some munging of all of the parameters above.

View File

@ -98,9 +98,6 @@ pub mod middle {
pub mod weak_lang_items;
}
#[path="middle/typeck/mod.rs"]
pub mod typeck;
pub mod metadata;
pub mod session;

View File

@ -20,7 +20,7 @@ use middle;
use plugin::load::Plugins;
use plugin::registry::Registry;
use plugin;
use rustc::typeck;
use rustc_typeck as typeck;
use trans;
use util::common::time;

View File

@ -32,6 +32,7 @@ extern crate getopts;
extern crate graphviz;
extern crate libc;
extern crate rustc;
extern crate rustc_typeck;
extern crate rustc_back;
#[phase(plugin, link)] extern crate log;
#[phase(plugin, link)] extern crate syntax;

View File

@ -54,10 +54,9 @@ 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 typeck::lookup_def_tcx;
use typeck::rscope::{mod, UnelidableRscope, RegionScope, SpecificRscope,
ShiftedRscope, BindingRscope};
use typeck::TypeAndSubsts;
use rscope::{mod, UnelidableRscope, RegionScope, SpecificRscope,
ShiftedRscope, BindingRscope};
use TypeAndSubsts;
use util::common::ErrorReported;
use util::nodemap::DefIdMap;
use util::ppaux::{mod, Repr, UserString};
@ -429,9 +428,9 @@ pub fn instantiate_trait_ref<'tcx,AC,RS>(this: &AC,
where AC: AstConv<'tcx>,
RS: RegionScope
{
match lookup_def_tcx(this.tcx(),
ast_trait_ref.path.span,
ast_trait_ref.ref_id) {
match ::lookup_def_tcx(this.tcx(),
ast_trait_ref.path.span,
ast_trait_ref.ref_id) {
def::DefTrait(trait_def_id) => {
let trait_ref = Rc::new(ast_path_to_trait_ref(this, rscope, trait_def_id,
self_ty, &ast_trait_ref.path));
@ -1477,7 +1476,7 @@ pub fn partition_bounds<'a>(tcx: &ty::ctxt,
for &ast_bound in ast_bounds.iter() {
match *ast_bound {
ast::TraitTyParamBound(ref b) => {
match lookup_def_tcx(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
match ::lookup_def_tcx(tcx, b.trait_ref.path.span, b.trait_ref.ref_id) {
def::DefTrait(trait_did) => {
match trait_def_ids.get(&trait_did) {
// Already seen this trait. We forbid

View File

@ -9,13 +9,13 @@
// except according to those terms.
use middle::def;
use middle::infer::{mod, resolve};
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 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 typeck::require_same_types;
use check::{check_expr, check_expr_has_type, demand, FnCtxt};
use check::{instantiate_path, structurally_resolved_type, valid_range_bounds};
use require_same_types;
use util::nodemap::FnvHashMap;
use std::cmp;

View File

@ -14,11 +14,11 @@ use super::check_fn;
use super::{Expectation, ExpectCastableToType, ExpectHasType, NoExpectation};
use super::FnCtxt;
use astconv;
use middle::infer;
use middle::subst;
use middle::ty::{mod, Ty};
use typeck::astconv;
use typeck::rscope::RegionScope;
use rscope::RegionScope;
use syntax::abi;
use syntax::ast;
use syntax::ast_util;

View File

@ -9,8 +9,8 @@
// except according to those terms.
use check::FnCtxt;
use middle::ty::{mod, Ty};
use typeck::check::FnCtxt;
use middle::infer;
use middle::infer::resolve_type;
use middle::infer::resolve::try_resolve_tvar_shallow;

View File

@ -10,12 +10,12 @@
use super::probe;
use check::{mod, FnCtxt, NoPreference, PreferMutLvalue};
use middle::subst::{mod, Subst};
use middle::traits;
use middle::ty::{mod, Ty};
use middle::ty::{MethodCall, MethodCallee, MethodObject, MethodOrigin,
MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam};
use typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue};
use middle::infer;
use middle::infer::InferCtxt;
use middle::ty_fold::HigherRankedFoldable;

View File

@ -10,16 +10,16 @@
//! Method lookup: the secret sauce of Rust. See `doc.rs`.
use astconv::AstConv;
use check::{FnCtxt};
use check::{impl_self_ty};
use check::vtable;
use check::vtable::select_new_fcx_obligations;
use middle::subst;
use middle::subst::{Subst};
use middle::traits;
use middle::ty::*;
use middle::ty;
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

@ -12,6 +12,8 @@ use super::{MethodError,Ambiguity,NoMatch};
use super::MethodIndex;
use super::{CandidateSource,ImplSource,TraitSource};
use check;
use check::{FnCtxt, NoPreference};
use middle::fast_reject;
use middle::subst;
use middle::subst::Subst;
@ -19,8 +21,6 @@ use middle::traits;
use middle::ty::{mod, Ty};
use middle::ty::{MethodObject};
use middle::ty_fold::HigherRankedFoldable;
use typeck::check;
use typeck::check::{FnCtxt, NoPreference};
use middle::infer;
use middle::infer::InferCtxt;
use syntax::ast;

View File

@ -31,7 +31,7 @@ can be broken down into several distinct phases:
In the process of checking, various constraints will be placed on
these type variables through the subtyping relationships requested
through the `demand` module. The `typeck::infer` module is in charge
through the `demand` module. The `infer` module is in charge
of resolving those constraints.
- regionck: after main is complete, the regionck pass goes over all
@ -82,7 +82,8 @@ pub use self::Expectation::*;
use self::IsBinopAssignment::*;
use self::TupleArgumentsFlag::*;
use session::Session;
use astconv::{mod, ast_region_to_region, ast_ty_to_ty, AstConv};
use check::_match::pat_ctxt;
use middle::{const_eval, def, traits};
use middle::infer;
use middle::lang_items::IteratorItem;
@ -96,11 +97,10 @@ 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 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 rscope::RegionScope;
use session::Session;
use {CrateCtxt, lookup_def_ccx, no_params, require_same_types};
use TypeAndSubsts;
use middle::lang_items::TypeIdLangItem;
use lint;
use util::common::{block_query, indenter, loop_query};

View File

@ -114,16 +114,16 @@
//! then mean that all later passes would have to check for these figments
//! and report an error, and it just seems like more mess in the end.)
use astconv::AstConv;
use check::FnCtxt;
use check::regionmanip;
use check::vtable;
use middle::def;
use middle::mem_categorization as mc;
use middle::region::CodeExtent;
use middle::traits;
use middle::ty::{ReScope};
use middle::ty::{mod, Ty, MethodCall};
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

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use check::{FnCtxt, structurally_resolved_type};
use middle::subst::{SelfSpace, FnSpace};
use middle::traits;
use middle::traits::{SelectionError, OutputTypeParameterMismatch, Overflow, Unimplemented};
@ -15,8 +16,6 @@ use middle::traits::{Obligation, obligation_for_builtin_bound};
use middle::traits::{FulfillmentError, CodeSelectionError, CodeAmbiguity};
use middle::traits::{ObligationCause};
use middle::ty::{mod, Ty};
use typeck::check::{FnCtxt,
structurally_resolved_type};
use middle::infer;
use std::rc::Rc;
use syntax::ast;

View File

@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use astconv::AstConv;
use check::{FnCtxt, Inherited, blank_fn_ctxt, vtable, regionck};
use CrateCtxt;
use middle::region;
use middle::subst;
use middle::subst::{Subst};
@ -15,9 +18,6 @@ use middle::traits;
use middle::ty::{mod, Ty};
use middle::ty::liberate_late_bound_regions;
use middle::ty_fold::{TypeFolder, TypeFoldable};
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

@ -13,17 +13,17 @@
// substitutions.
use self::ResolveReason::*;
use astconv::AstConv;
use check::FnCtxt;
use middle::def;
use middle::pat_util;
use middle::ty::{mod, Ty, MethodCall, MethodCallee};
use middle::ty_fold::{TypeFolder,TypeFoldable};
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 typeck::write_substs_to_tcx;
use typeck::write_ty_to_tcx;
use write_substs_to_tcx;
use write_ty_to_tcx;
use util::ppaux::Repr;
use std::cell::Cell;

View File

@ -30,7 +30,7 @@ use middle::ty::{ty_closure};
use middle::ty::type_is_ty_var;
use middle::subst::Subst;
use middle::ty;
use typeck::CrateCtxt;
use CrateCtxt;
use middle::infer::combine::Combine;
use middle::infer::InferCtxt;
use middle::infer::{new_infer_ctxt, resolve_ivar, resolve_type};

View File

@ -32,6 +32,9 @@ as `ty_param()` instances.
use self::ConvertMethodContext::*;
use self::CreateTypeParametersForAssociatedTypesFlag::*;
use astconv::{AstConv, ty_of_arg};
use astconv::{ast_ty_to_ty, ast_region_to_region};
use astconv;
use metadata::csearch;
use middle::def;
use middle::lang_items::SizedTraitLangItem;
@ -43,13 +46,9 @@ use middle::ty::{ImplContainer, ImplOrTraitItemContainer, TraitContainer};
use middle::ty::{Polytype};
use middle::ty::{mod, Ty};
use middle::ty_fold::TypeFolder;
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 typeck::rscope::*;
use typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
use typeck;
use rscope::*;
use {CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx};
use util::nodemap::{FnvHashMap, FnvHashSet};
use util::ppaux;
use util::ppaux::{Repr,UserString};
@ -2159,13 +2158,13 @@ fn check_method_self_type<'a, 'tcx, RS:RegionScope>(
base_type.repr(crate_context.tcx),
base_type_free.repr(crate_context.tcx));
let infcx = infer::new_infer_ctxt(crate_context.tcx);
drop(typeck::require_same_types(crate_context.tcx,
Some(&infcx),
false,
explicit_self.span,
base_type_free,
required_type_free,
|| {
drop(::require_same_types(crate_context.tcx,
Some(&infcx),
false,
explicit_self.span,
base_type_free,
required_type_free,
|| {
format!("mismatched self type: expected `{}`",
ppaux::ty_to_string(crate_context.tcx, required_type))
}));

View File

@ -145,5 +145,7 @@ register_diagnostics!(
E0166,
E0167,
E0168,
E0169
E0169,
E0171,
E0172
)

View File

@ -1,4 +1,4 @@
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/*
/*!
typeck.rs, an introduction
@ -57,10 +57,37 @@ independently:
all subtyping and assignment constraints are met. In essence, the check
module specifies the constraints, and the infer module solves them.
# Note
This API is completely unstable and subject to change.
*/
#![crate_name = "rustc_typeck"]
#![experimental]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(default_type_params, globs, if_let, import_shadowing, macro_rules, phase, quote)]
#![feature(slicing_syntax, tuple_indexing, unsafe_destructor)]
#![feature(rustc_diagnostic_macros)]
#![allow(non_camel_case_types)]
#[phase(plugin, link)] extern crate log;
#[phase(plugin, link)] extern crate syntax;
extern crate arena;
extern crate rustc;
pub use rustc::lint;
pub use rustc::metadata;
pub use rustc::middle;
pub use rustc::session;
pub use rustc::util;
use middle::def;
use middle::resolve;
use middle::infer;
@ -76,6 +103,9 @@ use syntax::codemap::Span;
use syntax::print::pprust::*;
use syntax::{ast, ast_map, abi};
#[cfg(stage0)]
mod diagnostics;
mod check;
mod rscope;
mod astconv;