Skip to content

Speed up operations on scopes #27943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 45 additions & 14 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}
'B' => {
assert_eq!(self.next(), '[');
// this is the wrong NodeId, but `param_id` is only accessed
// by the receiver-matching code in collect, which won't
// be going down this code path, and anyway I will kill it
// the moment wfcheck becomes the standard.
let node_id = self.parse_uint() as ast::NodeId;
assert_eq!(self.next(), '|');
let space = self.parse_param_space();
Expand All @@ -223,7 +227,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}
'f' => {
assert_eq!(self.next(), '[');
let scope = self.parse_destruction_scope_data();
let scope = self.parse_scope();
assert_eq!(self.next(), '|');
let br = self.parse_bound_region();
assert_eq!(self.next(), ']');
Expand All @@ -246,43 +250,44 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}

fn parse_scope(&mut self) -> region::CodeExtent {
match self.next() {
self.tcx.region_maps.bogus_code_extent(match self.next() {
// This creates scopes with the wrong NodeId. This isn't
// actually a problem because scopes only exist *within*
// functions, and functions aren't loaded until trans which
// doesn't care about regions.
//
// May still be worth fixing though.
'P' => {
assert_eq!(self.next(), '[');
let fn_id = self.parse_uint() as ast::NodeId;
assert_eq!(self.next(), '|');
let body_id = self.parse_uint() as ast::NodeId;
assert_eq!(self.next(), ']');
region::CodeExtent::ParameterScope {
region::CodeExtentData::ParameterScope {
fn_id: fn_id, body_id: body_id
}
}
'M' => {
let node_id = self.parse_uint() as ast::NodeId;
region::CodeExtent::Misc(node_id)
region::CodeExtentData::Misc(node_id)
}
'D' => {
let node_id = self.parse_uint() as ast::NodeId;
region::CodeExtent::DestructionScope(node_id)
region::CodeExtentData::DestructionScope(node_id)
}
'B' => {
assert_eq!(self.next(), '[');
let node_id = self.parse_uint() as ast::NodeId;
assert_eq!(self.next(), '|');
let first_stmt_index = self.parse_uint();
let first_stmt_index = self.parse_u32();
assert_eq!(self.next(), ']');
let block_remainder = region::BlockRemainder {
block: node_id, first_statement_index: first_stmt_index,
};
region::CodeExtent::Remainder(block_remainder)
region::CodeExtentData::Remainder(block_remainder)
}
_ => panic!("parse_scope: bad input")
}
}

fn parse_destruction_scope_data(&mut self) -> region::DestructionScopeData {
let node_id = self.parse_uint() as ast::NodeId;
region::DestructionScopeData::new(node_id)
})
}

fn parse_opt<T, F>(&mut self, f: F) -> Option<T>
Expand Down Expand Up @@ -619,6 +624,33 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
}
}

pub fn parse_region_param_def(&mut self) -> ty::RegionParameterDef {
let name = self.parse_name(':');
let def_id = self.parse_def(NominalType);
let space = self.parse_param_space();
assert_eq!(self.next(), '|');
let index = self.parse_u32();
assert_eq!(self.next(), '|');
let mut bounds = vec![];
loop {
match self.next() {
'R' => bounds.push(self.parse_region()),
'.' => { break; }
c => {
panic!("parse_region_param_def: bad bounds ('{}')", c)
}
}
}
ty::RegionParameterDef {
name: name,
def_id: def_id,
space: space,
index: index,
bounds: bounds
}
}


fn parse_object_lifetime_default(&mut self) -> ty::ObjectLifetimeDefault {
match self.next() {
'a' => ty::ObjectLifetimeDefault::Ambiguous,
Expand Down Expand Up @@ -717,4 +749,3 @@ fn parse_unsafety(c: char) -> ast::Unsafety {
_ => panic!("parse_unsafety: bad unsafety {}", c)
}
}

44 changes: 20 additions & 24 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
}
ty::ReFree(ref fr) => {
mywrite!(w, "f[");
enc_destruction_scope_data(w, fr.scope);
enc_scope(w, cx, fr.scope);
mywrite!(w, "|");
enc_bound_region(w, cx, fr.bound_region);
mywrite!(w, "]");
Expand All @@ -271,29 +271,24 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
ty::ReEmpty => {
mywrite!(w, "e");
}
ty::ReInfer(_) => {
ty::ReVar(_) | ty::ReSkolemized(..) => {
// these should not crop up after typeck
cx.diag.handler().bug("cannot encode region variables");
}
}
}

fn enc_scope(w: &mut Encoder, _cx: &ctxt, scope: region::CodeExtent) {
match scope {
region::CodeExtent::ParameterScope {
fn enc_scope(w: &mut Encoder, cx: &ctxt, scope: region::CodeExtent) {
match cx.tcx.region_maps.code_extent_data(scope) {
region::CodeExtentData::ParameterScope {
fn_id, body_id } => mywrite!(w, "P[{}|{}]", fn_id, body_id),
region::CodeExtent::Misc(node_id) => mywrite!(w, "M{}", node_id),
region::CodeExtent::Remainder(region::BlockRemainder {
region::CodeExtentData::Misc(node_id) => mywrite!(w, "M{}", node_id),
region::CodeExtentData::Remainder(region::BlockRemainder {
block: b, first_statement_index: i }) => mywrite!(w, "B[{}|{}]", b, i),
region::CodeExtent::DestructionScope(node_id) => mywrite!(w, "D{}", node_id),
region::CodeExtentData::DestructionScope(node_id) => mywrite!(w, "D{}", node_id),
}
}

fn enc_destruction_scope_data(w: &mut Encoder,
d: region::DestructionScopeData) {
mywrite!(w, "{}", d.node_id);
}

fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
match br {
ty::BrAnon(idx) => {
Expand Down Expand Up @@ -396,17 +391,6 @@ pub fn enc_existential_bounds<'a,'tcx>(w: &mut Encoder,
mywrite!(w, ".");
}

pub fn enc_region_bounds<'a, 'tcx>(w: &mut Encoder,
cx: &ctxt<'a, 'tcx>,
rs: &[ty::Region]) {
for &r in rs {
mywrite!(w, "R");
enc_region(w, cx, r);
}

mywrite!(w, ".");
}

pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
v: &ty::TypeParameterDef<'tcx>) {
mywrite!(w, "{}:{}|{}|{}|{}|",
Expand All @@ -416,6 +400,18 @@ pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
}

pub fn enc_region_param_def(w: &mut Encoder, cx: &ctxt,
v: &ty::RegionParameterDef) {
mywrite!(w, "{}:{}|{}|{}|",
v.name, (cx.ds)(v.def_id),
v.space.to_uint(), v.index);
for &r in &v.bounds {
mywrite!(w, "R");
enc_region(w, cx, r);
}
mywrite!(w, ".");
}

fn enc_object_lifetime_default<'a, 'tcx>(w: &mut Encoder,
cx: &ctxt<'a, 'tcx>,
default: ty::ObjectLifetimeDefault)
Expand Down
Loading