Skip to content

Commit

Permalink
auto merge of #14702 : nikomatsakis/rust/issue-5527-namespace-substs-…
Browse files Browse the repository at this point in the history
…b, r=pnkfelix

Separate out initial refactorings for PR #14604
  • Loading branch information
bors committed Jun 7, 2014
2 parents 8a41485 + 4a51e9c commit bd6683c
Show file tree
Hide file tree
Showing 71 changed files with 1,019 additions and 934 deletions.
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern crate time;
extern crate log;

pub mod middle {
pub mod def;
pub mod trans;
pub mod ty;
pub mod ty_fold;
Expand Down
33 changes: 17 additions & 16 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use metadata::tydecode::{parse_ty_data, parse_def_id,
parse_type_param_def_data,
parse_bare_fn_ty_data, parse_trait_ref_data};
use middle::lang_items;
use middle::def;
use middle::ty::{ImplContainer, TraitContainer};
use middle::ty;
use middle::typeck;
Expand Down Expand Up @@ -333,11 +334,11 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
-> DefLike {
let fam = item_family(item);
match fam {
ImmStatic => DlDef(ast::DefStatic(did, false)),
MutStatic => DlDef(ast::DefStatic(did, true)),
Struct => DlDef(ast::DefStruct(did)),
UnsafeFn => DlDef(ast::DefFn(did, ast::UnsafeFn)),
Fn => DlDef(ast::DefFn(did, ast::NormalFn)),
ImmStatic => DlDef(def::DefStatic(did, false)),
MutStatic => DlDef(def::DefStatic(did, true)),
Struct => DlDef(def::DefStruct(did)),
UnsafeFn => DlDef(def::DefFn(did, ast::UnsafeFn)),
Fn => DlDef(def::DefFn(did, ast::NormalFn)),
StaticMethod | UnsafeStaticMethod => {
let fn_style = if fam == UnsafeStaticMethod { ast::UnsafeFn } else
{ ast::NormalFn };
Expand All @@ -348,27 +349,27 @@ fn item_to_def_like(item: ebml::Doc, did: ast::DefId, cnum: ast::CrateNum)
// a trait_method_sort.
let provenance = if reader::maybe_get_doc(
item, tag_item_trait_method_sort).is_some() {
ast::FromTrait(item_reqd_and_translated_parent_item(cnum,
def::FromTrait(item_reqd_and_translated_parent_item(cnum,
item))
} else {
ast::FromImpl(item_reqd_and_translated_parent_item(cnum,
def::FromImpl(item_reqd_and_translated_parent_item(cnum,
item))
};
DlDef(ast::DefStaticMethod(did, provenance, fn_style))
DlDef(def::DefStaticMethod(did, provenance, fn_style))
}
Type | ForeignType => DlDef(ast::DefTy(did)),
Mod => DlDef(ast::DefMod(did)),
ForeignMod => DlDef(ast::DefForeignMod(did)),
Type | ForeignType => DlDef(def::DefTy(did)),
Mod => DlDef(def::DefMod(did)),
ForeignMod => DlDef(def::DefForeignMod(did)),
StructVariant => {
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
DlDef(ast::DefVariant(enum_did, did, true))
DlDef(def::DefVariant(enum_did, did, true))
}
TupleVariant => {
let enum_did = item_reqd_and_translated_parent_item(cnum, item);
DlDef(ast::DefVariant(enum_did, did, false))
DlDef(def::DefVariant(enum_did, did, false))
}
Trait => DlDef(ast::DefTrait(did)),
Enum => DlDef(ast::DefTy(did)),
Trait => DlDef(def::DefTrait(did)),
Enum => DlDef(def::DefTy(did)),
Impl => DlImpl(did),
PublicField | InheritedField => DlField,
}
Expand Down Expand Up @@ -459,7 +460,7 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
// Something that a name can resolve to.
#[deriving(Clone)]
pub enum DefLike {
DlDef(ast::Def),
DlDef(def::Def),
DlImpl(ast::DefId),
DlField
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> {
ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = &self.ecx.tcx.def_map;
let trait_def = def_map.borrow().get_copy(&trait_ref.ref_id);
let def_id = ast_util::def_id_of_def(trait_def);
let def_id = trait_def.def_id();

// Load eagerly if this is an implementation of the Drop trait
// or if the trait is not defined in this crate.
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#![allow(non_camel_case_types)]

use middle::subst;
use middle::ty;

use std::rc::Rc;
Expand All @@ -25,7 +26,6 @@ use std::uint;
use syntax::abi;
use syntax::ast;
use syntax::ast::*;
use syntax::owned_slice::OwnedSlice;
use syntax::parse::token;

// Compact string representation for ty::t values. API ty_str &
Expand Down Expand Up @@ -133,7 +133,7 @@ pub fn parse_trait_ref_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tc
}

pub fn parse_substs_data(data: &[u8], crate_num: ast::CrateNum, pos: uint, tcx: &ty::ctxt,
conv: conv_did) -> ty::substs {
conv: conv_did) -> subst::Substs {
let mut st = parse_state_from_data(data, crate_num, pos, tcx);
parse_substs(&mut st, conv)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ fn parse_trait_store(st: &mut PState, conv: conv_did) -> ty::TraitStore {
}
}

fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs {
fn parse_substs(st: &mut PState, conv: conv_did) -> subst::Substs {
let regions = parse_region_substs(st, |x,y| conv(x,y));

let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) );
Expand All @@ -172,24 +172,24 @@ fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs {
while peek(st) != ']' { params.push(parse_ty(st, |x,y| conv(x,y))); }
st.pos = st.pos + 1u;

return ty::substs {
return subst::Substs {
regions: regions,
self_ty: self_ty,
tps: params
};
}

fn parse_region_substs(st: &mut PState, conv: conv_did) -> ty::RegionSubsts {
fn parse_region_substs(st: &mut PState, conv: conv_did) -> subst::RegionSubsts {
match next(st) {
'e' => ty::ErasedRegions,
'e' => subst::ErasedRegions,
'n' => {
let mut regions = vec!();
while peek(st) != '.' {
let r = parse_region(st, |x,y| conv(x,y));
regions.push(r);
}
assert_eq!(next(st), '.');
ty::NonerasedRegions(OwnedSlice::from_vec(regions))
subst::NonerasedRegions(regions)
}
_ => fail!("parse_bound_region: bad input")
}
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::io::MemWriter;

use middle::subst;
use middle::ty::param_ty;
use middle::ty;

Expand Down Expand Up @@ -96,20 +97,20 @@ fn enc_opt<T>(w: &mut MemWriter, t: Option<T>, enc_f: |&mut MemWriter, T|) {
}
}

pub fn enc_substs(w: &mut MemWriter, cx: &ctxt, substs: &ty::substs) {
pub fn enc_substs(w: &mut MemWriter, cx: &ctxt, substs: &subst::Substs) {
enc_region_substs(w, cx, &substs.regions);
enc_opt(w, substs.self_ty, |w, t| enc_ty(w, cx, t));
mywrite!(w, "[");
for t in substs.tps.iter() { enc_ty(w, cx, *t); }
mywrite!(w, "]");
}

fn enc_region_substs(w: &mut MemWriter, cx: &ctxt, substs: &ty::RegionSubsts) {
fn enc_region_substs(w: &mut MemWriter, cx: &ctxt, substs: &subst::RegionSubsts) {
match *substs {
ty::ErasedRegions => {
subst::ErasedRegions => {
mywrite!(w, "e");
}
ty::NonerasedRegions(ref regions) => {
subst::NonerasedRegions(ref regions) => {
mywrite!(w, "n");
for &r in regions.iter() {
enc_region(w, cx, r);
Expand Down
82 changes: 42 additions & 40 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ use c = metadata::common;
use cstore = metadata::cstore;
use driver::session::Session;
use metadata::decoder;
use middle::def;
use e = metadata::encoder;
use middle::freevars::freevar_entry;
use middle::region;
use metadata::tydecode;
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter,
RegionParameter};
use metadata::tyencode;
use middle::subst;
use middle::typeck::{MethodCall, MethodCallee, MethodOrigin};
use middle::{ty, typeck};
use util::ppaux::ty_to_str;
Expand Down Expand Up @@ -394,58 +396,58 @@ fn renumber_and_map_ast(xcx: &ExtendedDecodeContext,
// ______________________________________________________________________
// Encoding and decoding of ast::def

fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> ast::Def {
fn decode_def(xcx: &ExtendedDecodeContext, doc: ebml::Doc) -> def::Def {
let mut dsr = reader::Decoder::new(doc);
let def: ast::Def = Decodable::decode(&mut dsr).unwrap();
let def: def::Def = Decodable::decode(&mut dsr).unwrap();
def.tr(xcx)
}

impl tr for ast::Def {
fn tr(&self, xcx: &ExtendedDecodeContext) -> ast::Def {
impl tr for def::Def {
fn tr(&self, xcx: &ExtendedDecodeContext) -> def::Def {
match *self {
ast::DefFn(did, p) => ast::DefFn(did.tr(xcx), p),
ast::DefStaticMethod(did, wrapped_did2, p) => {
ast::DefStaticMethod(did.tr(xcx),
def::DefFn(did, p) => def::DefFn(did.tr(xcx), p),
def::DefStaticMethod(did, wrapped_did2, p) => {
def::DefStaticMethod(did.tr(xcx),
match wrapped_did2 {
ast::FromTrait(did2) => {
ast::FromTrait(did2.tr(xcx))
def::FromTrait(did2) => {
def::FromTrait(did2.tr(xcx))
}
ast::FromImpl(did2) => {
ast::FromImpl(did2.tr(xcx))
def::FromImpl(did2) => {
def::FromImpl(did2.tr(xcx))
}
},
p)
}
ast::DefMethod(did0, did1) => {
ast::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
def::DefMethod(did0, did1) => {
def::DefMethod(did0.tr(xcx), did1.map(|did1| did1.tr(xcx)))
}
ast::DefSelfTy(nid) => { ast::DefSelfTy(xcx.tr_id(nid)) }
ast::DefMod(did) => { ast::DefMod(did.tr(xcx)) }
ast::DefForeignMod(did) => { ast::DefForeignMod(did.tr(xcx)) }
ast::DefStatic(did, m) => { ast::DefStatic(did.tr(xcx), m) }
ast::DefArg(nid, b) => { ast::DefArg(xcx.tr_id(nid), b) }
ast::DefLocal(nid, b) => { ast::DefLocal(xcx.tr_id(nid), b) }
ast::DefVariant(e_did, v_did, is_s) => {
ast::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
def::DefSelfTy(nid) => { def::DefSelfTy(xcx.tr_id(nid)) }
def::DefMod(did) => { def::DefMod(did.tr(xcx)) }
def::DefForeignMod(did) => { def::DefForeignMod(did.tr(xcx)) }
def::DefStatic(did, m) => { def::DefStatic(did.tr(xcx), m) }
def::DefArg(nid, b) => { def::DefArg(xcx.tr_id(nid), b) }
def::DefLocal(nid, b) => { def::DefLocal(xcx.tr_id(nid), b) }
def::DefVariant(e_did, v_did, is_s) => {
def::DefVariant(e_did.tr(xcx), v_did.tr(xcx), is_s)
},
ast::DefTrait(did) => ast::DefTrait(did.tr(xcx)),
ast::DefTy(did) => ast::DefTy(did.tr(xcx)),
ast::DefPrimTy(p) => ast::DefPrimTy(p),
ast::DefTyParam(did, v) => ast::DefTyParam(did.tr(xcx), v),
ast::DefBinding(nid, bm) => ast::DefBinding(xcx.tr_id(nid), bm),
ast::DefUse(did) => ast::DefUse(did.tr(xcx)),
ast::DefUpvar(nid1, def, nid2, nid3) => {
ast::DefUpvar(xcx.tr_id(nid1),
def::DefTrait(did) => def::DefTrait(did.tr(xcx)),
def::DefTy(did) => def::DefTy(did.tr(xcx)),
def::DefPrimTy(p) => def::DefPrimTy(p),
def::DefTyParam(did, v) => def::DefTyParam(did.tr(xcx), v),
def::DefBinding(nid, bm) => def::DefBinding(xcx.tr_id(nid), bm),
def::DefUse(did) => def::DefUse(did.tr(xcx)),
def::DefUpvar(nid1, def, nid2, nid3) => {
def::DefUpvar(xcx.tr_id(nid1),
@(*def).tr(xcx),
xcx.tr_id(nid2),
xcx.tr_id(nid3))
}
ast::DefStruct(did) => ast::DefStruct(did.tr(xcx)),
ast::DefRegion(nid) => ast::DefRegion(xcx.tr_id(nid)),
ast::DefTyParamBinder(nid) => {
ast::DefTyParamBinder(xcx.tr_id(nid))
def::DefStruct(did) => def::DefStruct(did.tr(xcx)),
def::DefRegion(nid) => def::DefRegion(xcx.tr_id(nid)),
def::DefTyParamBinder(nid) => {
def::DefTyParamBinder(xcx.tr_id(nid))
}
ast::DefLabel(nid) => ast::DefLabel(xcx.tr_id(nid))
def::DefLabel(nid) => def::DefLabel(xcx.tr_id(nid))
}
}
}
Expand Down Expand Up @@ -796,7 +798,7 @@ trait ebml_writer_helpers {
fn emit_tpbt(&mut self,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty);
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &ty::substs);
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs);
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment);
}

Expand Down Expand Up @@ -842,7 +844,7 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
});
}

fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &ty::substs) {
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs) {
self.emit_opaque(|this| Ok(tyencode::enc_substs(this.writer,
&ecx.ty_str_ctxt(),
substs)));
Expand Down Expand Up @@ -1076,7 +1078,7 @@ trait ebml_decoder_decoder_helpers {
-> ty::TypeParameterDef;
fn read_ty_param_bounds_and_ty(&mut self, xcx: &ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty;
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> ty::substs;
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> subst::Substs;
fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjustment;
fn convert_def_id(&mut self,
xcx: &ExtendedDecodeContext,
Expand All @@ -1093,7 +1095,7 @@ trait ebml_decoder_decoder_helpers {
cdata: &cstore::crate_metadata) -> Vec<ty::t>;
fn read_substs_noxcx(&mut self, tcx: &ty::ctxt,
cdata: &cstore::crate_metadata)
-> ty::substs;
-> subst::Substs;
}

impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
Expand Down Expand Up @@ -1121,7 +1123,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
fn read_substs_noxcx(&mut self,
tcx: &ty::ctxt,
cdata: &cstore::crate_metadata)
-> ty::substs
-> subst::Substs
{
self.read_opaque(|_, doc| {
Ok(tydecode::parse_substs_data(
Expand Down Expand Up @@ -1210,7 +1212,7 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
}).unwrap()
}

fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> ty::substs {
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> subst::Substs {
self.read_opaque(|this, doc| {
Ok(tydecode::parse_substs_data(doc.data,
xcx.dcx.cdata.cnum,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use middle::dataflow::DataFlowContext;
use middle::dataflow::DataFlowOperator;
use middle::def;
use euv = middle::expr_use_visitor;
use mc = middle::mem_categorization;
use middle::ty;
Expand Down Expand Up @@ -399,7 +400,7 @@ impl<'a> BorrowckCtxt<'a> {
id: ast::NodeId,
span: Span,
ty: ty::t,
def: ast::Def)
def: def::Def)
-> mc::cmt {
match self.mc().cat_def(id, span, ty, def) {
Ok(c) => c,
Expand All @@ -412,11 +413,11 @@ impl<'a> BorrowckCtxt<'a> {
pub fn cat_captured_var(&self,
closure_id: ast::NodeId,
closure_span: Span,
upvar_def: ast::Def)
upvar_def: def::Def)
-> mc::cmt {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
let var_id = ast_util::def_id_of_def(upvar_def).node;
let var_id = upvar_def.def_id().node;
let var_ty = ty::node_id_to_type(self.tcx, var_id);
self.cat_def(closure_id, closure_span, var_ty, upvar_def)
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

use middle::cfg::*;
use middle::def;
use middle::graph;
use middle::typeck;
use middle::ty;
Expand Down Expand Up @@ -531,7 +532,7 @@ impl<'a> CFGBuilder<'a> {

Some(_) => {
match self.tcx.def_map.borrow().find(&expr.id) {
Some(&ast::DefLabel(loop_id)) => {
Some(&def::DefLabel(loop_id)) => {
for l in self.loop_scopes.iter() {
if l.loop_id == loop_id {
return *l;
Expand Down
Loading

0 comments on commit bd6683c

Please sign in to comment.