Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin splitting middle::ty #28274

Merged
merged 4 commits into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub mod front {
pub mod middle {
pub mod astconv_util;
pub mod astencode;
pub mod cast;
pub mod cfg;
pub mod check_const;
pub mod check_static_recursion;
Expand All @@ -124,15 +123,13 @@ pub mod middle {
pub mod effect;
pub mod entry;
pub mod expr_use_visitor;
pub mod fast_reject;
pub mod free_region;
pub mod intrinsicck;
pub mod infer;
pub mod implicator;
pub mod lang_items;
pub mod liveness;
pub mod mem_categorization;
pub mod outlives;
pub mod pat_util;
pub mod privacy;
pub mod reachable;
Expand All @@ -143,11 +140,6 @@ pub mod middle {
pub mod subst;
pub mod traits;
pub mod ty;
pub mod ty_fold;
pub mod ty_match;
pub mod ty_relate;
pub mod ty_walk;
pub mod wf;
pub mod weak_lang_items;
}

Expand Down
8 changes: 5 additions & 3 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ pub fn get_impl_polarity<'tcx>(tcx: &ty::ctxt<'tcx>,
decoder::get_impl_polarity(&*cdata, def.node)
}

pub fn get_custom_coerce_unsized_kind<'tcx>(tcx: &ty::ctxt<'tcx>,
def: DefId)
-> Option<ty::CustomCoerceUnsized> {
pub fn get_custom_coerce_unsized_kind<'tcx>(
tcx: &ty::ctxt<'tcx>,
def: DefId)
-> Option<ty::adjustment::CustomCoerceUnsized>
{
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_custom_coerce_unsized_kind(&*cdata, def.node)
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,11 @@ pub fn get_impl_polarity<'tcx>(cdata: Cmd,
}
}

pub fn get_custom_coerce_unsized_kind<'tcx>(cdata: Cmd,
id: ast::NodeId)
-> Option<ty::CustomCoerceUnsized> {
pub fn get_custom_coerce_unsized_kind<'tcx>(
cdata: Cmd,
id: ast::NodeId)
-> Option<ty::adjustment::CustomCoerceUnsized>
{
let item_doc = cdata.lookup_item(id);
reader::maybe_get_doc(item_doc, tag_impl_coerce_unsized_kind).map(|kind_doc| {
let mut decoder = reader::Decoder::new(kind_doc);
Expand Down
60 changes: 31 additions & 29 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId};
use metadata::tydecode::{RegionParameter, ClosureSource};
use metadata::tyencode;
use middle::cast;
use middle::ty::adjustment;
use middle::ty::cast;
use middle::check_const::ConstQualif;
use middle::def;
use middle::def_id::{DefId, LOCAL_CRATE};
Expand Down Expand Up @@ -646,11 +647,11 @@ trait rbml_writer_helpers<'tcx> {
fn emit_builtin_bounds(&mut self, ecx: &e::EncodeContext, bounds: &ty::BuiltinBounds);
fn emit_upvar_capture(&mut self, ecx: &e::EncodeContext, capture: &ty::UpvarCapture);
fn emit_auto_adjustment<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
adj: &ty::AutoAdjustment<'tcx>);
adj: &adjustment::AutoAdjustment<'tcx>);
fn emit_autoref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
autoref: &ty::AutoRef<'tcx>);
autoref: &adjustment::AutoRef<'tcx>);
fn emit_auto_deref_ref<'a>(&mut self, ecx: &e::EncodeContext<'a, 'tcx>,
auto_deref_ref: &ty::AutoDerefRef<'tcx>);
auto_deref_ref: &adjustment::AutoDerefRef<'tcx>);
}

impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
Expand Down Expand Up @@ -771,22 +772,22 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
}

fn emit_auto_adjustment<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
adj: &ty::AutoAdjustment<'tcx>) {
adj: &adjustment::AutoAdjustment<'tcx>) {
use serialize::Encoder;

