Skip to content

Commit 8379890

Browse files
committed
auto merge of #10153 : nikomatsakis/rust/issue-4846-multiple-lifetime-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
2 parents dc5d9b9 + f6e8d49 commit 8379890

File tree

117 files changed

+5025
-3605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+5025
-3605
lines changed

Makefile.in

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ ifdef TRACE
125125
CFG_RUSTC_FLAGS += -Z trace
126126
endif
127127
ifndef DEBUG_BORROWS
128+
RUSTFLAGS_STAGE0 += -Z no-debug-borrows
128129
RUSTFLAGS_STAGE1 += -Z no-debug-borrows
129130
RUSTFLAGS_STAGE2 += -Z no-debug-borrows
130131
endif

src/libextra/arc.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ impl<T:Send> MutexArc<T> {
233233

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

291291
/// As unsafe_access_cond but safe and Freeze.
292292
#[inline]
293-
pub fn access_cond<'x, 'c, U>(&self,
294-
blk: &fn(x: &'x mut T,
295-
c: &'c Condvar) -> U)
296-
-> U {
293+
pub fn access_cond<U>(&self,
294+
blk: &fn(x: &mut T,
295+
c: &Condvar) -> U)
296+
-> U {
297297
unsafe { self.unsafe_access_cond(blk) }
298298
}
299299
}
@@ -402,9 +402,9 @@ impl<T:Freeze + Send> RWArc<T> {
402402

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

556556
/// Access the pre-downgrade RWArc in write mode with a condvar.
557-
pub fn write_cond<'x, 'c, U>(&mut self,
558-
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
559-
-> U {
557+
pub fn write_cond<U>(&mut self,
558+
blk: &fn(x: &mut T, c: &Condvar) -> U)
559+
-> U {
560560
match *self {
561561
RWWriteMode {
562562
data: &ref mut data,

src/librustc/driver/driver.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,20 @@ pub fn phase_3_run_analysis_passes(sess: Session,
239239
time(time_passes, "resolution", (), |_|
240240
middle::resolve::resolve_crate(sess, lang_items, crate));
241241

242+
let named_region_map = time(time_passes, "lifetime resolution", (),
243+
|_| middle::resolve_lifetime::crate(sess, crate));
244+
242245
time(time_passes, "looking for entry point", (),
243246
|_| middle::entry::find_entry_point(sess, crate, ast_map));
244247

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

248251
let region_map = time(time_passes, "region resolution", (), |_|
249-
middle::region::resolve_crate(sess, def_map, crate));
250-
251-
let rp_set = time(time_passes, "region parameterization inference", (), |_|
252-
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
252+
middle::region::resolve_crate(sess, crate));
253253

254-
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
255-
region_map, rp_set, lang_items);
254+
let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars,
255+
region_map, lang_items);
256256

257257
// passes are timed inside typeck
258258
let (method_map, vtable_map) = typeck::check_crate(

src/librustc/front/std_inject.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ impl fold::ast_fold for StandardLibraryInjector {
116116
segments: ~[
117117
ast::PathSegment {
118118
identifier: self.sess.ident_of("std"),
119-
lifetime: None,
119+
lifetimes: opt_vec::Empty,
120120
types: opt_vec::Empty,
121121
},
122122
ast::PathSegment {
123123
identifier: self.sess.ident_of("prelude"),
124-
lifetime: None,
124+
lifetimes: opt_vec::Empty,
125125
types: opt_vec::Empty,
126126
},
127127
],

src/librustc/front/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ fn path_node(ids: ~[ast::Ident]) -> ast::Path {
343343
global: false,
344344
segments: ids.move_iter().map(|identifier| ast::PathSegment {
345345
identifier: identifier,
346-
lifetime: None,
346+
lifetimes: opt_vec::Empty,
347347
types: opt_vec::Empty,
348348
}).collect()
349349
}
@@ -355,7 +355,7 @@ fn path_node_global(ids: ~[ast::Ident]) -> ast::Path {
355355
global: true,
356356
segments: ids.move_iter().map(|identifier| ast::PathSegment {
357357
identifier: identifier,
358-
lifetime: None,
358+
lifetimes: opt_vec::Empty,
359359
types: opt_vec::Empty,
360360
}).collect()
361361
}

src/librustc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ use syntax::diagnostic;
5454
pub mod middle {
5555
pub mod trans;
5656
pub mod ty;
57+
pub mod ty_fold;
5758
pub mod subst;
5859
pub mod resolve;
60+
pub mod resolve_lifetime;
5961
pub mod typeck;
6062
pub mod check_loop;
6163
pub mod check_match;

src/librustc/metadata/common.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub static tag_path_elt_name: uint = 0x43u;
8989
pub static tag_item_field: uint = 0x44u;
9090
pub static tag_struct_mut: uint = 0x45u;
9191

92-
pub static tag_region_param: uint = 0x46u;
92+
pub static tag_item_variances: uint = 0x46;
9393
pub static tag_mod_impl_trait: uint = 0x47u;
9494
/*
9595
trait items contain tag_item_trait_method elements,
@@ -193,6 +193,11 @@ pub static tag_path_elt_pretty_name: uint = 0x87;
193193
pub static tag_path_elt_pretty_name_ident: uint = 0x88;
194194
pub static tag_path_elt_pretty_name_extra: uint = 0x89;
195195

196+
pub static tag_region_param_def: uint = 0x100;
197+
pub static tag_region_param_def_ident: uint = 0x101;
198+
pub static tag_region_param_def_def_id: uint = 0x102;
199+
200+
196201
pub struct LinkMeta {
197202
name: @str,
198203
vers: @str,

src/librustc/metadata/csearch.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use metadata::common::*;
1515
use metadata::cstore;
1616
use metadata::decoder;
17-
use metadata;
1817
use middle::ty;
1918
use middle::typeck;
2019

@@ -144,6 +143,12 @@ pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,
144143
decoder::get_trait_method_def_ids(cdata, def.node)
145144
}
146145

146+
pub fn get_item_variances(cstore: @mut cstore::CStore,
147+
def: ast::DefId) -> ty::ItemVariances {
148+
let cdata = cstore::get_crate_data(cstore, def.crate);
149+
decoder::get_item_variances(cdata, def.node)
150+
}
151+
147152
pub fn get_provided_trait_methods(tcx: ty::ctxt,
148153
def: ast::DefId)
149154
-> ~[@ty::Method] {
@@ -199,12 +204,6 @@ pub fn get_trait_def(tcx: ty::ctxt, def: ast::DefId) -> ty::TraitDef {
199204
decoder::get_trait_def(cdata, def.node, tcx)
200205
}
201206

202-
pub fn get_region_param(cstore: @mut metadata::cstore::CStore,
203-
def: ast::DefId) -> Option<ty::region_variance> {
204-
let cdata = cstore::get_crate_data(cstore, def.crate);
205-
return decoder::get_region_param(cdata, def.node);
206-
}
207-
208207
pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
209208
def: ast::DefId) -> ty::ty_param_bounds_and_ty {
210209
let cstore = tcx.cstore;
@@ -224,7 +223,7 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
224223
let ty = decoder::item_type(def, the_field, tcx, cdata);
225224
ty::ty_param_bounds_and_ty {
226225
generics: ty::Generics {type_param_defs: @~[],
227-
region_param: None},
226+
region_param_defs: @[]},
228227
ty: ty
229228
}
230229
}

src/librustc/metadata/decoder.rs

+42-24
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use middle::ty;
2525
use middle::typeck;
2626
use middle::astencode::vtable_decoder_helpers;
2727

28-
28+
use std::at_vec;
2929
use std::u64;
3030
use std::rt::io;
3131
use std::rt::io::extensions::u64_from_be_bytes;
@@ -252,9 +252,11 @@ fn item_trait_ref(doc: ebml::Doc, tcx: ty::ctxt, cdata: Cmd) -> ty::TraitRef {
252252
doc_trait_ref(tp, tcx, cdata)
253253
}
254254

255-
fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: Cmd,
255+
fn item_ty_param_defs(item: ebml::Doc,
256+
tcx: ty::ctxt,
257+
cdata: Cmd,
256258
tag: uint)
257-
-> @~[ty::TypeParameterDef] {
259+
-> @~[ty::TypeParameterDef] {
258260
let mut bounds = ~[];
259261
do reader::tagged_docs(item, tag) |p| {
260262
let bd = parse_type_param_def_data(
@@ -266,10 +268,23 @@ fn item_ty_param_defs(item: ebml::Doc, tcx: ty::ctxt, cdata: Cmd,
266268
@bounds
267269
}
268270

269-
fn item_ty_region_param(item: ebml::Doc) -> Option<ty::region_variance> {
270-
do reader::maybe_get_doc(item, tag_region_param).map |doc| {
271-
let mut decoder = reader::Decoder(doc);
272-
Decodable::decode(&mut decoder)
271+
fn item_region_param_defs(item_doc: ebml::Doc,
272+
tcx: ty::ctxt,
273+
cdata: Cmd)
274+
-> @[ty::RegionParameterDef] {
275+
do at_vec::build(None) |push| {
276+
do reader::tagged_docs(item_doc, tag_region_param_def) |rp_doc| {
277+
let ident_str_doc = reader::get_doc(rp_doc,
278+
tag_region_param_def_ident);
279+
let ident = item_name(tcx.sess.intr(), ident_str_doc);
280+
let def_id_doc = reader::get_doc(rp_doc,
281+
tag_region_param_def_def_id);
282+
let def_id = reader::with_doc_data(def_id_doc, parse_def_id);
283+
let def_id = translate_def_id(cdata, def_id);
284+
push(ty::RegionParameterDef { ident: ident,
285+
def_id: def_id });
286+
true
287+
};
273288
}
274289
}
275290

@@ -393,7 +408,7 @@ pub fn get_trait_def(cdata: Cmd,
393408
let item_doc = lookup_item(item_id, cdata.data);
394409
let tp_defs = item_ty_param_defs(item_doc, tcx, cdata,
395410
tag_items_data_item_ty_param_bounds);
396-
let rp = item_ty_region_param(item_doc);
411+
let rp_defs = item_region_param_defs(item_doc, tcx, cdata);
397412
let mut bounds = ty::EmptyBuiltinBounds();
398413
// Collect the builtin bounds from the encoded supertraits.
399414
// FIXME(#8559): They should be encoded directly.
@@ -407,7 +422,7 @@ pub fn get_trait_def(cdata: Cmd,
407422
};
408423
ty::TraitDef {
409424
generics: ty::Generics {type_param_defs: tp_defs,
410-
region_param: rp},
425+
region_param_defs: rp_defs},
411426
bounds: bounds,
412427
trait_ref: @item_trait_ref(item_doc, tcx, cdata)
413428
}
@@ -417,33 +432,27 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: ty::ctxt)
417432
-> ty::ty_param_bounds_and_ty {
418433

419434
let item = lookup_item(id, cdata.data);
435+
420436
let t = item_type(ast::DefId { crate: cdata.cnum, node: id }, item, tcx,
421437
cdata);
422-
let tp_defs = if family_has_type_params(item_family(item)) {
423-
item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds)
424-
} else { @~[] };
425-
let rp = item_ty_region_param(item);
438+
439+
let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
440+
let rp_defs = item_region_param_defs(item, tcx, cdata);
441+
426442
ty::ty_param_bounds_and_ty {
427443
generics: ty::Generics {type_param_defs: tp_defs,
428-
region_param: rp},
444+
region_param_defs: rp_defs},
429445
ty: t
430446
}
431447
}
432448

433-
pub fn get_region_param(cdata: Cmd, id: ast::NodeId)
434-
-> Option<ty::region_variance> {
435-
436-
let item = lookup_item(id, cdata.data);
437-
return item_ty_region_param(item);
438-
}
439-
440449
pub fn get_type_param_count(data: @~[u8], id: ast::NodeId) -> uint {
441450
item_ty_param_count(lookup_item(id, data))
442451
}
443452

444453
pub fn get_impl_trait(cdata: Cmd,
445-
id: ast::NodeId,
446-
tcx: ty::ctxt) -> Option<@ty::TraitRef>
454+
id: ast::NodeId,
455+
tcx: ty::ctxt) -> Option<@ty::TraitRef>
447456
{
448457
let item_doc = lookup_item(id, cdata.data);
449458
do reader::maybe_get_doc(item_doc, tag_item_trait_ref).map |tp| {
@@ -1044,6 +1053,7 @@ pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
10441053
let name = item_name(intr, method_doc);
10451054
let type_param_defs = item_ty_param_defs(method_doc, tcx, cdata,
10461055
tag_item_method_tps);
1056+
let rp_defs = item_region_param_defs(method_doc, tcx, cdata);
10471057
let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata);
10481058
let fty = doc_method_fty(method_doc, tcx, cdata);
10491059
let vis = item_visibility(method_doc);
@@ -1054,7 +1064,7 @@ pub fn get_method(intr: @ident_interner, cdata: Cmd, id: ast::NodeId,
10541064
name,
10551065
ty::Generics {
10561066
type_param_defs: type_param_defs,
1057-
region_param: None
1067+
region_param_defs: rp_defs,
10581068
},
10591069
transformed_self_ty,
10601070
fty,
@@ -1078,6 +1088,14 @@ pub fn get_trait_method_def_ids(cdata: Cmd,
10781088
result
10791089
}
10801090

1091+
pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
1092+
let data = cdata.data;
1093+
let item_doc = lookup_item(id, data);
1094+
let variance_doc = reader::get_doc(item_doc, tag_item_variances);
1095+
let mut decoder = reader::Decoder(variance_doc);
1096+
Decodable::decode(&mut decoder)
1097+
}
1098+
10811099
pub fn get_provided_trait_methods(intr: @ident_interner, cdata: Cmd,
10821100
id: ast::NodeId, tcx: ty::ctxt) ->
10831101
~[@ty::Method] {

0 commit comments

Comments
 (0)