Skip to content

Commit

Permalink
Introduce new variance inference pass that replaces (and generalizes)…
Browse files Browse the repository at this point in the history
… old

region-parameterization/variance inference. We now compute variance for
type parameters but do not make use of it (most of the way towards rust-lang#3598).
  • Loading branch information
nikomatsakis committed Nov 9, 2013
1 parent 1f4faae commit 9d3f57e
Show file tree
Hide file tree
Showing 23 changed files with 1,278 additions and 807 deletions.
2 changes: 1 addition & 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
7 changes: 6 additions & 1 deletion 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
8 changes: 8 additions & 0 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,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
12 changes: 12 additions & 0 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ fn encode_region_param_defs(ebml_w: &mut writer::Encoder,
}
}

fn encode_item_variances(ebml_w: &mut writer::Encoder,
ecx: &EncodeContext,
id: ast::NodeId) {
let v = ty::item_variances(ecx.tcx, ast_util::local_def(id));
ebml_w.start_tag(tag_item_variances);
v.encode(ebml_w);
ebml_w.end_tag();
}

fn encode_bounds_and_type(ebml_w: &mut writer::Encoder,
ecx: &EncodeContext,
tpt: &ty::ty_param_bounds_and_ty) {
Expand Down Expand Up @@ -992,6 +1001,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 't');
encode_item_variances(ebml_w, ecx, item.id);
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));
encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs);
Expand Down Expand Up @@ -1032,6 +1042,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_family(ebml_w, 'S');
encode_bounds_and_type(ebml_w, ecx, &lookup_item_type(tcx, def_id));

encode_item_variances(ebml_w, ecx, item.id);
encode_name(ecx, ebml_w, item.ident);
encode_attributes(ebml_w, item.attrs);
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
Expand Down Expand Up @@ -1138,6 +1149,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, def_id);
encode_family(ebml_w, 'I');
encode_item_variances(ebml_w, ecx, item.id);
let trait_def = ty::lookup_trait_def(tcx, def_id);
encode_ty_type_param_defs(ebml_w, ecx,
trait_def.generics.type_param_defs,
Expand Down
Loading

0 comments on commit 9d3f57e

Please sign in to comment.