self.emit_enum("AutoAdjustment", |this| {
match *adj {
ty::AdjustReifyFnPointer=> {
adjustment::AdjustReifyFnPointer=> {
this.emit_enum_variant("AdjustReifyFnPointer", 1, 0, |_| Ok(()))
}

ty::AdjustUnsafeFnPointer => {
adjustment::AdjustUnsafeFnPointer => {
this.emit_enum_variant("AdjustUnsafeFnPointer", 2, 0, |_| {
Ok(())
})
}

ty::AdjustDerefRef(ref auto_deref_ref) => {
adjustment::AdjustDerefRef(ref auto_deref_ref) => {
this.emit_enum_variant("AdjustDerefRef", 3, 2, |this| {
this.emit_enum_variant_arg(0,
|this| Ok(this.emit_auto_deref_ref(ecx, auto_deref_ref)))
Expand All @@ -797,19 +798,19 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
}

fn emit_autoref<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
autoref: &ty::AutoRef<'tcx>) {
autoref: &adjustment::AutoRef<'tcx>) {
use serialize::Encoder;

self.emit_enum("AutoRef", |this| {
match autoref {
&ty::AutoPtr(r, m) => {
&adjustment::AutoPtr(r, m) => {
this.emit_enum_variant("AutoPtr", 0, 2, |this| {
this.emit_enum_variant_arg(0,
|this| Ok(this.emit_region(ecx, *r)));
this.emit_enum_variant_arg(1, |this| m.encode(this))
})
}
&ty::AutoUnsafe(m) => {
&adjustment::AutoUnsafe(m) => {
this.emit_enum_variant("AutoUnsafe", 1, 1, |this| {
this.emit_enum_variant_arg(0, |this| m.encode(this))
})
Expand All @@ -819,7 +820,7 @@ impl<'a, 'tcx> rbml_writer_helpers<'tcx> for Encoder<'a> {
}

fn emit_auto_deref_ref<'b>(&mut self, ecx: &e::EncodeContext<'b, 'tcx>,
auto_deref_ref: &ty::AutoDerefRef<'tcx>) {
auto_deref_ref: &adjustment::AutoDerefRef<'tcx>) {
use serialize::Encoder;

self.emit_struct("AutoDerefRef", 2, |this| {
Expand Down Expand Up @@ -974,7 +975,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,

if let Some(adjustment) = tcx.tables.borrow().adjustments.get(&id) {
match *adjustment {
ty::AdjustDerefRef(ref adj) => {
adjustment::AdjustDerefRef(ref adj) => {
for autoderef in 0..adj.autoderefs {
let method_call = ty::MethodCall::autoderef(id, autoderef as u32);
if let Some(method) = tcx.tables.borrow().method_map.get(&method_call) {
Expand Down Expand Up @@ -1063,17 +1064,17 @@ trait rbml_decoder_decoder_helpers<'tcx> {
fn read_upvar_capture(&mut self, dcx: &DecodeContext)
-> ty::UpvarCapture;
fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
-> ty::AutoAdjustment<'tcx>;
-> adjustment::AutoAdjustment<'tcx>;
fn read_cast_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
-> cast::CastKind;
fn read_closure_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
-> ty::ClosureKind;
fn read_closure_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
-> ty::ClosureTy<'tcx>;
fn read_auto_deref_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
-> ty::AutoDerefRef<'tcx>;
-> adjustment::AutoDerefRef<'tcx>;
fn read_autoref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
-> ty::AutoRef<'tcx>;
-> adjustment::AutoRef<'tcx>;
fn convert_def_id(&mut self,
dcx: &DecodeContext,
source: DefIdSource,
Expand Down Expand Up @@ -1246,30 +1247,30 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
}).unwrap()
}
fn read_auto_adjustment<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::AutoAdjustment<'tcx> {
-> adjustment::AutoAdjustment<'tcx> {
self.read_enum("AutoAdjustment", |this| {
let variants = ["AdjustReifyFnPointer", "AdjustUnsafeFnPointer", "AdjustDerefRef"];
this.read_enum_variant(&variants, |this, i| {
Ok(match i {
1 => ty::AdjustReifyFnPointer,
2 => ty::AdjustUnsafeFnPointer,
1 => adjustment::AdjustReifyFnPointer,
2 => adjustment::AdjustUnsafeFnPointer,
3 => {
let auto_deref_ref: ty::AutoDerefRef =
let auto_deref_ref: adjustment::AutoDerefRef =
this.read_enum_variant_arg(0,
|this| Ok(this.read_auto_deref_ref(dcx))).unwrap();

ty::AdjustDerefRef(auto_deref_ref)
adjustment::AdjustDerefRef(auto_deref_ref)
}
_ => panic!("bad enum variant for ty::AutoAdjustment")
_ => panic!("bad enum variant for adjustment::AutoAdjustment")
})
})
}).unwrap()
}

fn read_auto_deref_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::AutoDerefRef<'tcx> {
-> adjustment::AutoDerefRef<'tcx> {
self.read_struct("AutoDerefRef", 2, |this| {
Ok(ty::AutoDerefRef {
Ok(adjustment::AutoDerefRef {
autoderefs: this.read_struct_field("autoderefs", 0, |this| {
Decodable::decode(this)
}).unwrap(),
Expand All @@ -1296,7 +1297,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
}

fn read_autoref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::AutoRef<'tcx> {
-> adjustment::AutoRef<'tcx> {
self.read_enum("AutoRef", |this| {
let variants = ["AutoPtr", "AutoUnsafe"];
this.read_enum_variant(&variants, |this, i| {
Expand All @@ -1311,15 +1312,15 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
Decodable::decode(this)
}).unwrap();

ty::AutoPtr(dcx.tcx.mk_region(r), m)
adjustment::AutoPtr(dcx.tcx.mk_region(r), m)
}
1 => {
let m: hir::Mutability =
this.read_enum_variant_arg(0, |this| Decodable::decode(this)).unwrap();

ty::AutoUnsafe(m)
adjustment::AutoUnsafe(m)
}
_ => panic!("bad enum variant for ty::AutoRef")
_ => panic!("bad enum variant for adjustment::AutoRef")
})
})
}).unwrap()
Expand Down Expand Up @@ -1467,7 +1468,8 @@ fn decode_side_tables(dcx: &DecodeContext,
dcx.tcx.tables.borrow_mut().method_map.insert(method_call, method);
}
c::tag_table_adjustments => {
let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(dcx);
let adj =
val_dsr.read_auto_adjustment(dcx);
dcx.tcx.tables.borrow_mut().adjustments.insert(id, adj);
}
c::tag_table_closure_tys => {
Expand Down
11 changes: 8 additions & 3 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// - It's not possible to take the address of a static item with unsafe interior. This is enforced
// by borrowck::gather_loans

use middle::cast::{CastKind};
use middle::ty::cast::{CastKind};
use middle::const_eval;
use middle::const_eval::EvalHint::ExprTypeChecked;
use middle::def;
Expand Down Expand Up @@ -798,8 +798,13 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
/// Check the adjustments of an expression
fn check_adjustments<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr) {
match v.tcx.tables.borrow().adjustments.get(&e.id) {
None | Some(&ty::AdjustReifyFnPointer) | Some(&ty::AdjustUnsafeFnPointer) => {}
Some(&ty::AdjustDerefRef(ty::AutoDerefRef { autoderefs, .. })) => {
None |
Some(&ty::adjustment::AdjustReifyFnPointer) |
Some(&ty::adjustment::AdjustUnsafeFnPointer) => {}

Some(&ty::adjustment::AdjustDerefRef(
ty::adjustment::AutoDerefRef { autoderefs, .. }
)) => {
if (0..autoderefs as u32).any(|autoderef| {
v.tcx.is_overloaded_autoderef(e.id, autoderef)
}) {
Expand Down
15 changes: 8 additions & 7 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use middle::def_id::{DefId};
use middle::infer;
use middle::mem_categorization as mc;
use middle::ty;
use middle::ty::adjustment;

use rustc_front::hir;

Expand Down Expand Up @@ -726,16 +727,16 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
let adj = typer.adjustments().get(&expr.id).map(|x| x.clone());
if let Some(adjustment) = adj {
match adjustment {
ty::AdjustReifyFnPointer |
ty::AdjustUnsafeFnPointer => {
adjustment::AdjustReifyFnPointer |
adjustment::AdjustUnsafeFnPointer => {
// Creating a closure/fn-pointer or unsizing consumes
// the input and stores it into the resulting rvalue.
debug!("walk_adjustment(AdjustReifyFnPointer|AdjustUnsafeFnPointer)");
let cmt_unadjusted =
return_if_err!(self.mc.cat_expr_unadjusted(expr));
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
}
ty::AdjustDerefRef(ref adj) => {
adjustment::AdjustDerefRef(ref adj) => {
self.walk_autoderefref(expr, adj);
}
}
Expand Down Expand Up @@ -778,7 +779,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {

fn walk_autoderefref(&mut self,
expr: &hir::Expr,
adj: &ty::AutoDerefRef<'tcx>) {
adj: &adjustment::AutoDerefRef<'tcx>) {
debug!("walk_autoderefref expr={:?} adj={:?}",
expr,
adj);
Expand Down Expand Up @@ -809,7 +810,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
fn walk_autoref(&mut self,
expr: &hir::Expr,
cmt_base: mc::cmt<'tcx>,
opt_autoref: Option<ty::AutoRef<'tcx>>)
opt_autoref: Option<adjustment::AutoRef<'tcx>>)
-> mc::cmt<'tcx>
{
debug!("walk_autoref(expr.id={} cmt_derefd={:?} opt_autoref={:?})",
Expand All @@ -828,7 +829,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
};

match *autoref {
ty::AutoPtr(r, m) => {
adjustment::AutoPtr(r, m) => {
self.delegate.borrow(expr.id,
expr.span,
cmt_base,
Expand All @@ -837,7 +838,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
AutoRef);
}

ty::AutoUnsafe(m) => {
adjustment::AutoUnsafe(m) => {
debug!("walk_autoref: expr.id={} cmt_base={:?}",
expr.id,
cmt_base);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/free_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! region outlives another and so forth.

use middle::ty::{self, FreeRegion, Region};
use middle::wf::ImpliedBound;
use middle::ty::wf::ImpliedBound;
use rustc_data_structures::transitive_relation::TransitiveRelation;

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/implicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use middle::infer::{InferCtxt, GenericKind};
use middle::subst::Substs;
use middle::traits;
use middle::ty::{self, RegionEscape, ToPredicate, Ty};
use middle::ty_fold::{TypeFoldable, TypeFolder};
use middle::ty::fold::{TypeFoldable, TypeFolder};

use syntax::ast;
use syntax::codemap::Span;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/bivariate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use super::type_variable::{BiTo};

use middle::ty::{self, Ty};
use middle::ty::TyVar;
use middle::ty_relate::{Relate, RelateResult, TypeRelation};
use middle::ty::relate::{Relate, RelateResult, TypeRelation};

pub struct Bivariate<'a, 'tcx: 'a> {
fields: CombineFields<'a, 'tcx>
Expand Down
Loading