Skip to content

Commit

Permalink
auto merge of #10153 : nikomatsakis/rust/issue-4846-multiple-lifetime…
Browse files Browse the repository at this point in the history
…-parameters-7, r=pnkfelix

Fully support multiple lifetime parameters on types and elsewhere, removing special treatment for `'self`. I am submitting this a touch early in that I plan to push a new commit with more tests specifically targeting types with multiple lifetime parameters -- but the current code bootstraps and passes `make check`.

Fixes #4846
  • Loading branch information
bors committed Nov 9, 2013
2 parents dc5d9b9 + f6e8d49 commit 8379890
Show file tree
Hide file tree
Showing 117 changed files with 5,025 additions and 3,605 deletions.
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ ifdef TRACE
CFG_RUSTC_FLAGS += -Z trace
endif
ifndef DEBUG_BORROWS
RUSTFLAGS_STAGE0 += -Z no-debug-borrows
RUSTFLAGS_STAGE1 += -Z no-debug-borrows
RUSTFLAGS_STAGE2 += -Z no-debug-borrows
endif
Expand Down
28 changes: 14 additions & 14 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ impl<T:Send> MutexArc<T> {

/// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond().
#[inline]
pub unsafe fn unsafe_access_cond<'x, 'c, U>(&self,
blk: &fn(x: &'x mut T,
c: &'c Condvar) -> U)
-> U {
pub unsafe fn unsafe_access_cond<U>(&self,
blk: &fn(x: &mut T,
c: &Condvar) -> U)
-> U {
let state = self.x.get();
do (&(*state).lock).lock_cond |cond| {
check_poison(true, (*state).failed);
Expand Down Expand Up @@ -290,10 +290,10 @@ impl<T:Freeze + Send> MutexArc<T> {

/// As unsafe_access_cond but safe and Freeze.
#[inline]
pub fn access_cond<'x, 'c, U>(&self,
blk: &fn(x: &'x mut T,
c: &'c Condvar) -> U)
-> U {
pub fn access_cond<U>(&self,
blk: &fn(x: &mut T,
c: &Condvar) -> U)
-> U {
unsafe { self.unsafe_access_cond(blk) }
}
}
Expand Down Expand Up @@ -402,9 +402,9 @@ impl<T:Freeze + Send> RWArc<T> {

/// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline]
pub fn write_cond<'x, 'c, U>(&self,
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
-> U {
pub fn write_cond<U>(&self,
blk: &fn(x: &mut T, c: &Condvar) -> U)
-> U {
unsafe {
let state = self.x.get();
do (*borrow_rwlock(state)).write_cond |cond| {
Expand Down Expand Up @@ -554,9 +554,9 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
}

/// Access the pre-downgrade RWArc in write mode with a condvar.
pub fn write_cond<'x, 'c, U>(&mut self,
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
-> U {
pub fn write_cond<U>(&mut self,
blk: &fn(x: &mut T, c: &Condvar) -> U)
-> U {
match *self {
RWWriteMode {
data: &ref mut data,
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,20 @@ pub fn phase_3_run_analysis_passes(sess: Session,
time(time_passes, "resolution", (), |_|
middle::resolve::resolve_crate(sess, lang_items, crate));

let named_region_map = time(time_passes, "lifetime resolution", (),
|_| middle::resolve_lifetime::crate(sess, crate));

time(time_passes, "looking for entry point", (),
|_| middle::entry::find_entry_point(sess, crate, ast_map));

let freevars = time(time_passes, "freevar finding", (), |_|
freevars::annotate_freevars(def_map, crate));

let region_map = time(time_passes, "region resolution", (), |_|
middle::region::resolve_crate(sess, def_map, crate));

let rp_set = time(time_passes, "region parameterization inference", (), |_|
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
middle::region::resolve_crate(sess, crate));

let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
region_map, rp_set, lang_items);
let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars,
region_map, lang_items);

// passes are timed inside typeck
let (method_map, vtable_map) = typeck::check_crate(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/front/std_inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ impl fold::ast_fold for StandardLibraryInjector {
segments: ~[
ast::PathSegment {
identifier: self.sess.ident_of("std"),
lifetime: None,
lifetimes: opt_vec::Empty,
types: opt_vec::Empty,
},
ast::PathSegment {
identifier: self.sess.ident_of("prelude"),
lifetime: None,
lifetimes: opt_vec::Empty,
types: opt_vec::Empty,
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn path_node(ids: ~[ast::Ident]) -> ast::Path {
global: false,
segments: ids.move_iter().map(|identifier| ast::PathSegment {
identifier: identifier,
lifetime: None,
lifetimes: opt_vec::Empty,
types: opt_vec::Empty,
}).collect()
}
Expand All @@ -355,7 +355,7 @@ fn path_node_global(ids: ~[ast::Ident]) -> ast::Path {
global: true,
segments: ids.move_iter().map(|identifier| ast::PathSegment {
identifier: identifier,
lifetime: None,
lifetimes: opt_vec::Empty,
types: opt_vec::Empty,
}).collect()
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ use syntax::diagnostic;
pub mod middle {
pub mod trans;
pub mod ty;
pub mod ty_fold;
pub mod subst;
pub mod resolve;
pub mod resolve_lifetime;
pub mod typeck;
pub mod check_loop;
pub mod check_match;
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub static tag_path_elt_name: uint = 0x43u;
pub static tag_item_field: uint = 0x44u;
pub static tag_struct_mut: uint = 0x45u;

pub static tag_region_param: uint = 0x46u;
pub static tag_item_variances: uint = 0x46;
pub static tag_mod_impl_trait: uint = 0x47u;
/*
trait items contain tag_item_trait_method elements,
Expand Down Expand Up @@ -193,6 +193,11 @@ pub static tag_path_elt_pretty_name: uint = 0x87;
pub static tag_path_elt_pretty_name_ident: uint = 0x88;
pub static tag_path_elt_pretty_name_extra: uint = 0x89;

pub static tag_region_param_def: uint = 0x100;
pub static tag_region_param_def_ident: uint = 0x101;
pub static tag_region_param_def_def_id: uint = 0x102;


pub struct LinkMeta {
name: @str,
vers: @str,
Expand Down
15 changes: 7 additions & 8 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use metadata::common::*;
use metadata::cstore;
use metadata::decoder;
use metadata;
use middle::ty;
use middle::typeck;

Expand Down Expand Up @@ -144,6 +143,12 @@ pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,
decoder::get_trait_method_def_ids(cdata, def.node)
}

pub fn get_item_variances(cstore: @mut cstore::CStore,
def: ast::DefId) -> ty::ItemVariances {
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_item_variances(cdata, def.node)
}

pub fn get_provided_trait_methods(tcx: ty::ctxt,
def: ast::DefId)
-> ~[@ty::Method] {
Expand Down Expand Up @@ -199,12 +204,6 @@ pub fn get_trait_def(tcx: ty::ctxt, def: ast::DefId) -> ty::TraitDef {
decoder::get_trait_def(cdata, def.node, tcx)
}

pub fn get_region_param(cstore: @mut metadata::cstore::CStore,
def: ast::DefId) -> Option<ty::region_variance> {
let cdata = cstore::get_crate_data(cstore, def.crate);
return decoder::get_region_param(cdata, def.node);
}

pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
def: ast::DefId) -> ty::ty_param_bounds_and_ty {
let cstore = tcx.cstore;
Expand All @@ -224,7 +223,7 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
let ty = decoder::item_type(def, the_field, tcx, cdata);
ty::ty_param_bounds_and_ty {
generics: ty::Generics {type_param_defs: @~[],
region_param: None},
region_param_defs: @[]},
ty: ty
}
}
Expand Down
66 changes: 42 additions & 24 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use middle::ty;
use middle::typeck;
use middle::astencode::vtable_decoder_helpers;


use std::at_vec;
use std::u64;
use std::rt::io;
use std::rt::io::extensions::u64_from_be_bytes;
Expand Down Expand Up @@ -252,9 +252,11 @@ fn item_trait_ref(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> ty::TraitRef {
doc_trait_ref(tp, tcx, cdata)
}

fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: Cmd,
fn item_ty_param_defs(item: ebml::Doc,
tcx: ty::ctxt,
cdata: Cmd,
tag: uint)
-> @~[ty::TypeParameterDef] {
-> @~[ty::TypeParameterDef] {
let mut bounds = ~[];
do reader::tagged_docs(item, tag) |p| {
let bd = parse_type_param_def_data(
Expand All @@ -266,10 +268,23 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: Cmd,
@bounds
}

fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
do reader::maybe_get_doc(item, tag_region_param).map |doc| {
let mut decoder = reader::Decoder(doc);
Decodable::decode(&mut decoder)
fn item_region_param_defs(item_doc: ebml::Doc,
tcx: ty::ctxt,
cdata: Cmd)
-> @[ty::RegionParameterDef] {
do at_vec::build(None) |push| {
do reader::tagged_docs(item_doc, tag_region_param_def) |rp_doc| {
let ident_str_doc = reader::get_doc(rp_doc,
tag_region_param_def_ident);
let ident = item_name(tcx.sess.intr(), ident_str_doc);
let def_id_doc = reader::get_doc(rp_doc,
tag_region_param_def_def_id);
let def_id = reader::with_doc_data(def_id_doc, parse_def_id);
let def_id = translate_def_id(cdata, def_id);
push(ty::RegionParameterDef { ident: ident,
def_id: def_id });
true
};
}
}

Expand Down Expand Up @@ -393,7 +408,7 @@ pub fn get_trait_def(cdata: Cmd,
let item_doc = lookup_item(item_id, cdata.data);
let tp_defs = item_ty_param_defs(item_doc, tcx, cdata,
tag_items_data_item_ty_param_bounds);
let rp = item_ty_region_param(item_doc);
let rp_defs = item_region_param_defs(item_doc, tcx, cdata);
let mut bounds = ty::EmptyBuiltinBounds();
// Collect the builtin bounds from the encoded supertraits.
// FIXME(#8559): They should be encoded directly.
Expand All @@ -407,7 +422,7 @@ pub fn get_trait_def(cdata: Cmd,
};
ty::TraitDef {
generics: ty::Generics {type_param_defs: tp_defs,
region_param: rp},
region_param_defs: rp_defs},
bounds: bounds,
trait_ref: @item_trait_ref(item_doc, tcx, cdata)
}
Expand All @@ -417,33 +432,27 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
-> ty::ty_param_bounds_and_ty {

let item = lookup_item(id, cdata.data);

let t = item_type(ast::DefId { crate: cdata.cnum, node: id }, item, tcx,
cdata);
let tp_defs = if family_has_type_params(item_family(item)) {
item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds)
} else { @~[] };
let rp = item_ty_region_param(item);

let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
let rp_defs = item_region_param_defs(item, tcx, cdata);

ty::ty_param_bounds_and_ty {
generics: ty::Generics {type_param_defs: tp_defs,
region_param: rp},
region_param_defs: rp_defs},
ty: t
}
}

pub fn get_region_param(cdata: Cmd, id: ast::NodeId)
-> Option<ty::region_variance> {

let item = lookup_item(id, cdata.data);
return item_ty_region_param(item);
}

pub fn get_type_param_count(data: @~[u8], id: ast::NodeId) -> uint {
item_ty_param_count(lookup_item(id, data))
}

pub fn get_impl_trait(cdata: Cmd,
id: ast::NodeId,
tcx: ty::ctxt) -> Option<@ty::TraitRef>
id: ast::NodeId,
tcx: ty::ctxt) -> Option<@ty::TraitRef>
{
let item_doc = lookup_item(id, cdata.data);
do reader::maybe_get_doc(item_doc, tag_item_trait_ref).map |tp| {
Expand Down Expand Up @@ -1044,6 +1053,7 @@ pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
let name = item_name(intr, method_doc);
let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
tag_item_method_tps);
let rp_defs = item_region_param_defs(method_doc, tcx, cdata);
let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata);
let fty = doc_method_fty(method_doc, tcx, cdata);
let vis = item_visibility(method_doc);
Expand All @@ -1054,7 +1064,7 @@ pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
name,
ty::Generics {
type_param_defs: type_param_defs,
region_param: None
region_param_defs: rp_defs,
},
transformed_self_ty,
fty,
Expand All @@ -1078,6 +1088,14 @@ pub fn get_trait_method_def_ids(cdata: Cmd,
result
}

pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
let data = cdata.data;
let item_doc = lookup_item(id, data);
let variance_doc = reader::get_doc(item_doc, tag_item_variances);
let mut decoder = reader::Decoder(variance_doc);
Decodable::decode(&mut decoder)
}

pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd,
id: ast::NodeId, tcx: ty::ctxt) ->
~[@ty::Method] {
Expand Down
Loading

0 comments on commit 8379890

Please sign in to comment.