Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 511e762

Browse files
committedAug 23, 2012
Infer variance of types with respect to the region parameter.
A similar approach could be used for type parameters. Fixes #2282.
1 parent 8185ede commit 511e762

33 files changed

+723
-235
lines changed
 

‎src/libcore/task.rs

+1
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ enum AncestorList = option<unsafe::Exclusive<AncestorNode>>;
770770
fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U {
771771
unsafe { x.with(blk) }
772772
}
773+
773774
#[inline(always)]
774775
fn access_ancestors<U>(x: &unsafe::Exclusive<AncestorNode>,
775776
blk: fn(x: &mut AncestorNode) -> U) -> U {

‎src/libsyntax/ast_map.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,20 @@ fn node_id_to_str(map: map, id: node_id, itr: ident_interner) -> ~str {
299299
fmt!{"unknown node (id=%d)", id}
300300
}
301301
some(node_item(item, path)) => {
302-
fmt!{"item %s (id=%?)", path_ident_to_str(*path, item.ident, itr), id}
302+
let path_str = path_ident_to_str(*path, item.ident, itr);
303+
let item_str = match item.node {
304+
item_const(*) => ~"const",
305+
item_fn(*) => ~"fn",
306+
item_mod(*) => ~"mod",
307+
item_foreign_mod(*) => ~"foreign mod",
308+
item_ty(*) => ~"ty",
309+
item_enum(*) => ~"enum",
310+
item_class(*) => ~"class",
311+
item_trait(*) => ~"trait",
312+
item_impl(*) => ~"impl",
313+
item_mac(*) => ~"macro"
314+
};
315+
fmt!("%s %s (id=%?)", item_str, path_str, id)
303316
}
304317
some(node_foreign_item(item, abi, path)) => {
305318
fmt!{"foreign item %s with abi %? (id=%?)",

‎src/rustc/metadata/csearch.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
127127
}
128128

129129
fn get_region_param(cstore: metadata::cstore::cstore,
130-
def: ast::def_id) -> bool {
130+
def: ast::def_id) -> option<ty::region_variance> {
131131
let cdata = cstore::get_crate_data(cstore, def.crate);
132132
return decoder::get_region_param(cdata, def.node);
133133
}
@@ -149,7 +149,9 @@ fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
149149
class_id, def} );
150150
debug!{"got field data %?", the_field};
151151
let ty = decoder::item_type(def, the_field, tcx, cdata);
152-
return {bounds: @~[], rp: false, ty: ty};
152+
return {bounds: @~[],
153+
region_param: none,
154+
ty: ty};
153155
}
154156

155157
// Given a def_id for an impl or class, return the traits it implements,

‎src/rustc/metadata/decoder.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ fn item_ty_param_bounds(item: ebml::doc, tcx: ty::ctxt, cdata: cmd)
237237
@bounds
238238
}
239239

240-
fn item_ty_region_param(item: ebml::doc) -> bool {
241-
match ebml::maybe_get_doc(item, tag_region_param) {
242-
some(_) => true,
243-
none => false
244-
}
240+
fn item_ty_region_param(item: ebml::doc) -> option<ty::region_variance> {
241+
ebml::maybe_get_doc(item, tag_region_param).map(|doc| {
242+
let d = ebml::ebml_deserializer(doc);
243+
ty::deserialize_region_variance(d)
244+
})
245245
}
246246

247247
fn item_ty_param_count(item: ebml::doc) -> uint {
@@ -340,10 +340,14 @@ fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
340340
item_ty_param_bounds(item, tcx, cdata)
341341
} else { @~[] };
342342
let rp = item_ty_region_param(item);
343-
return {bounds: tp_bounds, rp: rp, ty: t};
343+
return {bounds: tp_bounds,
344+
region_param: rp,
345+
ty: t};
344346
}
345347

346-
fn get_region_param(cdata: cmd, id: ast::node_id) -> bool {
348+
fn get_region_param(cdata: cmd, id: ast::node_id)
349+
-> option<ty::region_variance> {
350+
347351
let item = lookup_item(id, cdata.data);
348352
return item_ty_region_param(item);
349353
}

‎src/rustc/metadata/encoder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ fn encode_def_id(ebml_w: ebml::writer, id: def_id) {
8181

8282
fn encode_region_param(ecx: @encode_ctxt, ebml_w: ebml::writer,
8383
it: @ast::item) {
84-
let rp = ecx.tcx.region_paramd_items.contains_key(it.id);
85-
if rp { do ebml_w.wr_tag(tag_region_param) { } }
84+
let opt_rp = ecx.tcx.region_paramd_items.find(it.id);
85+
for opt_rp.each |rp| {
86+
do ebml_w.wr_tag(tag_region_param) {
87+
ty::serialize_region_variance(ebml_w, rp);
88+
}
89+
}
8690
}
8791

8892
fn encode_mutability(ebml_w: ebml::writer, mt: class_mutability) {

‎src/rustc/middle/astencode.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,10 @@ impl ebml::writer: ebml_writer_helpers {
601601
self.emit_bounds(ecx, bs);
602602
}
603603
}
604-
do self.emit_rec_field(~"rp", 1u) {
605-
self.emit_bool(tpbt.rp);
604+
do self.emit_rec_field(~"region_param", 1u) {
605+
ty::serialize_opt_region_variance(
606+
self,
607+
tpbt.region_param);
606608
}
607609
do self.emit_rec_field(~"ty", 2u) {
608610
self.emit_ty(ecx, tpbt.ty);
@@ -817,8 +819,8 @@ impl ebml::ebml_deserializer: ebml_deserializer_decoder_helpers {
817819
bounds: self.read_rec_field(~"bounds", 0u, || {
818820
@self.read_to_vec(|| self.read_bounds(xcx) )
819821
}),
820-
rp: self.read_rec_field(~"rp", 1u, || {
821-
self.read_bool()
822+
region_param: self.read_rec_field(~"region_param", 1u, || {
823+
ty::deserialize_opt_region_variance(self)
822824
}),
823825
ty: self.read_rec_field(~"ty", 2u, || {
824826
self.read_ty(xcx)
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.