Skip to content

Commit 1f4faae

Browse files
committed
Generalize AST and ty::Generics to accept multiple lifetimes.
1 parent 85c51d3 commit 1f4faae

Some content is hidden

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

52 files changed

+1516
-1460
lines changed

src/librustc/front/std_inject.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ use syntax::diagnostic;
5353
pub mod middle {
5454
pub mod trans;
5555
pub mod ty;
56+
pub mod ty_fold;
5657
pub mod subst;
5758
pub mod resolve;
59+
pub mod resolve_lifetime;
5860
pub mod typeck;
5961
pub mod check_loop;
6062
pub mod check_match;

src/librustc/metadata/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,6 @@ pub fn get_trait_def(tcx: ty::ctxt, def: ast::DefId) -> ty::TraitDef {
199199
decoder::get_trait_def(cdata, def.node, tcx)
200200
}
201201

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-
208202
pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
209203
def: ast::DefId) -> ty::ty_param_bounds_and_ty {
210204
let cstore = tcx.cstore;
@@ -224,7 +218,7 @@ pub fn get_field_type(tcx: ty::ctxt, class_id: ast::DefId,
224218
let ty = decoder::item_type(def, the_field, tcx, cdata);
225219
ty::ty_param_bounds_and_ty {
226220
generics: ty::Generics {type_param_defs: @~[],
227-
region_param: None},
221+
region_param_defs: @[]},
228222
ty: ty
229223
}
230224
}

src/librustc/metadata/decoder.rs

Lines changed: 34 additions & 24 deletions
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,

src/librustc/metadata/encoder.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,6 @@ pub fn encode_def_id(ebml_w: &mut writer::Encoder, id: DefId) {
121121
ebml_w.wr_tagged_str(tag_def_id, def_to_str(id));
122122
}
123123

124-
fn encode_region_param(ecx: &EncodeContext,
125-
ebml_w: &mut writer::Encoder,
126-
it: @ast::item) {
127-
let opt_rp = ecx.tcx.region_paramd_items.find(&it.id);
128-
for rp in opt_rp.iter() {
129-
ebml_w.start_tag(tag_region_param);
130-
rp.encode(ebml_w);
131-
ebml_w.end_tag();
132-
}
133-
}
134-
135124
#[deriving(Clone)]
136125
struct entry<T> {
137126
val: T,
@@ -205,11 +194,29 @@ fn encode_ty_type_param_defs(ebml_w: &mut writer::Encoder,
205194
}
206195
}
207196

197+
fn encode_region_param_defs(ebml_w: &mut writer::Encoder,
198+
ecx: &EncodeContext,
199+
params: @[ty::RegionParameterDef]) {
200+
for param in params.iter() {
201+
ebml_w.start_tag(tag_region_param_def);
202+
203+
ebml_w.start_tag(tag_region_param_def_ident);
204+
encode_name(ecx, ebml_w, param.ident);
205+
ebml_w.end_tag();
206+
207+
ebml_w.wr_tagged_str(tag_region_param_def_def_id,
208+
def_to_str(param.def_id));
209+
210+
ebml_w.end_tag();
211+
}
212+
}
213+
208214
fn encode_bounds_and_type(ebml_w: &mut writer::Encoder,
209215
ecx: &EncodeContext,
210216
tpt: &ty::ty_param_bounds_and_ty) {
211217
encode_ty_type_param_defs(ebml_w, ecx, tpt.generics.type_param_defs,
212218
tag_items_data_item_ty_param_bounds);
219+
encode_region_param_defs(ebml_w, ecx, tpt.generics.region_param_defs);
213220
encode_type(ecx, ebml_w, tpt.ty);
214221
}
215222

@@ -976,7 +983,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
976983
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
977984
encode_name(ecx, ebml_w, item.ident);
978985
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
979-
encode_region_param(ecx, ebml_w, item);
980986
encode_visibility(ebml_w, vis);
981987
ebml_w.end_tag();
982988
}
@@ -994,7 +1000,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
9941000
}
9951001
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
9961002
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
997-
encode_region_param(ecx, ebml_w, item);
9981003

9991004
// Encode inherent implementations for this enumeration.
10001005
encode_inherent_implementations(ecx, ebml_w, def_id);
@@ -1030,7 +1035,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
10301035
encode_name(ecx, ebml_w, item.ident);
10311036
encode_attributes(ebml_w, item.attrs);
10321037
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
1033-
encode_region_param(ecx, ebml_w, item);
10341038
encode_visibility(ebml_w, vis);
10351039

10361040
/* Encode def_ids for each field and method
@@ -1075,7 +1079,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
10751079
ebml_w.start_tag(tag_items_data_item);
10761080
encode_def_id(ebml_w, def_id);
10771081
encode_family(ebml_w, 'i');
1078-
encode_region_param(ecx, ebml_w, item);
10791082
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
10801083
encode_name(ecx, ebml_w, item.ident);
10811084
encode_attributes(ebml_w, item.attrs);
@@ -1135,7 +1138,6 @@ fn encode_info_for_item(ecx: &EncodeContext,
11351138
ebml_w.start_tag(tag_items_data_item);
11361139
encode_def_id(ebml_w, def_id);
11371140
encode_family(ebml_w, 'I');
1138-
encode_region_param(ecx, ebml_w, item);
11391141
let trait_def = ty::lookup_trait_def(tcx, def_id);
11401142
encode_ty_type_param_defs(ebml_w, ecx,
11411143
trait_def.generics.type_param_defs,

0 commit comments

Comments
 (0)