diff --git a/mk/crates.mk b/mk/crates.mk index 77cea02f43b73..3a2def389cc24 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -53,8 +53,8 @@ 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 \ - rustc_llvm rustc_back +RUSTC_CRATES := rustc rustc_typeck rustc_driver rustc_trans rustc_back rustc_llvm +HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc regex_macros fmt_macros CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustdoc rustc @@ -67,12 +67,16 @@ 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_driver := arena flate getopts graphviz libc rustc rustc_back \ + rustc_typeck log syntax serialize rustc_llvm rustc_trans +DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \ + 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 DEPS_rustc_back := std syntax rustc_llvm flate log libc -DEPS_rustdoc := rustc rustc_trans native:hoedown serialize getopts \ +DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \ test time DEPS_flate := std native:miniz DEPS_arena := std @@ -94,7 +98,7 @@ DEPS_fmt_macros = std TOOL_DEPS_compiletest := test getopts TOOL_DEPS_rustdoc := rustdoc -TOOL_DEPS_rustc := rustc_trans +TOOL_DEPS_rustc := rustc_driver TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs TOOL_SOURCE_rustc := $(S)src/driver/driver.rs @@ -110,8 +114,12 @@ 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 rustc_driver, \ + $(filter-out syntax, $(CRATES)))))) +COMPILER_DOC_CRATES := rustc rustc_trans rustc_typeck rustc_driver syntax # This macro creates some simple definitions for each crate being built, just # some munging of all of the parameters above. diff --git a/mk/tests.mk b/mk/tests.mk index e5cde66293c92..b4b8249a8cb42 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -21,7 +21,7 @@ $(eval $(call RUST_CRATE,coretest)) TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) coretest TEST_DOC_CRATES = $(DOC_CRATES) -TEST_HOST_CRATES = $(HOST_CRATES) +TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_trans,$(HOST_CRATES)) TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES) ###################################################################### diff --git a/src/driver/driver.rs b/src/driver/driver.rs index 632d21d7b9c05..5c29cb4ec7276 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -12,6 +12,6 @@ extern crate "rustdoc" as this; #[cfg(rustc)] -extern crate "rustc_trans" as this; +extern crate "rustc_driver" as this; fn main() { this::main() } diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index a83f8afd39617..a964609e4e634 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -59,6 +59,7 @@ pub mod back { } pub mod middle { + pub mod astconv_util; pub mod astencode; pub mod borrowck; pub mod cfg; @@ -79,6 +80,7 @@ pub mod middle { pub mod fast_reject; pub mod graph; pub mod intrinsicck; + pub mod infer; pub mod lang_items; pub mod liveness; pub mod mem_categorization; @@ -93,7 +95,6 @@ pub mod middle { pub mod traits; pub mod ty; pub mod ty_fold; - pub mod typeck; pub mod weak_lang_items; } diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 9a214d531d157..10c0ae6d37417 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -29,8 +29,6 @@ use self::MethodContext::*; use metadata::csearch; use middle::def::*; use middle::ty::{mod, Ty}; -use middle::typeck::astconv::ast_ty_to_ty; -use middle::typeck::{mod, infer}; use middle::{def, pat_util, stability}; use middle::const_eval::{eval_const_expr_partial, const_int, const_uint}; use util::ppaux::{ty_to_string}; @@ -84,7 +82,7 @@ impl LintPass for UnusedCasts { fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { if let ast::ExprCast(ref expr, ref ty) = e.node { - let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &**ty); + let t_t = ty::expr_ty(cx.tcx, e); if ty::expr_ty(cx.tcx, &**expr) == t_t { cx.span_lint(UNUSED_TYPECASTS, ty.span, "unnecessary type cast"); } @@ -1589,22 +1587,22 @@ impl LintPass for Stability { } ast::ExprMethodCall(i, _, _) => { span = i.span; - let method_call = typeck::MethodCall::expr(e.id); + let method_call = ty::MethodCall::expr(e.id); match cx.tcx.method_map.borrow().get(&method_call) { Some(method) => { match method.origin { - typeck::MethodStatic(def_id) => { + ty::MethodStatic(def_id) => { def_id } - typeck::MethodStaticUnboxedClosure(def_id) => { + ty::MethodStaticUnboxedClosure(def_id) => { def_id } - typeck::MethodTypeParam(typeck::MethodParam { + ty::MethodTypeParam(ty::MethodParam { ref trait_ref, method_num: index, .. }) | - typeck::MethodTraitObject(typeck::MethodObject { + ty::MethodTraitObject(ty::MethodObject { ref trait_ref, method_num: index, .. diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index c7bed838eb919..442d3aab92dba 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -26,17 +26,13 @@ use self::TargetLint::*; use middle::privacy::ExportedItems; -use middle::subst; use middle::ty::{mod, Ty}; -use middle::typeck::astconv::AstConv; -use middle::typeck::infer; use session::{early_error, Session}; use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject}; use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid}; use lint::builtin; use util::nodemap::FnvHashMap; -use std::rc::Rc; use std::cell::RefCell; use std::tuple::Tuple2; use std::mem; @@ -541,42 +537,6 @@ impl<'a, 'tcx> Context<'a, 'tcx> { } } -impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{ - fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } - - fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> { - ty::lookup_item_type(self.tcx, id) - } - - fn get_trait_def(&self, id: ast::DefId) -> Rc> { - ty::lookup_trait_def(self.tcx, id) - } - - fn ty_infer(&self, _span: Span) -> Ty<'tcx> { - infer::new_infer_ctxt(self.tcx).next_ty_var() - } - - fn associated_types_of_trait_are_valid(&self, _: Ty<'tcx>, _: ast::DefId) - -> bool { - // FIXME(pcwalton): This is wrong. - true - } - - fn associated_type_binding(&self, - _: Span, - _: Option>, - trait_id: ast::DefId, - associated_type_id: ast::DefId) - -> Ty<'tcx> { - // FIXME(pcwalton): This is wrong. - let trait_def = self.get_trait_def(trait_id); - let index = ty::associated_type_parameter_index(self.tcx, - &*trait_def, - associated_type_id); - ty::mk_param(self.tcx, subst::TypeSpace, index, associated_type_id) - } -} - impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { fn visit_item(&mut self, it: &ast::Item) { self.with_lint_attrs(it.attrs.as_slice(), |cx| { diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 20e3f27f2ae18..ebf5cca6a31a3 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -21,7 +21,6 @@ use middle::def; use middle::lang_items; use middle::resolve; use middle::ty; -use middle::typeck; use middle::subst::VecPerParamSpace; use rbml; @@ -268,7 +267,7 @@ pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>, // Given a def_id for an impl, return information about its vtables pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) - -> typeck::vtable_res<'tcx> { + -> ty::vtable_res<'tcx> { let cstore = &tcx.sess.cstore; let cdata = cstore.get_crate_data(def.krate); decoder::get_impl_vtables(&*cdata, def.node, tcx) diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index ec812cea3728d..f352a28df6972 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -30,7 +30,6 @@ use middle::resolve::{TraitItemKind, TypeTraitItemKind}; use middle::subst; use middle::ty::{ImplContainer, TraitContainer}; use middle::ty::{mod, Ty}; -use middle::typeck; use middle::astencode::vtable_decoder_helpers; use std::hash::Hash; @@ -422,7 +421,7 @@ pub fn get_impl_trait<'tcx>(cdata: Cmd, pub fn get_impl_vtables<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>) - -> typeck::vtable_res<'tcx> + -> ty::vtable_res<'tcx> { let item_doc = lookup_item(id, cdata.data()); let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables); diff --git a/src/librustc/middle/astconv_util.rs b/src/librustc/middle/astconv_util.rs new file mode 100644 index 0000000000000..6b90bcd60e753 --- /dev/null +++ b/src/librustc/middle/astconv_util.rs @@ -0,0 +1,89 @@ +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/*! + * This module contains a simple utility routine + * used by both `typeck` and `const_eval`. + * Almost certainly this could (and should) be refactored out of existence. + */ + +use middle::def; +use middle::ty::{mod, Ty}; +use syntax::ast; +use util::ppaux::Repr; + +pub const NO_REGIONS: uint = 1; +pub const NO_TPS: uint = 2; + +pub fn check_path_args(tcx: &ty::ctxt, + path: &ast::Path, + flags: uint) { + if (flags & NO_TPS) != 0u { + if path.segments.iter().any(|s| s.parameters.has_types()) { + span_err!(tcx.sess, path.span, E0109, + "type parameters are not allowed on this type"); + } + } + + if (flags & NO_REGIONS) != 0u { + if path.segments.iter().any(|s| s.parameters.has_lifetimes()) { + span_err!(tcx.sess, path.span, E0110, + "region parameters are not allowed on this type"); + } + } +} + +pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty) + -> Option> { + match ast_ty.node { + ast::TyPath(ref path, id) => { + let a_def = match tcx.def_map.borrow().get(&id) { + None => { + tcx.sess.span_bug(ast_ty.span, + format!("unbound path {}", + path.repr(tcx)).as_slice()) + } + Some(&d) => d + }; + match a_def { + def::DefPrimTy(nty) => { + match nty { + ast::TyBool => { + check_path_args(tcx, path, NO_TPS | NO_REGIONS); + Some(ty::mk_bool()) + } + ast::TyChar => { + check_path_args(tcx, path, NO_TPS | NO_REGIONS); + Some(ty::mk_char()) + } + ast::TyInt(it) => { + check_path_args(tcx, path, NO_TPS | NO_REGIONS); + Some(ty::mk_mach_int(it)) + } + ast::TyUint(uit) => { + check_path_args(tcx, path, NO_TPS | NO_REGIONS); + Some(ty::mk_mach_uint(uit)) + } + ast::TyFloat(ft) => { + check_path_args(tcx, path, NO_TPS | NO_REGIONS); + Some(ty::mk_mach_float(ft)) + } + ast::TyStr => { + Some(ty::mk_str(tcx)) + } + } + } + _ => None + } + } + _ => None + } +} + diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 523e997a8deec..113d127503f02 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -26,8 +26,7 @@ use metadata::tyencode; use middle::mem_categorization::Typer; use middle::subst; use middle::subst::VecPerParamSpace; -use middle::typeck::{mod, MethodCall, MethodCallee, MethodOrigin}; -use middle::ty::{mod, Ty}; +use middle::ty::{mod, Ty, MethodCall, MethodCallee, MethodOrigin}; use util::ppaux::ty_to_string; use syntax::{ast, ast_map, ast_util, codemap, fold}; @@ -576,12 +575,12 @@ impl tr for ty::UpvarBorrow { trait read_method_callee_helper<'tcx> { fn read_method_callee<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) - -> (typeck::ExprAdjustment, MethodCallee<'tcx>); + -> (ty::ExprAdjustment, MethodCallee<'tcx>); } fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>, rbml_w: &mut Encoder, - adjustment: typeck::ExprAdjustment, + adjustment: ty::ExprAdjustment, method: &MethodCallee<'tcx>) { use serialize::Encoder; @@ -603,7 +602,7 @@ fn encode_method_callee<'a, 'tcx>(ecx: &e::EncodeContext<'a, 'tcx>, impl<'a, 'tcx> read_method_callee_helper<'tcx> for reader::Decoder<'a> { fn read_method_callee<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) - -> (typeck::ExprAdjustment, MethodCallee<'tcx>) { + -> (ty::ExprAdjustment, MethodCallee<'tcx>) { self.read_struct("MethodCallee", 4, |this| { let adjustment = this.read_struct_field("adjustment", 0, |this| { @@ -627,22 +626,22 @@ impl<'a, 'tcx> read_method_callee_helper<'tcx> for reader::Decoder<'a> { impl<'tcx> tr for MethodOrigin<'tcx> { fn tr(&self, dcx: &DecodeContext) -> MethodOrigin<'tcx> { match *self { - typeck::MethodStatic(did) => typeck::MethodStatic(did.tr(dcx)), - typeck::MethodStaticUnboxedClosure(did) => { - typeck::MethodStaticUnboxedClosure(did.tr(dcx)) + ty::MethodStatic(did) => ty::MethodStatic(did.tr(dcx)), + ty::MethodStaticUnboxedClosure(did) => { + ty::MethodStaticUnboxedClosure(did.tr(dcx)) } - typeck::MethodTypeParam(ref mp) => { - typeck::MethodTypeParam( - typeck::MethodParam { + ty::MethodTypeParam(ref mp) => { + ty::MethodTypeParam( + ty::MethodParam { // def-id is already translated when we read it out trait_ref: mp.trait_ref.clone(), method_num: mp.method_num, } ) } - typeck::MethodTraitObject(ref mo) => { - typeck::MethodTraitObject( - typeck::MethodObject { + ty::MethodTraitObject(ref mo) => { + ty::MethodTraitObject( + ty::MethodObject { trait_ref: mo.trait_ref.clone(), .. *mo } @@ -687,16 +686,16 @@ pub trait vtable_decoder_helpers<'tcx> { fn read_vtable_res_with_key(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> (typeck::ExprAdjustment, typeck::vtable_res<'tcx>); + -> (ty::ExprAdjustment, ty::vtable_res<'tcx>); fn read_vtable_res(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_res<'tcx>; + -> ty::vtable_res<'tcx>; fn read_vtable_param_res(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_param_res<'tcx>; + -> ty::vtable_param_res<'tcx>; fn read_vtable_origin(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_origin<'tcx>; + -> ty::vtable_origin<'tcx>; } impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { @@ -714,7 +713,7 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { fn read_vtable_res_with_key(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> (typeck::ExprAdjustment, typeck::vtable_res<'tcx>) { + -> (ty::ExprAdjustment, ty::vtable_res<'tcx>) { self.read_struct("VtableWithKey", 2, |this| { let adjustment = this.read_struct_field("adjustment", 0, |this| { Decodable::decode(this) @@ -728,7 +727,7 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { fn read_vtable_res(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_res<'tcx> + -> ty::vtable_res<'tcx> { self.read_vec_per_param_space( |this| this.read_vtable_param_res(tcx, cdata)) @@ -736,14 +735,14 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { fn read_vtable_param_res(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_param_res<'tcx> { + -> ty::vtable_param_res<'tcx> { self.read_to_vec(|this| Ok(this.read_vtable_origin(tcx, cdata))) .unwrap().into_iter().collect() } fn read_vtable_origin(&mut self, tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) - -> typeck::vtable_origin<'tcx> { + -> ty::vtable_origin<'tcx> { self.read_enum("vtable_origin", |this| { this.read_enum_variant(&["vtable_static", "vtable_param", @@ -752,7 +751,7 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { |this, i| { Ok(match i { 0 => { - typeck::vtable_static( + ty::vtable_static( this.read_enum_variant_arg(0u, |this| { Ok(this.read_def_id_nodcx(cdata)) }).unwrap(), @@ -765,7 +764,7 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { ) } 1 => { - typeck::vtable_param( + ty::vtable_param( this.read_enum_variant_arg(0u, |this| { Decodable::decode(this) }).unwrap(), @@ -775,14 +774,14 @@ impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> { ) } 2 => { - typeck::vtable_unboxed_closure( + ty::vtable_unboxed_closure( this.read_enum_variant_arg(0u, |this| { Ok(this.read_def_id_nodcx(cdata)) }).unwrap() ) } 3 => { - typeck::vtable_error + ty::vtable_error } _ => panic!("bad enum variant") }) @@ -826,7 +825,7 @@ trait rbml_writer_helpers<'tcx> { closure_type: &ty::ClosureTy<'tcx>); fn emit_method_origin<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, - method_origin: &typeck::MethodOrigin<'tcx>); + method_origin: &ty::MethodOrigin<'tcx>); fn emit_ty<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, ty: Ty<'tcx>); fn emit_tys<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, tys: &[Ty<'tcx>]); fn emit_type_param_def<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, @@ -860,25 +859,25 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { fn emit_method_origin<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>, - method_origin: &typeck::MethodOrigin<'tcx>) + method_origin: &ty::MethodOrigin<'tcx>) { use serialize::Encoder; self.emit_enum("MethodOrigin", |this| { match *method_origin { - typeck::MethodStatic(def_id) => { + ty::MethodStatic(def_id) => { this.emit_enum_variant("MethodStatic", 0, 1, |this| { Ok(this.emit_def_id(def_id)) }) } - typeck::MethodStaticUnboxedClosure(def_id) => { + ty::MethodStaticUnboxedClosure(def_id) => { this.emit_enum_variant("MethodStaticUnboxedClosure", 1, 1, |this| { Ok(this.emit_def_id(def_id)) }) } - typeck::MethodTypeParam(ref p) => { + ty::MethodTypeParam(ref p) => { this.emit_enum_variant("MethodTypeParam", 2, 1, |this| { this.emit_struct("MethodParam", 2, |this| { try!(this.emit_struct_field("trait_ref", 0, |this| { @@ -892,7 +891,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> { }) } - typeck::MethodTraitObject(ref o) => { + ty::MethodTraitObject(ref o) => { this.emit_enum_variant("MethodTraitObject", 3, 1, |this| { this.emit_struct("MethodObject", 2, |this| { try!(this.emit_struct_field("trait_ref", 0, |this| { @@ -1330,7 +1329,7 @@ impl<'a> doc_decoder_helpers for rbml::Doc<'a> { trait rbml_decoder_decoder_helpers<'tcx> { fn read_method_origin<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) - -> typeck::MethodOrigin<'tcx>; + -> ty::MethodOrigin<'tcx>; fn read_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Ty<'tcx>; fn read_tys<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Vec>; fn read_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) @@ -1409,7 +1408,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { } fn read_method_origin<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) - -> typeck::MethodOrigin<'tcx> + -> ty::MethodOrigin<'tcx> { self.read_enum("MethodOrigin", |this| { let variants = &["MethodStatic", "MethodStaticUnboxedClosure", @@ -1418,18 +1417,18 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { Ok(match i { 0 => { let def_id = this.read_def_id(dcx); - typeck::MethodStatic(def_id) + ty::MethodStatic(def_id) } 1 => { let def_id = this.read_def_id(dcx); - typeck::MethodStaticUnboxedClosure(def_id) + ty::MethodStaticUnboxedClosure(def_id) } 2 => { this.read_struct("MethodTypeParam", 2, |this| { - Ok(typeck::MethodTypeParam( - typeck::MethodParam { + Ok(ty::MethodTypeParam( + ty::MethodParam { trait_ref: { this.read_struct_field("trait_ref", 0, |this| { Ok(this.read_trait_ref(dcx)) @@ -1446,8 +1445,8 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> { 3 => { this.read_struct("MethodTraitObject", 2, |this| { - Ok(typeck::MethodTraitObject( - typeck::MethodObject { + Ok(ty::MethodTraitObject( + ty::MethodObject { trait_ref: { this.read_struct_field("trait_ref", 0, |this| { Ok(this.read_trait_ref(dcx)) diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index b42fb8ccc41f4..90919609e2e44 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -12,7 +12,6 @@ use middle::cfg::*; use middle::def; use middle::graph; use middle::region::CodeExtent; -use middle::typeck; use middle::ty; use syntax::ast; use syntax::ast_util; @@ -510,7 +509,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { pred: CFGIndex, func_or_rcvr: &ast::Expr, args: I) -> CFGIndex { - let method_call = typeck::MethodCall::expr(call_expr.id); + let method_call = ty::MethodCall::expr(call_expr.id); let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().get(&method_call) { Some(method) => method.ty, None => ty::expr_ty(self.tcx, func_or_rcvr) @@ -635,7 +634,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } fn is_method_call(&self, expr: &ast::Expr) -> bool { - let method_call = typeck::MethodCall::expr(expr.id); + let method_call = ty::MethodCall::expr(expr.id); self.tcx.method_map.borrow().contains_key(&method_call) } } diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 8cb63fcd82741..de140fd5c306c 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -11,7 +11,6 @@ use middle::def::*; use middle::ty; -use middle::typeck; use util::ppaux; use syntax::ast; @@ -111,7 +110,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool { } ast::ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {} ast::ExprBinary(..) | ast::ExprUnary(..) => { - let method_call = typeck::MethodCall::expr(e.id); + let method_call = ty::MethodCall::expr(e.id); if v.tcx.method_map.borrow().contains_key(&method_call) { span_err!(v.tcx.sess, e.span, E0011, "user-defined operators are not allowed in constant \ diff --git a/src/librustc/middle/check_static.rs b/src/librustc/middle/check_static.rs index d3c7ccf65dd72..2fc85afd3935d 100644 --- a/src/librustc/middle/check_static.rs +++ b/src/librustc/middle/check_static.rs @@ -27,7 +27,7 @@ use self::Mode::*; use middle::ty; use middle::def; -use middle::typeck; +use middle::infer; use middle::traits; use middle::mem_categorization as mc; use middle::expr_use_visitor as euv; @@ -113,7 +113,7 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> { fn check_static_type(&self, e: &ast::Expr) { let ty = ty::node_id_to_type(self.tcx, e.id); - let infcx = typeck::infer::new_infer_ctxt(self.tcx); + let infcx = infer::new_infer_ctxt(self.tcx); let mut fulfill_cx = traits::FulfillmentContext::new(); let cause = traits::ObligationCause::misc(DUMMY_SP); let obligation = traits::obligation_for_builtin_bound(self.tcx, cause, ty, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index d5a292b9f09c6..43726f55bb989 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -17,8 +17,8 @@ pub use self::constness::*; use metadata::csearch; use middle::{astencode, def}; use middle::pat_util::def_to_path; -use middle::ty::{mod, Ty}; -use middle::typeck::{astconv, check}; +use middle::ty::{mod}; +use middle::astconv_util::{ast_ty_to_prim_ty}; use util::nodemap::DefIdMap; use syntax::ast::{mod, Expr}; @@ -277,14 +277,6 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> { } impl<'a, 'tcx, 'v> Visitor<'v> for ConstEvalVisitor<'a, 'tcx> { - fn visit_ty(&mut self, t: &ast::Ty) { - if let ast::TyFixedLengthVec(_, ref expr) = t.node { - check::check_const_in_type(self.tcx, &**expr, ty::mk_uint()); - } - - visit::walk_ty(self, t); - } - fn visit_expr_post(&mut self, e: &Expr) { self.classify(e); } @@ -504,7 +496,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result MarkSymbolVisitor<'a, 'tcx> { fn lookup_and_handle_method(&mut self, id: ast::NodeId, span: codemap::Span) { - let method_call = typeck::MethodCall::expr(id); + let method_call = ty::MethodCall::expr(id); match self.tcx.method_map.borrow().get(&method_call) { Some(method) => { match method.origin { - typeck::MethodStatic(def_id) => { + ty::MethodStatic(def_id) => { match ty::provided_source(self.tcx, def_id) { Some(p_did) => self.check_def_id(p_did), None => self.check_def_id(def_id) } } - typeck::MethodStaticUnboxedClosure(_) => {} - typeck::MethodTypeParam(typeck::MethodParam { + ty::MethodStaticUnboxedClosure(_) => {} + ty::MethodTypeParam(ty::MethodParam { ref trait_ref, method_num: index, .. }) | - typeck::MethodTraitObject(typeck::MethodObject { + ty::MethodTraitObject(ty::MethodObject { ref trait_ref, method_num: index, .. diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index e67df0332dce6..dbec69f420503 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -14,7 +14,7 @@ use self::UnsafeContext::*; use middle::def; use middle::ty::{mod, Ty}; -use middle::typeck::MethodCall; +use middle::ty::MethodCall; use util::ppaux; use syntax::ast; diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index cbf36aeff512c..7d2bb7458acd5 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -24,10 +24,9 @@ use middle::{def, region, pat_util}; use middle::mem_categorization as mc; use middle::mem_categorization::Typer; use middle::ty::{mod, Ty}; -use middle::typeck::{MethodCall, MethodObject, MethodTraitObject}; -use middle::typeck::{MethodOrigin, MethodParam, MethodTypeParam}; -use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure}; -use middle::typeck; +use middle::ty::{MethodCall, MethodObject, MethodTraitObject}; +use middle::ty::{MethodOrigin, MethodParam, MethodTypeParam}; +use middle::ty::{MethodStatic, MethodStaticUnboxedClosure}; use util::ppaux::Repr; use syntax::ast; @@ -825,7 +824,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { debug!("walk_autoderefs expr={} autoderefs={}", expr.repr(self.tcx()), autoderefs); for i in range(0, autoderefs) { - let deref_id = typeck::MethodCall::autoderef(expr.id, i); + let deref_id = ty::MethodCall::autoderef(expr.id, i); match self.typer.node_method_ty(deref_id) { None => {} Some(method_ty) => { diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/infer/coercion.rs similarity index 99% rename from src/librustc/middle/typeck/infer/coercion.rs rename to src/librustc/middle/infer/coercion.rs index 51f8668692ea7..f04c519badc8c 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/infer/coercion.rs @@ -60,14 +60,15 @@ //! sort of a minor point so I've opted to leave it for later---after all //! we may want to adjust precisely when coercions occur. +use super::{CoerceResult, resolve_type, Coercion}; +use super::combine::{CombineFields, Combine}; +use super::sub::Sub; +use super::resolve::try_resolve_tvar_shallow; + use middle::subst; use middle::ty::{AutoPtr, AutoDerefRef, AdjustDerefRef, AutoUnsize, AutoUnsafe}; use middle::ty::{mt}; use middle::ty::{mod, Ty}; -use middle::typeck::infer::{CoerceResult, resolve_type, Coercion}; -use middle::typeck::infer::combine::{CombineFields, Combine}; -use middle::typeck::infer::sub::Sub; -use middle::typeck::infer::resolve::try_resolve_tvar_shallow; use util::ppaux; use util::ppaux::Repr; diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/infer/combine.rs similarity index 98% rename from src/librustc/middle/typeck/infer/combine.rs rename to src/librustc/middle/infer/combine.rs index ba6ae00b6671f..ab9c5b86aeb62 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/infer/combine.rs @@ -32,6 +32,14 @@ // is also useful to track which value is the "expected" value in // terms of error reporting. +use super::equate::Equate; +use super::glb::Glb; +use super::lub::Lub; +use super::sub::Sub; +use super::unify::InferCtxtMethodsForSimplyUnifiableTypes; +use super::{InferCtxt, cres}; +use super::{MiscVariable, TypeTrace}; +use super::type_variable::{RelationDir, EqTo, SubtypeOf, SupertypeOf}; use middle::subst; use middle::subst::{ErasedRegions, NonerasedRegions, Substs}; @@ -40,15 +48,6 @@ use middle::ty::{IntType, UintType}; use middle::ty::{BuiltinBounds}; use middle::ty::{mod, Ty}; use middle::ty_fold; -use middle::typeck::infer::equate::Equate; -use middle::typeck::infer::glb::Glb; -use middle::typeck::infer::lub::Lub; -use middle::typeck::infer::sub::Sub; -use middle::typeck::infer::unify::InferCtxtMethodsForSimplyUnifiableTypes; -use middle::typeck::infer::{InferCtxt, cres}; -use middle::typeck::infer::{MiscVariable, TypeTrace}; -use middle::typeck::infer::type_variable::{RelationDir, EqTo, - SubtypeOf, SupertypeOf}; use middle::ty_fold::{TypeFoldable}; use util::ppaux::Repr; diff --git a/src/librustc/middle/typeck/infer/doc.rs b/src/librustc/middle/infer/doc.rs similarity index 100% rename from src/librustc/middle/typeck/infer/doc.rs rename to src/librustc/middle/infer/doc.rs diff --git a/src/librustc/middle/typeck/infer/equate.rs b/src/librustc/middle/infer/equate.rs similarity index 93% rename from src/librustc/middle/typeck/infer/equate.rs rename to src/librustc/middle/infer/equate.rs index 356081c199afa..a79a50b1781eb 100644 --- a/src/librustc/middle/typeck/infer/equate.rs +++ b/src/librustc/middle/infer/equate.rs @@ -11,14 +11,14 @@ use middle::ty::{BuiltinBounds}; use middle::ty::{mod, Ty}; use middle::ty::TyVar; -use middle::typeck::infer::combine::*; -use middle::typeck::infer::{cres}; -use middle::typeck::infer::glb::Glb; -use middle::typeck::infer::InferCtxt; -use middle::typeck::infer::lub::Lub; -use middle::typeck::infer::sub::Sub; -use middle::typeck::infer::{TypeTrace, Subtype}; -use middle::typeck::infer::type_variable::{EqTo}; +use middle::infer::combine::*; +use middle::infer::{cres}; +use middle::infer::glb::Glb; +use middle::infer::InferCtxt; +use middle::infer::lub::Lub; +use middle::infer::sub::Sub; +use middle::infer::{TypeTrace, Subtype}; +use middle::infer::type_variable::{EqTo}; use util::ppaux::{Repr}; use syntax::ast::{Onceness, FnStyle}; diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs similarity index 99% rename from src/librustc/middle/typeck/infer/error_reporting.rs rename to src/librustc/middle/infer/error_reporting.rs index 0607ccdc595a2..657ee088758d1 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -57,24 +57,25 @@ use self::FreshOrKept::*; +use super::InferCtxt; +use super::TypeTrace; +use super::SubregionOrigin; +use super::RegionVariableOrigin; +use super::ValuePairs; +use super::region_inference::RegionResolutionError; +use super::region_inference::ConcreteFailure; +use super::region_inference::SubSupConflict; +use super::region_inference::SupSupConflict; +use super::region_inference::ParamBoundFailure; +use super::region_inference::ProcessedErrors; +use super::region_inference::SameRegions; + use std::collections::HashSet; use middle::def; +use middle::infer; use middle::subst; use middle::ty::{mod, Ty}; use middle::ty::{Region, ReFree}; -use middle::typeck::infer; -use middle::typeck::infer::InferCtxt; -use middle::typeck::infer::TypeTrace; -use middle::typeck::infer::SubregionOrigin; -use middle::typeck::infer::RegionVariableOrigin; -use middle::typeck::infer::ValuePairs; -use middle::typeck::infer::region_inference::RegionResolutionError; -use middle::typeck::infer::region_inference::ConcreteFailure; -use middle::typeck::infer::region_inference::SubSupConflict; -use middle::typeck::infer::region_inference::SupSupConflict; -use middle::typeck::infer::region_inference::ParamBoundFailure; -use middle::typeck::infer::region_inference::ProcessedErrors; -use middle::typeck::infer::region_inference::SameRegions; use std::cell::{Cell, RefCell}; use std::char::from_u32; use std::rc::Rc; diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/infer/glb.rs similarity index 92% rename from src/librustc/middle/typeck/infer/glb.rs rename to src/librustc/middle/infer/glb.rs index 671d2e3837c79..4237a7af32fc1 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/infer/glb.rs @@ -8,17 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use super::combine::*; +use super::lattice::*; +use super::equate::Equate; +use super::higher_ranked::HigherRankedRelations; +use super::lub::Lub; +use super::sub::Sub; +use super::{cres, InferCtxt}; +use super::{TypeTrace, Subtype}; use middle::ty::{BuiltinBounds}; use middle::ty::{mod, Ty}; -use middle::typeck::infer::combine::*; -use middle::typeck::infer::lattice::*; -use middle::typeck::infer::equate::Equate; -use middle::typeck::infer::higher_ranked::HigherRankedRelations; -use middle::typeck::infer::lub::Lub; -use middle::typeck::infer::sub::Sub; -use middle::typeck::infer::{cres, InferCtxt}; -use middle::typeck::infer::{TypeTrace, Subtype}; use syntax::ast::{Many, Once, MutImmutable, MutMutable}; use syntax::ast::{NormalFn, UnsafeFn}; use syntax::ast::{Onceness, FnStyle}; diff --git a/src/librustc/middle/typeck/infer/higher_ranked/doc.rs b/src/librustc/middle/infer/higher_ranked/doc.rs similarity index 100% rename from src/librustc/middle/typeck/infer/higher_ranked/doc.rs rename to src/librustc/middle/infer/higher_ranked/doc.rs diff --git a/src/librustc/middle/typeck/infer/higher_ranked/mod.rs b/src/librustc/middle/infer/higher_ranked/mod.rs similarity index 97% rename from src/librustc/middle/typeck/infer/higher_ranked/mod.rs rename to src/librustc/middle/infer/higher_ranked/mod.rs index 2f80a574bb18b..95805ef8b944d 100644 --- a/src/librustc/middle/typeck/infer/higher_ranked/mod.rs +++ b/src/librustc/middle/infer/higher_ranked/mod.rs @@ -11,10 +11,11 @@ //! Helper routines for higher-ranked things. See the `doc` module at //! the end of the file for details. +use super::{combine, cres, InferCtxt, HigherRankedType}; +use super::combine::Combine; +use super::region_inference::{RegionMark}; + use middle::ty::{mod, Ty, replace_late_bound_regions}; -use middle::typeck::infer::{mod, combine, cres, InferCtxt}; -use middle::typeck::infer::combine::Combine; -use middle::typeck::infer::region_inference::{RegionMark}; use middle::ty_fold::{mod, HigherRankedFoldable, TypeFoldable}; use syntax::codemap::Span; use util::nodemap::FnvHashMap; @@ -62,7 +63,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C let (a_prime, _) = self.infcx().replace_late_bound_regions_with_fresh_var( self.trace().origin.span(), - infer::HigherRankedType, + HigherRankedType, a); // Second, we instantiate each bound region in the supertype with a @@ -131,10 +132,10 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C let span = self.trace().origin.span(); let (a_with_fresh, a_map) = self.infcx().replace_late_bound_regions_with_fresh_var( - span, infer::HigherRankedType, a); + span, HigherRankedType, a); let (b_with_fresh, _) = self.infcx().replace_late_bound_regions_with_fresh_var( - span, infer::HigherRankedType, b); + span, HigherRankedType, b); // Collect constraints. let result0 = @@ -221,10 +222,10 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C // Instantiate each bound region with a fresh region variable. let (a_with_fresh, a_map) = self.infcx().replace_late_bound_regions_with_fresh_var( - self.trace().origin.span(), infer::HigherRankedType, a); + self.trace().origin.span(), HigherRankedType, a); let (b_with_fresh, b_map) = self.infcx().replace_late_bound_regions_with_fresh_var( - self.trace().origin.span(), infer::HigherRankedType, b); + self.trace().origin.span(), HigherRankedType, b); let a_vars = var_ids(self, &a_map); let b_vars = var_ids(self, &b_map); diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/infer/lattice.rs similarity index 96% rename from src/librustc/middle/typeck/infer/lattice.rs rename to src/librustc/middle/infer/lattice.rs index daec959d11cd3..dd514ebee524a 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/infer/lattice.rs @@ -29,12 +29,13 @@ //! over a `LatticeValue`, which is a value defined with respect to //! a lattice. +use super::*; +use super::combine::*; +use super::glb::Glb; +use super::lub::Lub; + use middle::ty::{TyVar}; use middle::ty::{mod, Ty}; -use middle::typeck::infer::*; -use middle::typeck::infer::combine::*; -use middle::typeck::infer::glb::Glb; -use middle::typeck::infer::lub::Lub; use util::ppaux::Repr; pub trait LatticeDir<'tcx> { diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/infer/lub.rs similarity index 91% rename from src/librustc/middle/typeck/infer/lub.rs rename to src/librustc/middle/infer/lub.rs index e7bd1f3716c12..f53ba571062b2 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/infer/lub.rs @@ -8,16 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use super::combine::*; +use super::equate::Equate; +use super::glb::Glb; +use super::higher_ranked::HigherRankedRelations; +use super::lattice::*; +use super::sub::Sub; +use super::{cres, InferCtxt}; +use super::{TypeTrace, Subtype}; + use middle::ty::{BuiltinBounds}; use middle::ty::{mod, Ty}; -use middle::typeck::infer::combine::*; -use middle::typeck::infer::equate::Equate; -use middle::typeck::infer::glb::Glb; -use middle::typeck::infer::higher_ranked::HigherRankedRelations; -use middle::typeck::infer::lattice::*; -use middle::typeck::infer::sub::Sub; -use middle::typeck::infer::{cres, InferCtxt}; -use middle::typeck::infer::{TypeTrace, Subtype}; use syntax::ast::{Many, Once}; use syntax::ast::{NormalFn, UnsafeFn}; use syntax::ast::{Onceness, FnStyle}; diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/infer/mod.rs similarity index 100% rename from src/librustc/middle/typeck/infer/mod.rs rename to src/librustc/middle/infer/mod.rs diff --git a/src/librustc/middle/typeck/infer/region_inference/doc.rs b/src/librustc/middle/infer/region_inference/doc.rs similarity index 99% rename from src/librustc/middle/typeck/infer/region_inference/doc.rs rename to src/librustc/middle/infer/region_inference/doc.rs index b4eac4c002677..686174b73060b 100644 --- a/src/librustc/middle/typeck/infer/region_inference/doc.rs +++ b/src/librustc/middle/infer/region_inference/doc.rs @@ -371,4 +371,4 @@ //! ### Skolemization //! //! For a discussion on skolemization and higher-ranked subtyping, please -//! see the module `middle::typeck::infer::higher_ranked::doc`. +//! see the module `middle::infer::higher_ranked::doc`. diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/infer/region_inference/mod.rs similarity index 99% rename from src/librustc/middle/typeck/infer/region_inference/mod.rs rename to src/librustc/middle/infer/region_inference/mod.rs index e39fbe105dcfc..9155c18cb3b5a 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/infer/region_inference/mod.rs @@ -18,14 +18,14 @@ pub use self::RegionResolutionError::*; pub use self::VarValue::*; use self::Classification::*; +use super::cres; +use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable}; + use middle::region; use middle::ty; use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid}; use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound}; use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh}; -use middle::typeck::infer::cres; -use middle::typeck::infer::{RegionVariableOrigin, SubregionOrigin, TypeTrace}; -use middle::typeck::infer; use middle::graph; use middle::graph::{Direction, NodeIndex}; use util::common::indenter; @@ -573,7 +573,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { } None => {} } - let c = self.new_region_var(infer::MiscVariable(origin.span())); + let c = self.new_region_var(MiscVariable(origin.span())); self.combine_map(t).borrow_mut().insert(vars, c); if self.in_snapshot() { self.undo_log.borrow_mut().push(AddCombination(t, vars)); diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/infer/resolve.rs similarity index 98% rename from src/librustc/middle/typeck/infer/resolve.rs rename to src/librustc/middle/infer/resolve.rs index cf5efd188ed96..eaf363ffc74c2 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/infer/resolve.rs @@ -48,12 +48,13 @@ #![allow(non_upper_case_globals)] +use super::{fixup_err, fres, InferCtxt}; +use super::{unresolved_int_ty,unresolved_float_ty,unresolved_ty}; + use middle::ty::{FloatVar, FloatVid, IntVar, IntVid, RegionVid, TyVar, TyVid}; use middle::ty::{IntType, UintType}; use middle::ty::{mod, Ty}; use middle::ty_fold; -use middle::typeck::infer::{fixup_err, fres, InferCtxt}; -use middle::typeck::infer::{unresolved_int_ty,unresolved_float_ty,unresolved_ty}; use syntax::codemap::Span; use util::ppaux::{Repr, ty_to_string}; diff --git a/src/librustc/middle/typeck/infer/skolemize.rs b/src/librustc/middle/infer/skolemize.rs similarity index 100% rename from src/librustc/middle/typeck/infer/skolemize.rs rename to src/librustc/middle/infer/skolemize.rs diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/infer/sub.rs similarity index 92% rename from src/librustc/middle/typeck/infer/sub.rs rename to src/librustc/middle/infer/sub.rs index 65d2a5133936c..c470b2488273a 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/infer/sub.rs @@ -8,19 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use super::combine::*; +use super::{cres, CresCompare}; +use super::equate::Equate; +use super::glb::Glb; +use super::higher_ranked::HigherRankedRelations; +use super::InferCtxt; +use super::lub::Lub; +use super::{TypeTrace, Subtype}; +use super::type_variable::{SubtypeOf, SupertypeOf}; use middle::ty::{BuiltinBounds}; use middle::ty::{mod, Ty}; use middle::ty::TyVar; -use middle::typeck::infer::combine::*; -use middle::typeck::infer::{cres, CresCompare}; -use middle::typeck::infer::equate::Equate; -use middle::typeck::infer::glb::Glb; -use middle::typeck::infer::higher_ranked::HigherRankedRelations; -use middle::typeck::infer::InferCtxt; -use middle::typeck::infer::lub::Lub; -use middle::typeck::infer::{TypeTrace, Subtype}; -use middle::typeck::infer::type_variable::{SubtypeOf, SupertypeOf}; use util::ppaux::{Repr}; use syntax::ast::{Onceness, FnStyle, MutImmutable, MutMutable}; diff --git a/src/librustc/middle/typeck/infer/type_variable.rs b/src/librustc/middle/infer/type_variable.rs similarity index 100% rename from src/librustc/middle/typeck/infer/type_variable.rs rename to src/librustc/middle/infer/type_variable.rs diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/infer/unify.rs similarity index 99% rename from src/librustc/middle/typeck/infer/unify.rs rename to src/librustc/middle/infer/unify.rs index 1b3413bfb0104..6f6adb84a75f5 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/infer/unify.rs @@ -14,8 +14,8 @@ use std::kinds::marker; use middle::ty::{expected_found, IntVarValue}; use middle::ty::{mod, Ty}; -use middle::typeck::infer::{uok, ures}; -use middle::typeck::infer::InferCtxt; +use middle::infer::{uok, ures}; +use middle::infer::InferCtxt; use std::cell::RefCell; use std::fmt::Show; use syntax::ast; diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index fcc23d8ac5548..523c9f3330968 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -111,7 +111,7 @@ use self::VarKind::*; use middle::def::*; use middle::mem_categorization::Typer; -use middle::{pat_util, typeck, ty}; +use middle::{pat_util, ty}; use lint; use util::nodemap::NodeMap; @@ -1156,7 +1156,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } ast::ExprMethodCall(_, _, ref args) => { - let method_call = typeck::MethodCall::expr(expr.id); + let method_call = ty::MethodCall::expr(expr.id); let method_ty = self.ir.tcx.method_map.borrow().get(&method_call).unwrap().ty; let diverges = ty::ty_fn_ret(method_ty) == ty::FnDiverging; let succ = if diverges { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index ce166fc5de6bb..cd70d8e2b487a 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -74,7 +74,6 @@ pub use self::categorization::*; use middle::def; use middle::region; use middle::ty::{mod, Ty}; -use middle::typeck; use util::nodemap::{DefIdMap, NodeMap}; use util::ppaux::{ty_to_string, Repr}; @@ -283,7 +282,7 @@ pub type McResult = Result; pub trait Typer<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; fn node_ty(&self, id: ast::NodeId) -> McResult>; - fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option>; + fn node_method_ty(&self, method_call: ty::MethodCall) -> Option>; fn adjustments<'a>(&'a self) -> &'a RefCell>>; fn is_method_call(&self, id: ast::NodeId) -> bool; fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option; @@ -509,7 +508,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { } ast::ExprIndex(ref base, _) => { - let method_call = typeck::MethodCall::expr(expr.id()); + let method_call = ty::MethodCall::expr(expr.id()); match self.typer.node_method_ty(method_call) { Some(method_ty) => { // If this is an index implemented by a method call, then it will @@ -890,12 +889,12 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { implicit: bool) -> cmt<'tcx> { let adjustment = match self.typer.adjustments().borrow().get(&node.id()) { - Some(adj) if ty::adjust_is_object(adj) => typeck::AutoObject, - _ if deref_cnt != 0 => typeck::AutoDeref(deref_cnt), - _ => typeck::NoAdjustment + Some(adj) if ty::adjust_is_object(adj) => ty::AutoObject, + _ if deref_cnt != 0 => ty::AutoDeref(deref_cnt), + _ => ty::NoAdjustment }; - let method_call = typeck::MethodCall { + let method_call = ty::MethodCall { expr_id: node.id(), adjustment: adjustment }; @@ -980,7 +979,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { //! - `elt`: the AST node being indexed //! - `base_cmt`: the cmt of `elt` - let method_call = typeck::MethodCall::expr(elt.id()); + let method_call = ty::MethodCall::expr(elt.id()); let method_ty = self.typer.node_method_ty(method_call); let element_ty = match method_ty { diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 5e182ba8337cb..5770b601a69ce 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -19,8 +19,8 @@ use std::mem::replace; use metadata::csearch; use middle::{def, resolve}; use middle::ty::{mod, Ty}; -use middle::typeck::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam}; -use middle::typeck::{MethodStatic, MethodStaticUnboxedClosure, MethodObject, MethodTraitObject}; +use middle::ty::{MethodCall, MethodMap, MethodOrigin, MethodParam, MethodTypeParam}; +use middle::ty::{MethodStatic, MethodStaticUnboxedClosure, MethodObject, MethodTraitObject}; use util::nodemap::{NodeMap, NodeSet}; use syntax::{ast, ast_map}; diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 96e1aacb0cef5..fa02c940aa754 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -17,7 +17,6 @@ use middle::def; use middle::ty; -use middle::typeck; use middle::privacy; use session::config; use util::nodemap::NodeSet; @@ -137,9 +136,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> { } } ast::ExprMethodCall(..) => { - let method_call = typeck::MethodCall::expr(expr.id); + let method_call = ty::MethodCall::expr(expr.id); match (*self.tcx.method_map.borrow())[method_call].origin { - typeck::MethodStatic(def_id) => { + ty::MethodStatic(def_id) => { if is_local(def_id) { if self.def_id_represents_local_inlined_item(def_id) { self.worklist.push(def_id.node) diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index 0a3e6c20316be..21f57a9d57388 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -589,8 +589,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { // type declarations and other outer declarations, not those // bound in *fn types*. Region substitution of the bound // regions that appear in a function signature is done using - // the specialized routine - // `middle::typeck::check::regionmanip::replace_late_regions_in_fn_sig()`. + // the specialized routine `ty::replace_late_regions()`. match r { ty::ReEarlyBound(_, space, i, region_name) => { match self.substs.regions { diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index 048f394224cf0..1bce353cb0cfe 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -17,7 +17,7 @@ use super::util; use middle::subst; use middle::subst::Subst; use middle::ty::{mod, Ty}; -use middle::typeck::infer::{mod, InferCtxt}; +use middle::infer::{mod, InferCtxt}; use syntax::ast; use syntax::codemap::DUMMY_SP; use util::ppaux::Repr; diff --git a/src/librustc/middle/traits/fulfill.rs b/src/librustc/middle/traits/fulfill.rs index 25c86be993f70..653c686ab197c 100644 --- a/src/librustc/middle/traits/fulfill.rs +++ b/src/librustc/middle/traits/fulfill.rs @@ -10,7 +10,7 @@ use middle::mem_categorization::Typer; use middle::ty; -use middle::typeck::infer::InferCtxt; +use middle::infer::InferCtxt; use std::collections::HashSet; use std::rc::Rc; use util::ppaux::Repr; diff --git a/src/librustc/middle/traits/mod.rs b/src/librustc/middle/traits/mod.rs index b8d915c06e0b7..e12ec44ad87ce 100644 --- a/src/librustc/middle/traits/mod.rs +++ b/src/librustc/middle/traits/mod.rs @@ -18,7 +18,7 @@ pub use self::ObligationCauseCode::*; use middle::mem_categorization::Typer; use middle::subst; use middle::ty::{mod, Ty}; -use middle::typeck::infer::InferCtxt; +use middle::infer::InferCtxt; use std::rc::Rc; use std::slice::Items; use syntax::ast; diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 2604204d9e63f..0e6a0c19f7061 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -30,8 +30,8 @@ use middle::fast_reject; use middle::mem_categorization::Typer; use middle::subst::{Subst, Substs, VecPerParamSpace}; use middle::ty::{mod, Ty}; -use middle::typeck::infer; -use middle::typeck::infer::{InferCtxt, TypeSkolemizer}; +use middle::infer; +use middle::infer::{InferCtxt, TypeSkolemizer}; use middle::ty_fold::TypeFoldable; use std::cell::RefCell; use std::collections::hash_map::HashMap; diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 1084807ef4a0a..1b7998a92638c 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -11,7 +11,7 @@ use middle::subst; use middle::subst::{ParamSpace, Substs, VecPerParamSpace}; -use middle::typeck::infer::InferCtxt; +use middle::infer::InferCtxt; use middle::ty::{mod, Ty}; use std::collections::HashSet; use std::fmt; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 35aed356303d8..994f0c2090a57 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -35,6 +35,9 @@ pub use self::ImplOrTraitItem::*; pub use self::BoundRegion::*; pub use self::sty::*; pub use self::IntVarValue::*; +pub use self::ExprAdjustment::*; +pub use self::vtable_origin::*; +pub use self::MethodOrigin::*; use back::svh::Svh; use session::Session; @@ -53,7 +56,6 @@ use middle::stability; use middle::subst::{mod, Subst, Substs, VecPerParamSpace}; use middle::traits; use middle::ty; -use middle::typeck; use middle::ty_fold::{mod, TypeFoldable, TypeFolder, HigherRankedFoldable}; use middle; use util::ppaux::{note_and_explain_region, bound_region_ptr_to_string}; @@ -90,6 +92,17 @@ pub const INITIAL_DISCRIMINANT_VALUE: Disr = 0; // Data types +/// The complete set of all analyses described in this module. This is +/// produced by the driver and fed to trans and later passes. +pub struct CrateAnalysis<'tcx> { + pub exp_map2: middle::resolve::ExportMap2, + pub exported_items: middle::privacy::ExportedItems, + pub public_items: middle::privacy::PublicItems, + pub ty_cx: ty::ctxt<'tcx>, + pub reachable: NodeSet, + pub name: String, +} + #[deriving(PartialEq, Eq, Hash)] pub struct field<'tcx> { pub name: ast::Name, @@ -412,7 +425,161 @@ pub fn type_of_adjust<'tcx>(cx: &ctxt<'tcx>, adj: &AutoAdjustment<'tcx>) -> Opti } } +#[deriving(Clone, Encodable, Decodable, PartialEq, PartialOrd, Show)] +pub struct param_index { + pub space: subst::ParamSpace, + pub index: uint +} + +#[deriving(Clone, Show)] +pub enum MethodOrigin<'tcx> { + // fully statically resolved method + MethodStatic(ast::DefId), + + // fully statically resolved unboxed closure invocation + MethodStaticUnboxedClosure(ast::DefId), + + // method invoked on a type parameter with a bounded trait + MethodTypeParam(MethodParam<'tcx>), + + // method invoked on a trait instance + MethodTraitObject(MethodObject<'tcx>), + +} + +// details for a method invoked with a receiver whose type is a type parameter +// with a bounded trait. +#[deriving(Clone, Show)] +pub struct MethodParam<'tcx> { + // the precise trait reference that occurs as a bound -- this may + // be a supertrait of what the user actually typed. + pub trait_ref: Rc>, + + // index of uint in the list of methods for the trait + pub method_num: uint, +} + +// details for a method invoked with a receiver whose type is an object +#[deriving(Clone, Show)] +pub struct MethodObject<'tcx> { + // the (super)trait containing the method to be invoked + pub trait_ref: Rc>, + + // the actual base trait id of the object + pub object_trait_id: ast::DefId, + + // index of the method to be invoked amongst the trait's methods + pub method_num: uint, + + // index into the actual runtime vtable. + // the vtable is formed by concatenating together the method lists of + // the base object trait and all supertraits; this is the index into + // that vtable + pub real_index: uint, +} + +#[deriving(Clone)] +pub struct MethodCallee<'tcx> { + pub origin: MethodOrigin<'tcx>, + pub ty: Ty<'tcx>, + pub substs: subst::Substs<'tcx> +} + +/// With method calls, we store some extra information in +/// side tables (i.e method_map). We use +/// MethodCall as a key to index into these tables instead of +/// just directly using the expression's NodeId. The reason +/// for this being that we may apply adjustments (coercions) +/// with the resulting expression also needing to use the +/// side tables. The problem with this is that we don't +/// assign a separate NodeId to this new expression +/// and so it would clash with the base expression if both +/// needed to add to the side tables. Thus to disambiguate +/// we also keep track of whether there's an adjustment in +/// our key. +#[deriving(Clone, PartialEq, Eq, Hash, Show)] +pub struct MethodCall { + pub expr_id: ast::NodeId, + pub adjustment: ExprAdjustment +} + +#[deriving(Clone, PartialEq, Eq, Hash, Show, Encodable, Decodable)] +pub enum ExprAdjustment { + NoAdjustment, + AutoDeref(uint), + AutoObject +} + +impl MethodCall { + pub fn expr(id: ast::NodeId) -> MethodCall { + MethodCall { + expr_id: id, + adjustment: NoAdjustment + } + } + + pub fn autoobject(id: ast::NodeId) -> MethodCall { + MethodCall { + expr_id: id, + adjustment: AutoObject + } + } + + pub fn autoderef(expr_id: ast::NodeId, autoderef: uint) -> MethodCall { + MethodCall { + expr_id: expr_id, + adjustment: AutoDeref(1 + autoderef) + } + } +} + +// maps from an expression id that corresponds to a method call to the details +// of the method to be invoked +pub type MethodMap<'tcx> = RefCell>>; +pub type vtable_param_res<'tcx> = Vec>; + +// Resolutions for bounds of all parameters, left to right, for a given path. +pub type vtable_res<'tcx> = VecPerParamSpace>; + +#[deriving(Clone)] +pub enum vtable_origin<'tcx> { + /* + Statically known vtable. def_id gives the impl item + from whence comes the vtable, and tys are the type substs. + vtable_res is the vtable itself. + */ + vtable_static(ast::DefId, subst::Substs<'tcx>, vtable_res<'tcx>), + + /* + Dynamic vtable, comes from a parameter that has a bound on it: + fn foo(a: T) -- a's vtable would have a + vtable_param origin + + The first argument is the param index (identifying T in the example), + and the second is the bound number (identifying baz) + */ + vtable_param(param_index, uint), + + /* + Vtable automatically generated for an unboxed closure. The def ID is the + ID of the closure expression. + */ + vtable_unboxed_closure(ast::DefId), + + /* + Asked to determine the vtable for ty_err. This is the value used + for the vtables of `Self` in a virtual call like `foo.bar()` + where `foo` is of object type. The same value is also used when + type errors occur. + */ + vtable_error, +} + + +// For every explicit cast into an object type, maps from the cast +// expr to the associated trait ref. +pub type ObjectCastMap<'tcx> = RefCell>>>; /// A restriction that certain types must be the same size. The use of /// `transmute` gives rise to these restrictions. @@ -473,7 +640,7 @@ pub struct ctxt<'tcx> { /// Maps from node-id of a trait object cast (like `foo as /// Box`) to the trait reference. - pub object_cast_map: typeck::ObjectCastMap<'tcx>, + pub object_cast_map: ObjectCastMap<'tcx>, pub map: ast_map::Map<'tcx>, pub intrinsic_defs: RefCell>>, @@ -548,7 +715,7 @@ pub struct ctxt<'tcx> { pub extern_const_statics: RefCell>, pub extern_const_variants: RefCell>, - pub method_map: typeck::MethodMap<'tcx>, + pub method_map: MethodMap<'tcx>, pub dependency_formats: RefCell, @@ -3658,7 +3825,7 @@ pub fn adjust_ty<'tcx>(cx: &ctxt<'tcx>, expr_id: ast::NodeId, unadjusted_ty: Ty<'tcx>, adjustment: Option<&AutoAdjustment<'tcx>>, - method_type: |typeck::MethodCall| -> Option>) + method_type: |MethodCall| -> Option>) -> Ty<'tcx> { if let ty_err = unadjusted_ty.sty { @@ -3699,7 +3866,7 @@ pub fn adjust_ty<'tcx>(cx: &ctxt<'tcx>, if !ty::type_is_error(adjusted_ty) { for i in range(0, adj.autoderefs) { - let method_call = typeck::MethodCall::autoderef(expr_id, i); + let method_call = MethodCall::autoderef(expr_id, i); match method_type(method_call) { Some(method_ty) => { if let ty::FnConverging(result_type) = ty_fn_ret(method_ty) { @@ -3830,7 +3997,7 @@ pub enum ExprKind { } pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind { - if tcx.method_map.borrow().contains_key(&typeck::MethodCall::expr(expr.id)) { + if tcx.method_map.borrow().contains_key(&MethodCall::expr(expr.id)) { // Overloaded operations are generally calls, and hence they are // generated via DPS, but there are a few exceptions: return match expr.node { @@ -5747,7 +5914,7 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { Ok(ty::node_id_to_type(self, id)) } - fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option> { + fn node_method_ty(&self, method_call: MethodCall) -> Option> { self.method_map.borrow().get(&method_call).map(|method| method.ty) } @@ -5756,7 +5923,7 @@ impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { } fn is_method_call(&self, id: ast::NodeId) -> bool { - self.method_map.borrow().contains_key(&typeck::MethodCall::expr(id)) + self.method_map.borrow().contains_key(&MethodCall::expr(id)) } fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option { @@ -6010,3 +6177,55 @@ impl<'tcx> Repr<'tcx> for TyTrait<'tcx> { self.bounds.repr(tcx)) } } + +impl<'tcx> Repr<'tcx> for vtable_origin<'tcx> { + fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { + match *self { + vtable_static(def_id, ref tys, ref vtable_res) => { + format!("vtable_static({}:{}, {}, {})", + def_id, + ty::item_path_str(tcx, def_id), + tys.repr(tcx), + vtable_res.repr(tcx)) + } + + vtable_param(x, y) => { + format!("vtable_param({}, {})", x, y) + } + + vtable_unboxed_closure(def_id) => { + format!("vtable_unboxed_closure({})", def_id) + } + + vtable_error => { + format!("vtable_error") + } + } + } +} + +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 = + method.generics.types.get_slice(subst::FnSpace) + .iter() + .map(|def| ty::mk_param_from_def(tcx, def)) + .collect(); + let meth_regions: Vec = + 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) +} + diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index de9eb42649845..77092025349e7 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -38,7 +38,6 @@ use middle::subst; use middle::subst::VecPerParamSpace; use middle::ty::{mod, Ty}; use middle::traits; -use middle::typeck; use std::rc::Rc; use syntax::owned_slice::OwnedSlice; use util::ppaux::Repr; @@ -304,23 +303,23 @@ impl<'tcx> TypeFoldable<'tcx> for ty::AutoRef<'tcx> { } } -impl<'tcx> TypeFoldable<'tcx> for typeck::MethodOrigin<'tcx> { - fn fold_with>(&self, folder: &mut F) -> typeck::MethodOrigin<'tcx> { +impl<'tcx> TypeFoldable<'tcx> for ty::MethodOrigin<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::MethodOrigin<'tcx> { match *self { - typeck::MethodStatic(def_id) => { - typeck::MethodStatic(def_id) + ty::MethodStatic(def_id) => { + ty::MethodStatic(def_id) } - typeck::MethodStaticUnboxedClosure(def_id) => { - typeck::MethodStaticUnboxedClosure(def_id) + ty::MethodStaticUnboxedClosure(def_id) => { + ty::MethodStaticUnboxedClosure(def_id) } - typeck::MethodTypeParam(ref param) => { - typeck::MethodTypeParam(typeck::MethodParam { + ty::MethodTypeParam(ref param) => { + ty::MethodTypeParam(ty::MethodParam { trait_ref: param.trait_ref.fold_with(folder), method_num: param.method_num }) } - typeck::MethodTraitObject(ref object) => { - typeck::MethodTraitObject(typeck::MethodObject { + ty::MethodTraitObject(ref object) => { + ty::MethodTraitObject(ty::MethodObject { trait_ref: object.trait_ref.fold_with(folder), object_trait_id: object.object_trait_id, method_num: object.method_num, @@ -331,22 +330,22 @@ impl<'tcx> TypeFoldable<'tcx> for typeck::MethodOrigin<'tcx> { } } -impl<'tcx> TypeFoldable<'tcx> for typeck::vtable_origin<'tcx> { - fn fold_with>(&self, folder: &mut F) -> typeck::vtable_origin<'tcx> { +impl<'tcx> TypeFoldable<'tcx> for ty::vtable_origin<'tcx> { + fn fold_with>(&self, folder: &mut F) -> ty::vtable_origin<'tcx> { match *self { - typeck::vtable_static(def_id, ref substs, ref origins) => { + ty::vtable_static(def_id, ref substs, ref origins) => { let r_substs = substs.fold_with(folder); let r_origins = origins.fold_with(folder); - typeck::vtable_static(def_id, r_substs, r_origins) + ty::vtable_static(def_id, r_substs, r_origins) } - typeck::vtable_param(n, b) => { - typeck::vtable_param(n, b) + ty::vtable_param(n, b) => { + ty::vtable_param(n, b) } - typeck::vtable_unboxed_closure(def_id) => { - typeck::vtable_unboxed_closure(def_id) + ty::vtable_unboxed_closure(def_id) => { + ty::vtable_unboxed_closure(def_id) } - typeck::vtable_error => { - typeck::vtable_error + ty::vtable_error => { + ty::vtable_error } } } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 33de2c9abe928..cbc9dd9145bfb 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -114,6 +114,59 @@ pub struct Options { pub alt_std_name: Option } +pub enum Input { + /// Load source from file + File(Path), + /// The string is the source + Str(String) +} + +impl Input { + pub fn filestem(&self) -> String { + match *self { + Input::File(ref ifile) => ifile.filestem_str().unwrap().to_string(), + Input::Str(_) => "rust_out".to_string(), + } + } +} + +#[deriving(Clone)] +pub struct OutputFilenames { + pub out_directory: Path, + pub out_filestem: String, + pub single_output_file: Option, + pub extra: String, +} + +impl OutputFilenames { + pub fn path(&self, flavor: OutputType) -> Path { + match self.single_output_file { + Some(ref path) => return path.clone(), + None => {} + } + self.temp_path(flavor) + } + + pub fn temp_path(&self, flavor: OutputType) -> Path { + let base = self.out_directory.join(self.filestem()); + match flavor { + OutputTypeBitcode => base.with_extension("bc"), + OutputTypeAssembly => base.with_extension("s"), + OutputTypeLlvmAssembly => base.with_extension("ll"), + OutputTypeObject => base.with_extension("o"), + OutputTypeExe => base, + } + } + + pub fn with_extension(&self, extension: &str) -> Path { + self.out_directory.join(self.filestem()).with_extension(extension) + } + + pub fn filestem(&self) -> String { + format!("{}{}", self.out_filestem, self.extra) + } +} + pub fn host_triple() -> &'static str { // Get the host triple out of the build environment. This ensures that our // idea of the host triple is the same as for the set of libraries we've diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index b739a97f734be..1283e89c29d0c 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -23,8 +23,6 @@ use middle::ty::{ty_param, ty_ptr, ty_rptr, ty_tup, ty_open}; use middle::ty::{ty_unboxed_closure}; use middle::ty::{ty_uniq, ty_trait, ty_int, ty_uint, ty_infer}; use middle::ty; -use middle::typeck; -use middle::typeck::check::regionmanip; use std::rc::Rc; use syntax::abi; @@ -1018,7 +1016,7 @@ impl<'tcx> Repr<'tcx> for ty::FnOutput<'tcx> { } } -impl<'tcx> Repr<'tcx> for typeck::MethodCallee<'tcx> { +impl<'tcx> Repr<'tcx> for ty::MethodCallee<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("MethodCallee {{origin: {}, ty: {}, {}}}", self.origin.repr(tcx), @@ -1027,26 +1025,26 @@ impl<'tcx> Repr<'tcx> for typeck::MethodCallee<'tcx> { } } -impl<'tcx> Repr<'tcx> for typeck::MethodOrigin<'tcx> { +impl<'tcx> Repr<'tcx> for ty::MethodOrigin<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { match self { - &typeck::MethodStatic(def_id) => { + &ty::MethodStatic(def_id) => { format!("MethodStatic({})", def_id.repr(tcx)) } - &typeck::MethodStaticUnboxedClosure(def_id) => { + &ty::MethodStaticUnboxedClosure(def_id) => { format!("MethodStaticUnboxedClosure({})", def_id.repr(tcx)) } - &typeck::MethodTypeParam(ref p) => { + &ty::MethodTypeParam(ref p) => { p.repr(tcx) } - &typeck::MethodTraitObject(ref p) => { + &ty::MethodTraitObject(ref p) => { p.repr(tcx) } } } } -impl<'tcx> Repr<'tcx> for typeck::MethodParam<'tcx> { +impl<'tcx> Repr<'tcx> for ty::MethodParam<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("MethodParam({},{})", self.trait_ref.repr(tcx), @@ -1054,7 +1052,7 @@ impl<'tcx> Repr<'tcx> for typeck::MethodParam<'tcx> { } } -impl<'tcx> Repr<'tcx> for typeck::MethodObject<'tcx> { +impl<'tcx> Repr<'tcx> for ty::MethodObject<'tcx> { fn repr(&self, tcx: &ctxt<'tcx>) -> String { format!("MethodObject({},{},{})", self.trait_ref.repr(tcx), @@ -1293,25 +1291,6 @@ impl<'tcx> Repr<'tcx> for ty::ExplicitSelfCategory { } } - -impl<'tcx> Repr<'tcx> for regionmanip::WfConstraint<'tcx> { - fn repr(&self, tcx: &ctxt) -> String { - match *self { - regionmanip::RegionSubRegionConstraint(_, r_a, r_b) => { - format!("RegionSubRegionConstraint({}, {})", - r_a.repr(tcx), - r_b.repr(tcx)) - } - - regionmanip::RegionSubParamConstraint(_, r, p) => { - format!("RegionSubParamConstraint({}, {})", - r.repr(tcx), - p.repr(tcx)) - } - } - } -} - impl<'tcx> UserString<'tcx> for ParamTy { fn user_string(&self, tcx: &ctxt) -> String { let id = self.idx; diff --git a/src/librustc_trans/driver/driver.rs b/src/librustc_driver/driver.rs similarity index 89% rename from src/librustc_trans/driver/driver.rs rename to src/librustc_driver/driver.rs index d3281ae1c19fc..437b0257a9759 100644 --- a/src/librustc_trans/driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -8,26 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub use self::Input::*; - -use back::link; -use back::write; -use session::Session; -use session::config; -use lint; -use llvm::{ContextRef, ModuleRef}; -use metadata::common::LinkMeta; -use metadata::creader; -use middle::{stability, ty, typeck, reachable}; -use middle::dependency_format; -use middle; -use plugin::load::Plugins; -use plugin::registry::Registry; -use plugin; -use trans; - -use util::common::time; -use util::nodemap::{NodeSet}; +use rustc::session::Session; +use rustc::session::config::{mod, Input, OutputFilenames}; +use rustc::lint; +use rustc::metadata::creader; +use rustc::middle::{stability, ty, reachable}; +use rustc::middle::dependency_format; +use rustc::middle; +use rustc::plugin::load::Plugins; +use rustc::plugin::registry::Registry; +use rustc::plugin; +use rustc::util::common::time; +use rustc_trans::back::link; +use rustc_trans::back::write; +use rustc_trans::save; +use rustc_trans::trans; +use rustc_typeck as typeck; use serialize::{json, Encodable}; @@ -35,7 +31,6 @@ use std::io; use std::io::fs; use std::os; use arena::TypedArena; -use save; use syntax::ast; use syntax::ast_map; use syntax::attr; @@ -113,36 +108,19 @@ pub fn anon_src() -> String { pub fn source_name(input: &Input) -> String { match *input { // FIXME (#9639): This needs to handle non-utf8 paths - FileInput(ref ifile) => ifile.as_str().unwrap().to_string(), - StrInput(_) => anon_src() + Input::File(ref ifile) => ifile.as_str().unwrap().to_string(), + Input::Str(_) => anon_src() } } -pub enum Input { - /// Load source from file - FileInput(Path), - /// The string is the source - StrInput(String) -} - -impl Input { - fn filestem(&self) -> String { - match *self { - FileInput(ref ifile) => ifile.filestem_str().unwrap().to_string(), - StrInput(_) => "rust_out".to_string(), - } - } -} - - pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input) -> ast::Crate { let krate = time(sess.time_passes(), "parsing", (), |_| { match *input { - FileInput(ref file) => { + Input::File(ref file) => { parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess) } - StrInput(ref src) => { + Input::Str(ref src) => { parse::parse_crate_from_source_str(anon_src().to_string(), src.to_string(), cfg.clone(), @@ -342,23 +320,13 @@ pub fn assign_node_ids_and_map<'ast>(sess: &Session, map } -pub struct CrateAnalysis<'tcx> { - pub exp_map2: middle::resolve::ExportMap2, - pub exported_items: middle::privacy::ExportedItems, - pub public_items: middle::privacy::PublicItems, - pub ty_cx: ty::ctxt<'tcx>, - pub reachable: NodeSet, - pub name: String, -} - - /// Run the resolution, typechecking, region checking and other /// miscellaneous analysis passes on the crate. Return various /// structures carrying the results of the analysis. pub fn phase_3_run_analysis_passes<'tcx>(sess: Session, ast_map: ast_map::Map<'tcx>, type_arena: &'tcx TypedArena>, - name: String) -> CrateAnalysis<'tcx> { + name: String) -> ty::CrateAnalysis<'tcx> { let time_passes = sess.time_passes(); let krate = ast_map.krate(); @@ -473,7 +441,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session, time(time_passes, "lint checking", (), |_| lint::check_crate(&ty_cx, &exported_items)); - CrateAnalysis { + ty::CrateAnalysis { exp_map2: exp_map2, ty_cx: ty_cx, exported_items: exported_items, @@ -485,7 +453,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session, pub fn phase_save_analysis(sess: &Session, krate: &ast::Crate, - analysis: &CrateAnalysis, + analysis: &ty::CrateAnalysis, odir: &Option) { if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 { return; @@ -494,25 +462,10 @@ pub fn phase_save_analysis(sess: &Session, save::process_crate(sess, krate, analysis, odir)); } -pub struct ModuleTranslation { - pub llcx: ContextRef, - pub llmod: ModuleRef, -} - -pub struct CrateTranslation { - pub modules: Vec, - pub metadata_module: ModuleTranslation, - pub link: LinkMeta, - pub metadata: Vec, - pub reachable: Vec, - pub crate_formats: dependency_format::Dependencies, - pub no_builtins: bool, -} - /// Run the translation phase to LLVM, after which the AST and analysis can /// be discarded. -pub fn phase_4_translate_to_llvm<'tcx>(analysis: CrateAnalysis<'tcx>) - -> (ty::ctxt<'tcx>, CrateTranslation) { +pub fn phase_4_translate_to_llvm<'tcx>(analysis: ty::CrateAnalysis<'tcx>) + -> (ty::ctxt<'tcx>, trans::CrateTranslation) { let time_passes = analysis.ty_cx.sess.time_passes(); time(time_passes, "resolving dependency formats", (), |_| @@ -520,13 +473,13 @@ pub fn phase_4_translate_to_llvm<'tcx>(analysis: CrateAnalysis<'tcx>) // Option dance to work around the lack of stack once closures. time(time_passes, "translation", analysis, |analysis| - trans::base::trans_crate(analysis)) + trans::trans_crate(analysis)) } /// Run LLVM itself, producing a bitcode file, assembly file or object file /// as a side effect. pub fn phase_5_run_llvm_passes(sess: &Session, - trans: &CrateTranslation, + trans: &trans::CrateTranslation, outputs: &OutputFilenames) { if sess.opts.cg.no_integrated_as { let output_type = config::OutputTypeAssembly; @@ -554,7 +507,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session, /// Run the linker on any artifacts that resulted from the LLVM run. /// This should produce either a finished executable or library. pub fn phase_6_link_output(sess: &Session, - trans: &CrateTranslation, + trans: &trans::CrateTranslation, outputs: &OutputFilenames) { let old_path = os::getenv("PATH").unwrap_or_else(||String::new()); let mut new_path = sess.host_filesearch().get_tools_search_paths(); @@ -639,8 +592,8 @@ fn write_out_deps(sess: &Session, // Use default filename: crate source filename with extension replaced // by ".d" (true, None) => match *input { - FileInput(..) => outputs.with_extension("d"), - StrInput(..) => { + Input::File(..) => outputs.with_extension("d"), + Input::Str(..) => { sess.warn("can not write --dep-info without a filename \ when compiling stdin."); return @@ -751,43 +704,6 @@ pub fn collect_crate_metadata(session: &Session, session.opts.cg.metadata.clone() } -#[deriving(Clone)] -pub struct OutputFilenames { - pub out_directory: Path, - pub out_filestem: String, - pub single_output_file: Option, - extra: String, -} - -impl OutputFilenames { - pub fn path(&self, flavor: config::OutputType) -> Path { - match self.single_output_file { - Some(ref path) => return path.clone(), - None => {} - } - self.temp_path(flavor) - } - - pub fn temp_path(&self, flavor: config::OutputType) -> Path { - let base = self.out_directory.join(self.filestem()); - match flavor { - config::OutputTypeBitcode => base.with_extension("bc"), - config::OutputTypeAssembly => base.with_extension("s"), - config::OutputTypeLlvmAssembly => base.with_extension("ll"), - config::OutputTypeObject => base.with_extension("o"), - config::OutputTypeExe => base, - } - } - - pub fn with_extension(&self, extension: &str) -> Path { - self.out_directory.join(self.filestem()).with_extension(extension) - } - - fn filestem(&self) -> String { - format!("{}{}", self.out_filestem, self.extra) - } -} - pub fn build_output_filenames(input: &Input, odir: &Option, ofile: &Option, diff --git a/src/librustc_trans/driver/mod.rs b/src/librustc_driver/lib.rs similarity index 90% rename from src/librustc_trans/driver/mod.rs rename to src/librustc_driver/lib.rs index 658be9169afdd..33c009cf3291b 100644 --- a/src/librustc_trans/driver/mod.rs +++ b/src/librustc_driver/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2012 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,15 +8,46 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub use syntax::diagnostic; +//! The Rust compiler. +//! +//! # Note +//! +//! This API is completely unstable and subject to change. + +#![crate_name = "rustc_driver"] +#![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, unsafe_destructor)] +#![feature(rustc_diagnostic_macros)] + +extern crate arena; +extern crate flate; +extern crate getopts; +extern crate graphviz; +extern crate libc; +extern crate rustc; +extern crate rustc_typeck; +extern crate rustc_back; +extern crate rustc_trans; +#[phase(plugin, link)] extern crate log; +#[phase(plugin, link)] extern crate syntax; +extern crate serialize; +extern crate "rustc_llvm" as llvm; -use back::link; -use driver::driver::{Input, FileInput, StrInput}; -use session::{config, Session, build_session}; -use lint::Lint; -use lint; -use metadata; +pub use syntax::diagnostic; +use rustc_trans::back::link; +use rustc::session::{config, Session, build_session}; +use rustc::session::config::Input; +use rustc::lint::Lint; +use rustc::lint; +use rustc::metadata; use rustc::DIAGNOSTICS; use std::any::AnyRefExt; @@ -24,14 +55,15 @@ use std::io; use std::os; use std::task::TaskBuilder; -use session::early_error; +use rustc::session::early_error; use syntax::ast; use syntax::parse; use syntax::diagnostic::Emitter; use syntax::diagnostics; -use getopts; +#[cfg(test)] +pub mod test; pub mod driver; pub mod pretty; @@ -89,9 +121,9 @@ fn run_compiler(args: &[String]) { if ifile == "-" { let contents = io::stdin().read_to_end().unwrap(); let src = String::from_utf8(contents).unwrap(); - (StrInput(src), None) + (Input::Str(src), None) } else { - (FileInput(Path::new(ifile)), Some(Path::new(ifile))) + (Input::File(Path::new(ifile)), Some(Path::new(ifile))) } } _ => early_error("multiple input filenames provided") @@ -116,11 +148,11 @@ fn run_compiler(args: &[String]) { let r = matches.opt_strs("Z"); if r.contains(&("ls".to_string())) { match input { - FileInput(ref ifile) => { + Input::File(ref ifile) => { let mut stdout = io::stdout(); list_metadata(&sess, &(*ifile), &mut stdout).unwrap(); } - StrInput(_) => { + Input::Str(_) => { early_error("can not list metadata for stdin"); } } @@ -411,12 +443,12 @@ fn print_crate_info(sess: &Session, fn parse_crate_attrs(sess: &Session, input: &Input) -> Vec { let result = match *input { - FileInput(ref ifile) => { + Input::File(ref ifile) => { parse::parse_crate_attrs_from_file(ifile, Vec::new(), &sess.parse_sess) } - StrInput(ref src) => { + Input::Str(ref src) => { parse::parse_crate_attrs_from_source_str( driver::anon_src().to_string(), src.to_string(), @@ -438,13 +470,7 @@ pub fn list_metadata(sess: &Session, path: &Path, /// The diagnostic emitter yielded to the procedure should be used for reporting /// errors of the compiler. pub fn monitor(f: proc():Send) { - // FIXME: This is a hack for newsched since it doesn't support split stacks. - // rustc needs a lot of stack! When optimizations are disabled, it needs - // even *more* stack than usual as well. - #[cfg(rtopt)] - static STACK_SIZE: uint = 6000000; // 6MB - #[cfg(not(rtopt))] - static STACK_SIZE: uint = 20000000; // 20MB + static STACK_SIZE: uint = 32000000; // 32MB let (tx, rx) = channel(); let w = io::ChanWriter::new(tx); @@ -507,3 +533,9 @@ pub fn monitor(f: proc():Send) { } } +pub fn main() { + let args = std::os::args(); + let result = run(args); + std::os::set_exit_status(result); +} + diff --git a/src/test/compile-fail/rustc-diagnostics-2.rs b/src/librustc_driver/mod.rs similarity index 59% rename from src/test/compile-fail/rustc-diagnostics-2.rs rename to src/librustc_driver/mod.rs index c4e011bcea042..1fbbc9c05213b 100644 --- a/src/test/compile-fail/rustc-diagnostics-2.rs +++ b/src/librustc_driver/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,13 +8,3 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_diagnostic_macros)] - -__register_diagnostic!(E0001) -__register_diagnostic!(E0001) -//~^ ERROR diagnostic code E0001 already registered - -fn main() { -} - -__build_diagnostic_array!(DIAGNOSTICS) diff --git a/src/librustc_trans/driver/pretty.rs b/src/librustc_driver/pretty.rs similarity index 97% rename from src/librustc_trans/driver/pretty.rs rename to src/librustc_driver/pretty.rs index 7bb83d7c2a819..b6441ab4944f7 100644 --- a/src/librustc_trans/driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -15,18 +15,18 @@ pub use self::PpSourceMode::*; pub use self::PpMode::*; use self::NodesMatchingUII::*; -use back::link; +use rustc_trans::back::link; -use session::{config, Session}; -use driver::driver::{mod, CrateAnalysis}; +use driver; -use middle::ty; -use middle::borrowck::{mod, FnPartsWithCFG}; -use middle::borrowck::graphviz as borrowck_dot; -use middle::cfg; -use middle::cfg::graphviz::LabelledCFG; - -use util::ppaux; +use rustc::middle::ty; +use rustc::middle::borrowck::{mod, FnPartsWithCFG}; +use rustc::middle::borrowck::graphviz as borrowck_dot; +use rustc::middle::cfg; +use rustc::middle::cfg::graphviz::LabelledCFG; +use rustc::session::Session; +use rustc::session::config::{mod, Input}; +use rustc::util::ppaux; use syntax::ast; use syntax::ast_map::{mod, blocks, NodePrinter}; @@ -242,7 +242,7 @@ impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> { struct TypedAnnotation<'tcx> { - analysis: CrateAnalysis<'tcx>, + analysis: ty::CrateAnalysis<'tcx>, } impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> { @@ -409,7 +409,7 @@ fn needs_expansion(ppm: &PpMode) -> bool { pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, - input: &driver::Input, + input: &Input, ppm: PpMode, opt_uii: Option, ofile: Option) { @@ -536,7 +536,7 @@ pub fn pretty_print_input(sess: Session, } fn print_flowgraph(variants: Vec, - analysis: CrateAnalysis, + analysis: ty::CrateAnalysis, code: blocks::Code, mut out: W) -> io::IoResult<()> { let ty_cx = &analysis.ty_cx; diff --git a/src/librustc_trans/test.rs b/src/librustc_driver/test.rs similarity index 97% rename from src/librustc_trans/test.rs rename to src/librustc_driver/test.rs index 41fbe85576933..9404802cb681b 100644 --- a/src/librustc_trans/test.rs +++ b/src/librustc_driver/test.rs @@ -10,28 +10,28 @@ //! # Standalone Tests for the Inference Module -use driver::diagnostic; -use driver::diagnostic::Emitter; -use driver::driver; -use middle::lang_items; -use middle::region::{mod, CodeExtent}; -use middle::resolve; -use middle::resolve_lifetime; -use middle::stability; -use middle::subst; -use middle::subst::Subst; -use middle::ty::{mod, Ty}; -use middle::typeck::infer::combine::Combine; -use middle::typeck::infer; -use middle::typeck::infer::lub::Lub; -use middle::typeck::infer::glb::Glb; -use session::{mod,config}; +use diagnostic; +use diagnostic::Emitter; +use driver; +use rustc_typeck::middle::lang_items; +use rustc_typeck::middle::region::{mod, CodeExtent}; +use rustc_typeck::middle::resolve; +use rustc_typeck::middle::resolve_lifetime; +use rustc_typeck::middle::stability; +use rustc_typeck::middle::subst; +use rustc_typeck::middle::subst::Subst; +use rustc_typeck::middle::ty::{mod, Ty}; +use rustc_typeck::middle::infer::combine::Combine; +use rustc_typeck::middle::infer; +use rustc_typeck::middle::infer::lub::Lub; +use rustc_typeck::middle::infer::glb::Glb; +use rustc_typeck::util::ppaux::{ty_to_string, Repr, UserString}; +use rustc::session::{mod,config}; use syntax::{abi, ast, ast_map, ast_util}; use syntax::codemap; use syntax::codemap::{Span, CodeMap, DUMMY_SP}; use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note, Help}; use syntax::parse::token; -use util::ppaux::{ty_to_string, Repr, UserString}; use arena::TypedArena; @@ -108,7 +108,7 @@ fn test_env(source_string: &str, let sess = session::build_session_(options, None, span_diagnostic_handler); let krate_config = Vec::new(); - let input = driver::StrInput(source_string.to_string()); + let input = config::Input::Str(source_string.to_string()); let krate = driver::phase_1_parse_input(&sess, krate_config, &input); let krate = driver::phase_2_configure_and_expand(&sess, krate, "test", None) .expect("phase 2 aborted"); diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index d8cdffe210057..6057f9d908190 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -13,15 +13,13 @@ use super::archive; use super::rpath; use super::rpath::RPathConfig; use super::svh::Svh; -use driver::driver::{CrateTranslation, OutputFilenames, Input, FileInput}; use session::config; use session::config::NoDebugInfo; -use session::config::{OutputTypeBitcode, OutputTypeExe, OutputTypeObject}; +use session::config::{OutputFilenames, Input, OutputTypeBitcode, OutputTypeExe, OutputTypeObject}; use session::Session; use metadata::common::LinkMeta; use metadata::{encoder, cstore, filesearch, csearch, creader}; -use trans::context::CrateContext; -use trans::common::gensym_name; +use trans::{CrateContext, CrateTranslation, gensym_name}; use middle::ty::{mod, Ty}; use util::common::time; use util::ppaux; @@ -156,7 +154,7 @@ pub fn find_crate_name(sess: Option<&Session>, if let Some((attr, s)) = attr_crate_name { return validate(s.get().to_string(), Some(attr.span)); } - if let FileInput(ref path) = *input { + if let Input::File(ref path) = *input { if let Some(s) = path.filestem_str() { return validate(s.to_string(), None); } diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index b923bb076c301..e5ffe2675d6f4 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -10,13 +10,13 @@ use back::lto; use back::link::{get_cc_prog, remove}; -use driver::driver::{CrateTranslation, ModuleTranslation, OutputFilenames}; -use session::config::{NoDebugInfo, Passes, SomePasses, AllPasses}; +use session::config::{OutputFilenames, NoDebugInfo, Passes, SomePasses, AllPasses}; use session::Session; use session::config; use llvm; use llvm::{ModuleRef, TargetMachineRef, PassManagerRef, DiagnosticInfoRef, ContextRef}; use llvm::SMDiagnosticRef; +use trans::{CrateTranslation, ModuleTranslation}; use util::common::time; use syntax::codemap; use syntax::diagnostic; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 4dc8c4d173633..4e25921e0b29b 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -65,17 +65,7 @@ pub mod back { pub mod trans; pub mod save; -pub mod driver; pub mod lib { pub use llvm; } - -pub fn main() { - let args = std::os::args(); - let result = driver::run(args); - std::os::set_exit_status(result); -} - -#[cfg(test)] -pub mod test; diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 7a41be1dbe46f..1482422b8d03e 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -27,10 +27,9 @@ //! the format of the output away from extracting it from the compiler. //! DxrVisitor walks the AST and processes it. -use driver::driver::CrateAnalysis; use session::Session; -use middle::{def, typeck}; +use middle::def; use middle::ty::{mod, Ty}; use std::cell::Cell; @@ -68,7 +67,7 @@ fn generated_code(span: Span) -> bool { struct DxrVisitor<'l, 'tcx: 'l> { sess: &'l Session, - analysis: &'l CrateAnalysis<'tcx>, + analysis: &'l ty::CrateAnalysis<'tcx>, collected_paths: Vec<(NodeId, ast::Path, bool, recorder::Row)>, collecting: bool, @@ -912,10 +911,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { ex: &ast::Expr, args: &Vec>) { let method_map = self.analysis.ty_cx.method_map.borrow(); - let method_callee = &(*method_map)[typeck::MethodCall::expr(ex.id)]; + let method_callee = &(*method_map)[ty::MethodCall::expr(ex.id)]; let (def_id, decl_id) = match method_callee.origin { - typeck::MethodStatic(def_id) | - typeck::MethodStaticUnboxedClosure(def_id) => { + ty::MethodStatic(def_id) | + ty::MethodStaticUnboxedClosure(def_id) => { // method invoked on an object with a concrete type (not a static method) let decl_id = match ty::trait_item_of_item(&self.analysis.ty_cx, @@ -936,14 +935,14 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { }; (Some(def_id), decl_id) } - typeck::MethodTypeParam(ref mp) => { + ty::MethodTypeParam(ref mp) => { // method invoked on a type parameter let trait_item = ty::trait_item(&self.analysis.ty_cx, mp.trait_ref.def_id, mp.method_num); (None, Some(trait_item.def_id())) } - typeck::MethodTraitObject(ref mo) => { + ty::MethodTraitObject(ref mo) => { // method invoked on a trait instance let trait_item = ty::trait_item(&self.analysis.ty_cx, mo.trait_ref.def_id, @@ -1473,7 +1472,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> { pub fn process_crate(sess: &Session, krate: &ast::Crate, - analysis: &CrateAnalysis, + analysis: &ty::CrateAnalysis, odir: &Option) { if generated_code(krate.span) { return; diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 84a6b59934f6e..9d0e096c71d64 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -28,9 +28,11 @@ pub use self::ValueOrigin::*; pub use self::scalar_type::*; +use super::CrateTranslation; +use super::ModuleTranslation; + use back::link::{mangle_exported_name}; use back::{link, abi}; -use driver::driver::{CrateAnalysis, CrateTranslation, ModuleTranslation}; use lint; use llvm::{BasicBlockRef, Linkage, ValueRef, Vector, get_param}; use llvm; @@ -1078,12 +1080,6 @@ pub fn store_ty(cx: Block, v: ValueRef, dst: ValueRef, t: Ty) { }; } -pub fn ignore_lhs(_bcx: Block, local: &ast::Local) -> bool { - match local.pat.node { - ast::PatWild(ast::PatWildSingle) => true, _ => false - } -} - pub fn init_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, local: &ast::Local) -> Block<'blk, 'tcx> { debug!("init_local(bcx={}, local.id={})", bcx.to_str(), local.id); @@ -2916,12 +2912,6 @@ fn register_method(ccx: &CrateContext, id: ast::NodeId, llfn } -pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef { - unsafe { - return llvm::LLVMConstPtrToInt(v, ccx.int_type().to_ref()); - } -} - pub fn crate_ctxt_to_encode_parms<'a, 'tcx>(cx: &'a SharedCrateContext<'tcx>, ie: encoder::EncodeInlinedItem<'a>) -> encoder::EncodeParams<'a, 'tcx> { @@ -3055,9 +3045,9 @@ fn internalize_symbols(cx: &SharedCrateContext, reachable: &HashSet) { } } -pub fn trans_crate<'tcx>(analysis: CrateAnalysis<'tcx>) +pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>) -> (ty::ctxt<'tcx>, CrateTranslation) { - let CrateAnalysis { ty_cx: tcx, exp_map2, reachable, name, .. } = analysis; + let ty::CrateAnalysis { ty_cx: tcx, exp_map2, reachable, name, .. } = analysis; let krate = tcx.map.krate(); // Before we touch LLVM, make sure that multithreading is enabled. diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 176fe7096e751..746109ef11346 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -49,8 +49,7 @@ use trans::monomorphize; use trans::type_::Type; use trans::type_of; use middle::ty::{mod, Ty}; -use middle::typeck::coherence::make_substs_for_receiver_types; -use middle::typeck::MethodCall; +use middle::ty::MethodCall; 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 diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index febb33f6c54af..a8256176c2658 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -19,6 +19,7 @@ use llvm; use llvm::{ValueRef, BasicBlockRef, BuilderRef, ContextRef}; use llvm::{True, False, Bool}; use middle::def; +use middle::infer; use middle::lang_items::LangItem; use middle::mem_categorization as mc; use middle::region; @@ -36,8 +37,6 @@ use middle::traits; use middle::ty::{mod, Ty}; use middle::ty_fold; use middle::ty_fold::TypeFoldable; -use middle::typeck; -use middle::typeck::infer; use util::ppaux::Repr; use util::nodemap::{DefIdMap, FnvHashMap, NodeMap}; @@ -273,11 +272,6 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> { } } - pub fn out_arg_pos(&self) -> uint { - assert!(self.caller_expects_out_pointer); - 0u - } - pub fn env_arg_pos(&self) -> uint { if self.caller_expects_out_pointer { 1u @@ -468,7 +462,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { Ok(node_id_type(self, id)) } - fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option> { + fn node_method_ty(&self, method_call: ty::MethodCall) -> Option> { self.tcx() .method_map .borrow() @@ -481,7 +475,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { } fn is_method_call(&self, id: ast::NodeId) -> bool { - self.tcx().method_map.borrow().contains_key(&typeck::MethodCall::expr(id)) + self.tcx().method_map.borrow().contains_key(&ty::MethodCall::expr(id)) } fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option { @@ -870,7 +864,7 @@ pub enum ExprOrMethodCall { ExprId(ast::NodeId), // Type parameters for a method call like `a.foo::()` - MethodCall(typeck::MethodCall) + MethodCall(ty::MethodCall) } pub fn node_id_substs<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index 8220645cec78b..fd9d6b8f2c3b2 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -347,10 +347,6 @@ impl<'tcx> SharedCrateContext<'tcx> { &self.link_meta } - pub fn symbol_hasher<'a>(&'a self) -> &'a RefCell { - &self.symbol_hasher - } - pub fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { &self.tcx } diff --git a/src/librustc_trans/trans/controlflow.rs b/src/librustc_trans/trans/controlflow.rs index 3d32f6045a771..a1574aa2f0e43 100644 --- a/src/librustc_trans/trans/controlflow.rs +++ b/src/librustc_trans/trans/controlflow.rs @@ -27,7 +27,7 @@ use trans::meth; use trans::type_::Type; use trans; use middle::ty; -use middle::typeck::MethodCall; +use middle::ty::MethodCall; use session::config::FullDebugInfo; use util::ppaux::Repr; use util::ppaux; diff --git a/src/librustc_trans/trans/datum.rs b/src/librustc_trans/trans/datum.rs index f0fd94958ee97..532ef69081866 100644 --- a/src/librustc_trans/trans/datum.rs +++ b/src/librustc_trans/trans/datum.rs @@ -352,13 +352,6 @@ impl<'tcx> Datum<'tcx, Expr> { |_| bcx.sess().bug("assert_lvalue given rvalue")) } - /// Asserts that this datum *is* an lvalue and returns it. - pub fn assert_rvalue(self, bcx: Block) -> Datum<'tcx, Rvalue> { - self.match_kind( - |_| bcx.sess().bug("assert_rvalue given lvalue"), - |r| r) - } - pub fn store_to_dest<'blk>(self, bcx: Block<'blk, 'tcx>, dest: expr::Dest, diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 646ee601a4ca4..d130dc0a55b1c 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -41,15 +41,23 @@ use middle::def; use middle::mem_categorization::Typer; use middle::subst::{mod, Subst}; use trans::{_match, adt, asm, base, callee, closure, consts, controlflow}; -use trans::{debuginfo, glue, machine, meth, inline, tvec, type_of}; use trans::base::*; use trans::build::*; use trans::cleanup::{mod, CleanupMethods}; use trans::common::*; use trans::datum::*; -use middle::ty::{mod, struct_fields, tup_fields}; -use middle::ty::{AdjustDerefRef, AdjustAddEnv, AutoUnsafe, AutoPtr, Ty}; -use middle::typeck::{mod, MethodCall}; +use trans::debuginfo; +use trans::glue; +use trans::machine; +use trans::meth; +use trans::inline; +use trans::tvec; +use trans::type_of; +use middle::ty::{struct_fields, tup_fields}; +use middle::ty::{AdjustDerefRef, AdjustAddEnv, AutoUnsafe}; +use middle::ty::{AutoPtr}; +use middle::ty::{mod, Ty}; +use middle::ty::MethodCall; use util::common::indenter; use util::ppaux::Repr; use trans::machine::{llsize_of, llsize_of_alloc}; @@ -2091,7 +2099,7 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // path (below) to dereference that `&T`. let datum = match method_call.adjustment { // Always perform an AutoPtr when applying an overloaded auto-deref - typeck::AutoDeref(_) => unpack_datum!(bcx, auto_ref(bcx, datum, expr)), + ty::AutoDeref(_) => unpack_datum!(bcx, auto_ref(bcx, datum, expr)), _ => datum }; diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index ef431243b31e9..94ff526debd1e 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -31,8 +31,7 @@ use trans::machine; use trans::type_::Type; use trans::type_of::*; use middle::ty::{mod, Ty}; -use middle::typeck; -use middle::typeck::MethodCall; +use middle::ty::MethodCall; use util::ppaux::Repr; use std::c_str::ToCStr; @@ -119,8 +118,8 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, .unwrap(); match origin { - typeck::MethodStatic(did) | - typeck::MethodStaticUnboxedClosure(did) => { + ty::MethodStatic(did) | + ty::MethodStaticUnboxedClosure(did) => { Callee { bcx: bcx, data: Fn(callee::trans_fn_ref(bcx, @@ -129,7 +128,7 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } } - typeck::MethodTypeParam(typeck::MethodParam { + ty::MethodTypeParam(ty::MethodParam { ref trait_ref, method_num }) => { @@ -147,7 +146,7 @@ pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, method_num, origin) } - typeck::MethodTraitObject(ref mt) => { + ty::MethodTraitObject(ref mt) => { let self_expr = match self_expr { Some(self_expr) => self_expr, None => { diff --git a/src/librustc_trans/trans/mod.rs b/src/librustc_trans/trans/mod.rs index fe7697447acda..c00c477f4b8d2 100644 --- a/src/librustc_trans/trans/mod.rs +++ b/src/librustc_trans/trans/mod.rs @@ -8,40 +8,64 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub mod doc; -pub mod macros; -pub mod inline; -pub mod monomorphize; -pub mod controlflow; -pub mod glue; -pub mod datum; -pub mod callee; -pub mod expr; -pub mod common; -pub mod context; -pub mod consts; -pub mod type_of; -pub mod build; -pub mod builder; -pub mod base; -pub mod _match; -pub mod closure; -pub mod tvec; -pub mod meth; -pub mod cabi; -pub mod cabi_x86; -pub mod cabi_x86_64; -pub mod cabi_x86_win64; -pub mod cabi_arm; -pub mod cabi_mips; -pub mod foreign; -pub mod intrinsic; -pub mod debuginfo; -pub mod machine; -pub mod adt; -pub mod asm; -pub mod type_; -pub mod value; -pub mod basic_block; -pub mod llrepr; -pub mod cleanup; +use llvm::{ContextRef, ModuleRef}; +use metadata::common::LinkMeta; +use middle::dependency_format; + +pub use self::base::trans_crate; +pub use self::context::CrateContext; +pub use self::common::gensym_name; + +mod doc; +mod macros; +mod inline; +mod monomorphize; +mod controlflow; +mod glue; +mod datum; +mod callee; +mod expr; +mod common; +mod context; +mod consts; +mod type_of; +mod build; +mod builder; +mod base; +mod _match; +mod closure; +mod tvec; +mod meth; +mod cabi; +mod cabi_x86; +mod cabi_x86_64; +mod cabi_x86_win64; +mod cabi_arm; +mod cabi_mips; +mod foreign; +mod intrinsic; +mod debuginfo; +mod machine; +mod adt; +mod asm; +mod type_; +mod value; +mod basic_block; +mod llrepr; +mod cleanup; + +pub struct ModuleTranslation { + pub llcx: ContextRef, + pub llmod: ModuleRef, +} + +pub struct CrateTranslation { + pub modules: Vec, + pub metadata_module: ModuleTranslation, + pub link: LinkMeta, + pub metadata: Vec, + pub reachable: Vec, + pub crate_formats: dependency_format::Dependencies, + pub no_builtins: bool, +} + diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc_typeck/astconv.rs similarity index 95% rename from src/librustc/middle/typeck/astconv.rs rename to src/librustc_typeck/astconv.rs index 89c004fc64596..d95ad9a11c87f 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -46,17 +46,17 @@ //! Note that the self region for the `foo` defaulted to `&` in the first //! case but `&a` in the second. Basically, defaults that appear inside //! an rptr (`&r.T`) use the region `r` that appears in the rptr. + +use middle::astconv_util::{ast_ty_to_prim_ty, check_path_args, NO_TPS, NO_REGIONS}; use middle::const_eval; use middle::def; 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 rscope::{mod, UnelidableRscope, RegionScope, SpecificRscope, + ShiftedRscope, BindingRscope}; +use TypeAndSubsts; use util::common::ErrorReported; use util::nodemap::DefIdMap; use util::ppaux::{mod, Repr, UserString}; @@ -428,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)); @@ -553,74 +553,6 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>( } } -pub const NO_REGIONS: uint = 1; -pub const NO_TPS: uint = 2; - -fn check_path_args(tcx: &ty::ctxt, - path: &ast::Path, - flags: uint) { - if (flags & NO_TPS) != 0u { - if path.segments.iter().any(|s| s.parameters.has_types()) { - span_err!(tcx.sess, path.span, E0109, - "type parameters are not allowed on this type"); - } - } - - if (flags & NO_REGIONS) != 0u { - if path.segments.iter().any(|s| s.parameters.has_lifetimes()) { - span_err!(tcx.sess, path.span, E0110, - "region parameters are not allowed on this type"); - } - } -} - -pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty) - -> Option> { - match ast_ty.node { - ast::TyPath(ref path, id) => { - let a_def = match tcx.def_map.borrow().get(&id) { - None => { - tcx.sess.span_bug(ast_ty.span, - format!("unbound path {}", - path.repr(tcx)).as_slice()) - } - Some(&d) => d - }; - match a_def { - def::DefPrimTy(nty) => { - match nty { - ast::TyBool => { - check_path_args(tcx, path, NO_TPS | NO_REGIONS); - Some(ty::mk_bool()) - } - ast::TyChar => { - check_path_args(tcx, path, NO_TPS | NO_REGIONS); - Some(ty::mk_char()) - } - ast::TyInt(it) => { - check_path_args(tcx, path, NO_TPS | NO_REGIONS); - Some(ty::mk_mach_int(it)) - } - ast::TyUint(uit) => { - check_path_args(tcx, path, NO_TPS | NO_REGIONS); - Some(ty::mk_mach_uint(uit)) - } - ast::TyFloat(ft) => { - check_path_args(tcx, path, NO_TPS | NO_REGIONS); - Some(ty::mk_mach_float(ft)) - } - ast::TyStr => { - Some(ty::mk_str(tcx)) - } - } - } - _ => None - } - } - _ => None - } -} - /// Converts the given AST type to a built-in type. A "built-in type" is, at /// present, either a core numeric type, a string, or `Box`. pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( @@ -1544,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 diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs similarity index 98% rename from src/librustc/middle/typeck/check/_match.rs rename to src/librustc_typeck/check/_match.rs index cdfd607d06710..7dcf0aa3e2189 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -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 middle::typeck::check::{check_expr, check_expr_has_type, demand, FnCtxt}; -use middle::typeck::check::{instantiate_path, structurally_resolved_type, valid_range_bounds}; -use middle::typeck::infer::{mod, resolve}; -use middle::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; diff --git a/src/librustc/middle/typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs similarity index 99% rename from src/librustc/middle/typeck/check/closure.rs rename to src/librustc_typeck/check/closure.rs index 0a93b3a5ec7dc..34030ae4493a2 100644 --- a/src/librustc/middle/typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -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 middle::typeck::astconv; -use middle::typeck::infer; -use middle::typeck::rscope::RegionScope; +use rscope::RegionScope; use syntax::abi; use syntax::ast; use syntax::ast_util; diff --git a/src/librustc/middle/typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs similarity index 86% rename from src/librustc/middle/typeck/check/demand.rs rename to src/librustc_typeck/check/demand.rs index 1e45d059b849b..2b8a52f050d6f 100644 --- a/src/librustc/middle/typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -9,11 +9,11 @@ // except according to those terms. +use check::FnCtxt; use middle::ty::{mod, Ty}; -use middle::typeck::check::FnCtxt; -use middle::typeck::infer; -use middle::typeck::infer::resolve_type; -use middle::typeck::infer::resolve::try_resolve_tvar_shallow; +use middle::infer; +use middle::infer::resolve_type; +use middle::infer::resolve::try_resolve_tvar_shallow; use std::result::{Err, Ok}; use std::result; @@ -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, diff --git a/src/librustc/middle/typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs similarity index 99% rename from src/librustc/middle/typeck/check/method/confirm.rs rename to src/librustc_typeck/check/method/confirm.rs index e866627be3d29..1fe73f0478d56 100644 --- a/src/librustc/middle/typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -10,13 +10,14 @@ use super::probe; +use check::{mod, FnCtxt, NoPreference, PreferMutLvalue}; use middle::subst::{mod, Subst}; use middle::traits; use middle::ty::{mod, Ty}; -use middle::typeck::check::{mod, FnCtxt, NoPreference, PreferMutLvalue}; -use middle::typeck::{MethodCall, MethodCallee, MethodObject, MethodOrigin, - MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam}; -use middle::typeck::infer::{mod, InferCtxt}; +use middle::ty::{MethodCall, MethodCallee, MethodObject, MethodOrigin, + MethodParam, MethodStatic, MethodTraitObject, MethodTypeParam}; +use middle::infer; +use middle::infer::InferCtxt; use middle::ty_fold::HigherRankedFoldable; use syntax::ast; use syntax::codemap::Span; diff --git a/src/librustc/middle/typeck/check/method/doc.rs b/src/librustc_typeck/check/method/doc.rs similarity index 100% rename from src/librustc/middle/typeck/check/method/doc.rs rename to src/librustc_typeck/check/method/doc.rs diff --git a/src/librustc/middle/typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs similarity index 98% rename from src/librustc/middle/typeck/check/method/mod.rs rename to src/librustc_typeck/check/method/mod.rs index 34c3292f8cd69..f87a4c9294bab 100644 --- a/src/librustc/middle/typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -10,19 +10,17 @@ //! 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 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 middle::typeck::infer; -use middle::typeck::{MethodCallee}; -use middle::typeck::{MethodParam, MethodTypeParam}; +use middle::infer; use util::ppaux::{Repr, UserString}; use std::rc::Rc; diff --git a/src/librustc/middle/typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs similarity index 99% rename from src/librustc/middle/typeck/check/method/probe.rs rename to src/librustc_typeck/check/method/probe.rs index 484d72130e61d..6ff276edbce7e 100644 --- a/src/librustc/middle/typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -12,17 +12,17 @@ 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; 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 middle::typeck::{MethodObject}; -use middle::typeck::infer; -use middle::typeck::infer::InferCtxt; +use middle::infer; +use middle::infer::InferCtxt; use syntax::ast; use syntax::codemap::{Span, DUMMY_SP}; use std::collections::HashSet; diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs similarity index 99% rename from src/librustc/middle/typeck/check/mod.rs rename to src/librustc_typeck/check/mod.rs index 641cbd11d64e0..a0f3f2734d976 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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,8 +82,10 @@ 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; use middle::mem_categorization::{mod, McResult}; use middle::pat_util::{mod, pat_id_map}; @@ -93,12 +95,12 @@ use middle::ty::{FnSig, VariantInfo, Polytype}; use middle::ty::{Disr, ParamTy, ParameterEnvironment}; 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::{mod, CrateCtxt, infer, lookup_def_ccx, no_params, require_same_types}; -use middle::typeck::{MethodCall, MethodCallee, MethodMap, ObjectCastMap, 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}; @@ -279,7 +281,7 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> { fn node_ty(&self, id: ast::NodeId) -> McResult> { Ok(self.node_ty(id)) } - fn node_method_ty(&self, method_call: typeck::MethodCall) + fn node_method_ty(&self, method_call: ty::MethodCall) -> Option> { self.inh.method_map.borrow().get(&method_call).map(|m| m.ty) } @@ -287,7 +289,7 @@ impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> { &self.inh.adjustments } fn is_method_call(&self, id: ast::NodeId) -> bool { - self.inh.method_map.borrow().contains_key(&typeck::MethodCall::expr(id)) + self.inh.method_map.borrow().contains_key(&ty::MethodCall::expr(id)) } fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option { self.tcx().temporary_scope(rvalue_id) @@ -359,6 +361,17 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckItemTypesVisitor<'a, 'tcx> { check_item(self.ccx, i); visit::walk_item(self, i); } + + fn visit_ty(&mut self, t: &ast::Ty) { + match t.node { + ast::TyFixedLengthVec(_, ref expr) => { + check_const_in_type(self.ccx, &**expr, ty::mk_uint()); + } + _ => {} + } + + visit::walk_ty(self, t); + } } pub fn check_item_types(ccx: &CrateCtxt) { @@ -1860,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, @@ -1919,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>, @@ -3260,7 +3256,7 @@ fn check_expr_with_unifier<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, Some(method) => { let method_ty = method.ty; // HACK(eddyb) Fully qualified path to work around a resolve bug. - let method_call = ::middle::typeck::MethodCall::expr(op_ex.id); + let method_call = ::middle::ty::MethodCall::expr(op_ex.id); fcx.inh.method_map.borrow_mut().insert(method_call, method); match check_method_argument_types(fcx, op_ex.span, @@ -4670,25 +4666,18 @@ fn check_block_with_expected<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, /// Checks a constant appearing in a type. At the moment this is just the /// length expression in a fixed-length vector, but someday it might be /// extended to type-level numeric literals. -pub fn check_const_in_type<'tcx>(tcx: &ty::ctxt<'tcx>, - expr: &ast::Expr, - expected_type: Ty<'tcx>) { - // Synthesize a crate context. The trait map is not needed here (though I - // imagine it will be if we have associated statics --pcwalton), so we - // leave it blank. - let ccx = CrateCtxt { - trait_map: NodeMap::new(), - tcx: tcx, - }; - let inh = static_inherited_fields(&ccx); - let fcx = blank_fn_ctxt(&ccx, &inh, ty::FnConverging(expected_type), expr.id); +fn check_const_in_type<'a,'tcx>(ccx: &'a CrateCtxt<'a,'tcx>, + expr: &ast::Expr, + expected_type: Ty<'tcx>) { + let inh = static_inherited_fields(ccx); + let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(expected_type), expr.id); check_const_with_ty(&fcx, expr.span, expr, expected_type); } -pub fn check_const(ccx: &CrateCtxt, - sp: Span, - e: &ast::Expr, - id: ast::NodeId) { +fn check_const(ccx: &CrateCtxt, + sp: Span, + e: &ast::Expr, + id: ast::NodeId) { let inh = static_inherited_fields(ccx); let rty = ty::node_id_to_type(ccx.tcx, id); let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(rty), e.id); @@ -4696,10 +4685,10 @@ pub fn check_const(ccx: &CrateCtxt, check_const_with_ty(&fcx, sp, e, declty); } -pub fn check_const_with_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, - _: Span, - e: &ast::Expr, - declty: Ty<'tcx>) { +fn check_const_with_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, + _: Span, + e: &ast::Expr, + declty: Ty<'tcx>) { // Gather locals in statics (because of block expressions). // This is technically unnecessary because locals in static items are forbidden, // but prevents type checking from blowing up before const checking can properly diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs similarity index 99% rename from src/librustc/middle/typeck/check/regionck.rs rename to src/librustc_typeck/check/regionck.rs index 08f7f9cf5e37f..2aec4393de942 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -114,20 +114,19 @@ //! 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}; -use middle::typeck::astconv::AstConv; -use middle::typeck::check::FnCtxt; -use middle::typeck::check::regionmanip; -use middle::typeck::check::vtable; -use middle::typeck::infer::resolve_and_force_all_but_regions; -use middle::typeck::infer::resolve_type; -use middle::typeck::infer; -use middle::typeck::MethodCall; +use middle::ty::{mod, Ty, MethodCall}; +use middle::infer::resolve_and_force_all_but_regions; +use middle::infer::resolve_type; +use middle::infer; use middle::pat_util; use util::nodemap::{DefIdMap, NodeMap, FnvHashMap}; use util::ppaux::{ty_to_string, Repr}; diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc_typeck/check/regionmanip.rs similarity index 96% rename from src/librustc/middle/typeck/check/regionmanip.rs rename to src/librustc_typeck/check/regionmanip.rs index 55214618aa90b..92dfd8b5f56d2 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc_typeck/check/regionmanip.rs @@ -380,3 +380,22 @@ impl<'a, 'tcx> Wf<'a, 'tcx> { } } } + +impl<'tcx> Repr<'tcx> for WfConstraint<'tcx> { + fn repr(&self, tcx: &ty::ctxt) -> String { + match *self { + RegionSubRegionConstraint(_, r_a, r_b) => { + format!("RegionSubRegionConstraint({}, {})", + r_a.repr(tcx), + r_b.repr(tcx)) + } + + RegionSubParamConstraint(_, r, p) => { + format!("RegionSubParamConstraint({}, {})", + r.repr(tcx), + p.repr(tcx)) + } + } + } +} + diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc_typeck/check/vtable.rs similarity index 99% rename from src/librustc/middle/typeck/check/vtable.rs rename to src/librustc_typeck/check/vtable.rs index 84cb74b4de248..c2b263885bd73 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc_typeck/check/vtable.rs @@ -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,9 +16,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, - structurally_resolved_type}; -use middle::typeck::infer; +use middle::infer; use std::rc::Rc; use syntax::ast; use syntax::codemap::Span; diff --git a/src/librustc/middle/typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs similarity index 99% rename from src/librustc/middle/typeck/check/wf.rs rename to src/librustc_typeck/check/wf.rs index 8535ec4fa6e80..1769c588ec1de 100644 --- a/src/librustc/middle/typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -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 middle::typeck::astconv::AstConv; -use middle::typeck::check::{FnCtxt, Inherited, blank_fn_ctxt, vtable, regionck}; -use middle::typeck::CrateCtxt; use util::ppaux::Repr; use std::collections::HashSet; diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs similarity index 97% rename from src/librustc/middle/typeck/check/writeback.rs rename to src/librustc_typeck/check/writeback.rs index 23af30b44d935..777f354bec126 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -13,18 +13,17 @@ // substitutions. use self::ResolveReason::*; +use astconv::AstConv; +use check::FnCtxt; use middle::def; use middle::pat_util; -use middle::ty::{mod, Ty}; +use middle::ty::{mod, Ty, MethodCall, MethodCallee}; use middle::ty_fold::{TypeFolder,TypeFoldable}; -use middle::typeck::astconv::AstConv; -use middle::typeck::check::FnCtxt; -use middle::typeck::infer::{force_all, resolve_all, resolve_region}; -use middle::typeck::infer::resolve_type; -use middle::typeck::infer; -use middle::typeck::{MethodCall, MethodCallee}; -use middle::typeck::write_substs_to_tcx; -use middle::typeck::write_ty_to_tcx; +use middle::infer::{force_all, resolve_all, resolve_region}; +use middle::infer::resolve_type; +use middle::infer; +use write_substs_to_tcx; +use write_ty_to_tcx; use util::ppaux::Repr; use std::cell::Cell; diff --git a/src/librustc/middle/typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs similarity index 94% rename from src/librustc/middle/typeck/coherence/mod.rs rename to src/librustc_typeck/coherence/mod.rs index 758608b79c2cb..b8642ddde4082 100644 --- a/src/librustc/middle/typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -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,10 +30,10 @@ use middle::ty::{ty_closure}; use middle::ty::type_is_ty_var; use middle::subst::Subst; use middle::ty; -use middle::typeck::CrateCtxt; -use middle::typeck::infer::combine::Combine; -use middle::typeck::infer::InferCtxt; -use middle::typeck::infer::{new_infer_ctxt, resolve_ivar, resolve_type}; +use CrateCtxt; +use middle::infer::combine::Combine; +use middle::infer::InferCtxt; +use middle::infer::{new_infer_ctxt, resolve_ivar, resolve_type}; use std::collections::{HashSet}; use std::cell::RefCell; use std::rc::Rc; @@ -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 = - method.generics.types.get_slice(subst::FnSpace) - .iter() - .map(|def| ty::mk_param_from_def(tcx, def)) - .collect(); - let meth_regions: Vec = - 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) -> 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)); diff --git a/src/librustc/middle/typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs similarity index 100% rename from src/librustc/middle/typeck/coherence/orphan.rs rename to src/librustc_typeck/coherence/orphan.rs diff --git a/src/librustc/middle/typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs similarity index 98% rename from src/librustc/middle/typeck/coherence/overlap.rs rename to src/librustc_typeck/coherence/overlap.rs index 9f10a58f45852..0e74d4578d95b 100644 --- a/src/librustc/middle/typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -13,8 +13,7 @@ use middle::traits; use middle::ty; -use middle::typeck::infer::{new_infer_ctxt}; -use middle::typeck::infer; +use middle::infer::{mod, new_infer_ctxt}; use syntax::ast::{DefId}; use syntax::ast::{LOCAL_CRATE}; use syntax::ast; diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc_typeck/collect.rs similarity index 99% rename from src/librustc/middle/typeck/collect.rs rename to src/librustc_typeck/collect.rs index 6e989dd73dbef..717e886029a3d 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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 middle::typeck::astconv::{AstConv, ty_of_arg}; -use middle::typeck::astconv::{ast_ty_to_ty, ast_region_to_region}; -use middle::typeck::astconv; -use middle::typeck::infer; -use middle::typeck::rscope::*; -use middle::typeck::{CrateCtxt, lookup_def_tcx, no_params, write_ty_to_tcx}; -use middle::typeck; +use middle::infer; +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)) })); diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs new file mode 100644 index 0000000000000..36e81f18103b8 --- /dev/null +++ b/src/librustc_typeck/diagnostics.rs @@ -0,0 +1,151 @@ +// 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. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(non_snake_case)] + +register_diagnostic!(E0001, r##" + This error suggests that the expression arm corresponding to the noted pattern + will never be reached as for all possible values of the expression being matched, + one of the preceeding patterns will match. + + This means that perhaps some of the preceeding patterns are too general, this + one is too specific or the ordering is incorrect. +"##) + +register_diagnostics!( + E0002, + E0003, + E0004, + E0005, + E0006, + E0007, + E0008, + E0009, + E0010, + E0011, + E0012, + E0013, + E0014, + E0015, + E0016, + E0017, + E0018, + E0019, + E0020, + E0022, + E0023, + E0024, + E0025, + E0026, + E0027, + E0029, + E0030, + E0031, + E0033, + E0034, + E0035, + E0036, + E0038, + E0040, + E0044, + E0045, + E0046, + E0049, + E0050, + E0051, + E0052, + E0053, + E0054, + E0055, + E0056, + E0057, + E0059, + E0060, + E0061, + E0062, + E0063, + E0066, + E0067, + E0068, + E0069, + E0070, + E0071, + E0072, + E0073, + E0074, + E0075, + E0076, + E0077, + E0079, + E0080, + E0081, + E0082, + E0083, + E0084, + E0085, + E0086, + E0087, + E0088, + E0089, + E0090, + E0091, + E0092, + E0093, + E0094, + E0100, + E0101, + E0102, + E0103, + E0104, + E0106, + E0107, + E0108, + E0109, + E0110, + E0116, + E0117, + E0118, + E0119, + E0120, + E0121, + E0122, + E0124, + E0127, + E0128, + E0129, + E0130, + E0131, + E0132, + E0133, + E0134, + E0135, + E0136, + E0137, + E0138, + E0139, + E0140, + E0141, + E0152, + E0153, + E0157, + E0158, + E0159, + E0161, + E0162, + E0163, + E0164, + E0165, + E0166, + E0167, + E0168, + E0169, + E0171, + E0172 +) diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc_typeck/lib.rs similarity index 60% rename from src/librustc/middle/typeck/mod.rs rename to src/librustc_typeck/lib.rs index 501dfcb2e2d9e..2f5b473567faa 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc_typeck/lib.rs @@ -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,16 +57,40 @@ 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)] -pub use self::ExprAdjustment::*; -pub use self::vtable_origin::*; -pub use self::MethodOrigin::*; +#[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; use middle::subst; use middle::subst::VecPerParamSpace; use middle::ty::{mod, Ty}; @@ -74,222 +98,40 @@ use session::config; use util::common::time; use util::ppaux::Repr; use util::ppaux; -use util::nodemap::{NodeMap, FnvHashMap}; -use std::cell::RefCell; -use std::rc::Rc; 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 infer; -pub mod collect; -pub mod coherence; -pub mod variance; - -#[deriving(Clone, Encodable, Decodable, PartialEq, PartialOrd, Show)] -pub struct param_index { - pub space: subst::ParamSpace, - pub index: uint -} - -#[deriving(Clone, Show)] -pub enum MethodOrigin<'tcx> { - // fully statically resolved method - MethodStatic(ast::DefId), - - // fully statically resolved unboxed closure invocation - MethodStaticUnboxedClosure(ast::DefId), +#[cfg(stage0)] +mod diagnostics; - // method invoked on a type parameter with a bounded trait - MethodTypeParam(MethodParam<'tcx>), - - // method invoked on a trait instance - MethodTraitObject(MethodObject<'tcx>), - -} - -// details for a method invoked with a receiver whose type is a type parameter -// with a bounded trait. -#[deriving(Clone, Show)] -pub struct MethodParam<'tcx> { - // the precise trait reference that occurs as a bound -- this may - // be a supertrait of what the user actually typed. - pub trait_ref: Rc>, - - // index of uint in the list of methods for the trait - pub method_num: uint, -} - -// details for a method invoked with a receiver whose type is an object -#[deriving(Clone, Show)] -pub struct MethodObject<'tcx> { - // the (super)trait containing the method to be invoked - pub trait_ref: Rc>, - - // the actual base trait id of the object - pub object_trait_id: ast::DefId, - - // index of the method to be invoked amongst the trait's methods - pub method_num: uint, - - // index into the actual runtime vtable. - // the vtable is formed by concatenating together the method lists of - // the base object trait and all supertraits; this is the index into - // that vtable - pub real_index: uint, -} - -#[deriving(Clone)] -pub struct MethodCallee<'tcx> { - pub origin: MethodOrigin<'tcx>, - pub ty: Ty<'tcx>, - pub substs: subst::Substs<'tcx> -} - -/// With method calls, we store some extra information in -/// side tables (i.e method_map). We use -/// MethodCall as a key to index into these tables instead of -/// just directly using the expression's NodeId. The reason -/// for this being that we may apply adjustments (coercions) -/// with the resulting expression also needing to use the -/// side tables. The problem with this is that we don't -/// assign a separate NodeId to this new expression -/// and so it would clash with the base expression if both -/// needed to add to the side tables. Thus to disambiguate -/// we also keep track of whether there's an adjustment in -/// our key. -#[deriving(Clone, PartialEq, Eq, Hash, Show)] -pub struct MethodCall { - pub expr_id: ast::NodeId, - pub adjustment: ExprAdjustment -} - -#[deriving(Clone, PartialEq, Eq, Hash, Show, Encodable, Decodable)] -pub enum ExprAdjustment { - NoAdjustment, - AutoDeref(uint), - AutoObject -} +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>, } -impl MethodCall { - pub fn expr(id: ast::NodeId) -> MethodCall { - MethodCall { - expr_id: id, - adjustment: NoAdjustment - } - } - - pub fn autoobject(id: ast::NodeId) -> MethodCall { - MethodCall { - expr_id: id, - adjustment: AutoObject - } - } - - pub fn autoderef(expr_id: ast::NodeId, autoderef: uint) -> MethodCall { - MethodCall { - expr_id: expr_id, - adjustment: AutoDeref(1 + autoderef) - } - } -} - -// maps from an expression id that corresponds to a method call to the details -// of the method to be invoked -pub type MethodMap<'tcx> = RefCell>>; - -pub type vtable_param_res<'tcx> = Vec>; - -// Resolutions for bounds of all parameters, left to right, for a given path. -pub type vtable_res<'tcx> = VecPerParamSpace>; - -#[deriving(Clone)] -pub enum vtable_origin<'tcx> { - /* - Statically known vtable. def_id gives the impl item - from whence comes the vtable, and tys are the type substs. - vtable_res is the vtable itself. - */ - vtable_static(ast::DefId, subst::Substs<'tcx>, vtable_res<'tcx>), - - /* - Dynamic vtable, comes from a parameter that has a bound on it: - fn foo(a: T) -- a's vtable would have a - vtable_param origin - - The first argument is the param index (identifying T in the example), - and the second is the bound number (identifying baz) - */ - vtable_param(param_index, uint), - - /* - Vtable automatically generated for an unboxed closure. The def ID is the - ID of the closure expression. - */ - vtable_unboxed_closure(ast::DefId), - - /* - Asked to determine the vtable for ty_err. This is the value used - for the vtables of `Self` in a virtual call like `foo.bar()` - where `foo` is of object type. The same value is also used when - type errors occur. - */ - vtable_error, -} - -impl<'tcx> Repr<'tcx> for vtable_origin<'tcx> { - fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String { - match *self { - vtable_static(def_id, ref tys, ref vtable_res) => { - format!("vtable_static({}:{}, {}, {})", - def_id, - ty::item_path_str(tcx, def_id), - tys.repr(tcx), - vtable_res.repr(tcx)) - } - - vtable_param(x, y) => { - format!("vtable_param({}, {})", x, y) - } - - vtable_unboxed_closure(def_id) => { - format!("vtable_unboxed_closure({})", def_id) - } - - vtable_error => { - format!("vtable_error") - } - } - } -} - -// For every explicit cast into an object type, maps from the cast -// expr to the associated trait ref. -pub type ObjectCastMap<'tcx> = RefCell>>>; - -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() { @@ -302,7 +144,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(), _ => { @@ -311,12 +153,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()}, @@ -324,7 +166,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, diff --git a/src/librustc/middle/typeck/rscope.rs b/src/librustc_typeck/rscope.rs similarity index 100% rename from src/librustc/middle/typeck/rscope.rs rename to src/librustc_typeck/rscope.rs diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc_typeck/variance.rs similarity index 100% rename from src/librustc/middle/typeck/variance.rs rename to src/librustc_typeck/variance.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6f1ddaff3605f..7e02891160ad2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -39,7 +39,6 @@ use syntax::parse::token; use syntax::ptr::P; use rustc_trans::back::link; -use rustc_trans::driver::driver; use rustc::metadata::cstore; use rustc::metadata::csearch; use rustc::metadata::decoder; @@ -48,6 +47,7 @@ use rustc::middle::subst; use rustc::middle::subst::VecPerParamSpace; use rustc::middle::ty; use rustc::middle::stability; +use rustc::session::config; use std::rc::Rc; use std::u32; @@ -131,7 +131,7 @@ impl<'a, 'tcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx> { externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b)); // Figure out the name of this crate - let input = driver::FileInput(cx.src.clone()); + let input = config::Input::File(cx.src.clone()); let name = link::find_crate_name(None, self.attrs.as_slice(), &input); // Clean the crate, translating the entire libsyntax AST to one that is diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b040a4bfd2a09..4cd88bca51e93 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -9,7 +9,7 @@ // except according to those terms. pub use self::MaybeTyped::*; -use rustc_trans::driver::driver; +use rustc_driver::driver; use rustc::session::{mod, config}; use rustc::middle::{privacy, ty}; use rustc::lint; @@ -83,7 +83,7 @@ pub fn run_core(libs: Vec, cfgs: Vec, externs: Externs, // Parse, resolve, and typecheck the given crate. - let input = driver::FileInput(cpath.clone()); + let input = config::Input::File(cpath.clone()); let warning_lint = lint::builtin::WARNINGS.name_lower(); @@ -122,7 +122,7 @@ pub fn run_core(libs: Vec, cfgs: Vec, externs: Externs, let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest); let type_arena = TypedArena::new(); - let driver::CrateAnalysis { + let ty::CrateAnalysis { exported_items, public_items, ty_cx, .. } = driver::phase_3_run_analysis_passes(sess, ast_map, &type_arena, name); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index cc946a6ca4a96..1e7de50cf879d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -21,6 +21,7 @@ extern crate getopts; extern crate libc; extern crate rustc; extern crate rustc_trans; +extern crate rustc_driver; extern crate serialize; extern crate syntax; extern crate "test" as testing; @@ -163,7 +164,7 @@ pub fn main_args(args: &[String]) -> int { usage(args[0].as_slice()); return 0; } else if matches.opt_present("version") { - match rustc_trans::driver::version("rustdoc", &matches) { + match rustc_driver::version("rustdoc", &matches) { Some(err) => { println!("{}", err); return 1 diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 2a5972bb3d90b..7ca7ae4b21149 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -19,7 +19,7 @@ use std::string::String; use std::collections::{HashSet, HashMap}; use testing; use rustc::session::{mod, config}; -use rustc_trans::driver::driver; +use rustc_driver::driver; use syntax::ast; use syntax::codemap::{CodeMap, dummy_spanned}; use syntax::diagnostic; @@ -42,7 +42,7 @@ pub fn run(input: &str, crate_name: Option) -> int { let input_path = Path::new(input); - let input = driver::FileInput(input_path.clone()); + let input = config::Input::File(input_path.clone()); let sessopts = config::Options { maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()), @@ -110,7 +110,7 @@ fn runtest(test: &str, cratename: &str, libs: Vec, externs: core::Externs, // the test harness wants its own `main` & top level functions, so // never wrap the test in `fn main() { ... }` let test = maketest(test, Some(cratename), true, as_test_harness); - let input = driver::StrInput(test.to_string()); + let input = config::Input::Str(test.to_string()); let sessopts = config::Options { maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()), diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 5f4e675aad5d5..2be11a236d3b7 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -45,15 +45,6 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt, [ast::TtToken(_, token::Ident(code, _))] => code, _ => unreachable!() }; - with_registered_diagnostics(|diagnostics| { - if !diagnostics.contains_key(&code.name) { - ecx.span_err(span, format!( - "unknown diagnostic code {}; add to librustc/diagnostics.rs", - token::get_ident(code).get() - ).as_slice()); - } - () - }); with_used_diagnostics(|diagnostics| { match diagnostics.insert(code.name, span) { Some(previous_span) => { @@ -106,25 +97,19 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, _ => unreachable!() }; - let (count, expr) = with_used_diagnostics(|diagnostics_in_use| { + let (count, expr) = with_registered_diagnostics(|diagnostics| { - let descriptions: Vec> = diagnostics - .iter().filter_map(|(code, description)| { - if !diagnostics_in_use.contains_key(code) { - ecx.span_warn(span, format!( - "diagnostic code {} never used", token::get_name(*code).get() - ).as_slice()); - } - description.map(|description| { - ecx.expr_tuple(span, vec![ - ecx.expr_str(span, token::get_name(*code)), - ecx.expr_str(span, token::get_name(description)) - ]) - }) - }).collect(); + let descriptions: Vec> = + diagnostics.iter().filter_map(|(code, description)| { + description.map(|description| { + ecx.expr_tuple(span, vec![ + ecx.expr_str(span, token::get_name(*code)), + ecx.expr_str(span, token::get_name(description))]) + }) + }).collect(); (descriptions.len(), ecx.expr_vec(span, descriptions)) - }) - }); + }); + MacItems::new(vec![quote_item!(ecx, pub static $name: [(&'static str, &'static str), ..$count] = $expr; ).unwrap()].into_iter()) diff --git a/src/test/compile-fail/rustc-diagnostics-1.rs b/src/test/compile-fail/rustc-diagnostics-1.rs deleted file mode 100644 index 55d836092fa71..0000000000000 --- a/src/test/compile-fail/rustc-diagnostics-1.rs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(rustc_diagnostic_macros)] - -__register_diagnostic!(E0001) -__register_diagnostic!(E0003) - -fn main() { - __diagnostic_used!(E0002); - //~^ ERROR unknown diagnostic code E0002 - - __diagnostic_used!(E0001); - //~^ NOTE previous invocation - - __diagnostic_used!(E0001); - //~^ WARNING diagnostic code E0001 already used -} - -__build_diagnostic_array!(DIAGNOSTICS) -//~^ WARN diagnostic code E0003 never used diff --git a/src/test/compile-fail/rustc-diagnostics-3.rs b/src/test/compile-fail/rustc-diagnostics-3.rs deleted file mode 100644 index d160664a48c78..0000000000000 --- a/src/test/compile-fail/rustc-diagnostics-3.rs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -__register_diagnostic!(E0001) -//~^ ERROR macro undefined: '__register_diagnostic!' - -fn main() { - __diagnostic_used!(E0001); - //~^ ERROR macro undefined: '__diagnostic_used!' -} - -__build_diagnostic_array!(DIAGNOSTICS) -//~^ ERROR macro undefined: '__build_diagnostic_array!' diff --git a/src/test/run-make/issue-19371/foo.rs b/src/test/run-make/issue-19371/foo.rs index 715fae314b673..8a0c14d2d7e36 100644 --- a/src/test/run-make/issue-19371/foo.rs +++ b/src/test/run-make/issue-19371/foo.rs @@ -9,12 +9,12 @@ // except according to those terms. extern crate rustc; -extern crate rustc_trans; +extern crate rustc_driver; extern crate syntax; use rustc::session::{build_session, Session}; -use rustc::session::config::{basic_options, build_configuration, OutputTypeExe}; -use rustc_trans::driver::driver::{Input, StrInput, compile_input}; +use rustc::session::config::{basic_options, build_configuration, Input, OutputTypeExe}; +use rustc_driver::driver::{compile_input}; use syntax::diagnostics::registry::Registry; fn main() { @@ -55,7 +55,7 @@ fn compile(code: String, output: Path, sysroot: Path) { compile_input(sess, cfg, - &StrInput(code), + &Input::Str(code), &None, &Some(output), None);