Skip to content

Commit fc30438

Browse files
Ariel Ben-Yehudaarielb1
Ariel Ben-Yehuda
authored andcommitted
Use a Vec instead of an HashMap for the scope hierarchy
This increases regionck performance greatly - type-checking on librustc decreased from 9.1s to 8.1s. Because of Amdahl's law, total performance is improved only by about 1.5% (LLVM wizards, this is your opportunity to shine!). before: 576.91user 4.26system 7:42.36elapsed 125%CPU (0avgtext+0avgdata 1142192maxresident)k after: 566.50user 4.84system 7:36.84elapsed 125%CPU (0avgtext+0avgdata 1124304maxresident)k I am somewhat worried really need to find out why we have this Red Queen's Race going on here. Originally I suspected it may be a problem from RFC1214's warnings, but it seems to be an effect from other changes. However, the increase seems to be mostly in LLVM's time, so I guess it's the LLVM wizards' problem.
1 parent 2bcc6d8 commit fc30438

File tree

17 files changed

+561
-540
lines changed

17 files changed

+561
-540
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
207207
}
208208
'B' => {
209209
assert_eq!(self.next(), '[');
210+
// this is totally wrong, but nobody relevant cares about
211+
// this field - it will die soon(TM).
210212
let node_id = self.parse_uint() as ast::NodeId;
211213
assert_eq!(self.next(), '|');
212214
let space = self.parse_param_space();
@@ -246,24 +248,26 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
246248
}
247249

248250
fn parse_scope(&mut self) -> region::CodeExtent {
249-
match self.next() {
251+
self.tcx.region_maps.bogus_code_extent(match self.next() {
252+
// the scopes created here are totally bogus with their
253+
// NodeIDs
250254
'P' => {
251255
assert_eq!(self.next(), '[');
252256
let fn_id = self.parse_uint() as ast::NodeId;
253257
assert_eq!(self.next(), '|');
254258
let body_id = self.parse_uint() as ast::NodeId;
255259
assert_eq!(self.next(), ']');
256-
region::CodeExtent::ParameterScope {
260+
region::CodeExtentData::ParameterScope {
257261
fn_id: fn_id, body_id: body_id
258262
}
259263
}
260264
'M' => {
261265
let node_id = self.parse_uint() as ast::NodeId;
262-
region::CodeExtent::Misc(node_id)
266+
region::CodeExtentData::Misc(node_id)
263267
}
264268
'D' => {
265269
let node_id = self.parse_uint() as ast::NodeId;
266-
region::CodeExtent::DestructionScope(node_id)
270+
region::CodeExtentData::DestructionScope(node_id)
267271
}
268272
'B' => {
269273
assert_eq!(self.next(), '[');
@@ -274,10 +278,10 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
274278
let block_remainder = region::BlockRemainder {
275279
block: node_id, first_statement_index: first_stmt_index,
276280
};
277-
region::CodeExtent::Remainder(block_remainder)
281+
region::CodeExtentData::Remainder(block_remainder)
278282
}
279283
_ => panic!("parse_scope: bad input")
280-
}
284+
})
281285
}
282286

283287
fn parse_destruction_scope_data(&mut self) -> region::DestructionScopeData {
@@ -619,6 +623,33 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
619623
}
620624
}
621625

626+
pub fn parse_region_param_def(&mut self) -> ty::RegionParameterDef {
627+
let name = self.parse_name(':');
628+
let def_id = self.parse_def(NominalType);
629+
let space = self.parse_param_space();
630+
assert_eq!(self.next(), '|');
631+
let index = self.parse_u32();
632+
assert_eq!(self.next(), '|');
633+
let mut bounds = vec![];
634+
loop {
635+
match self.next() {
636+
'R' => bounds.push(self.parse_region()),
637+
'.' => { break; }
638+
c => {
639+
panic!("parse_region_param_def: bad bounds ('{}')", c)
640+
}
641+
}
642+
}
643+
ty::RegionParameterDef {
644+
name: name,
645+
def_id: def_id,
646+
space: space,
647+
index: index,
648+
bounds: bounds
649+
}
650+
}
651+
652+
622653
fn parse_object_lifetime_default(&mut self) -> ty::ObjectLifetimeDefault {
623654
match self.next() {
624655
'a' => ty::ObjectLifetimeDefault::Ambiguous,

src/librustc/metadata/tyencode.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
278278
}
279279
}
280280

281-
fn enc_scope(w: &mut Encoder, _cx: &ctxt, scope: region::CodeExtent) {
282-
match scope {
283-
region::CodeExtent::ParameterScope {
281+
fn enc_scope(w: &mut Encoder, cx: &ctxt, scope: region::CodeExtent) {
282+
match cx.tcx.region_maps.code_extent_data(scope) {
283+
region::CodeExtentData::ParameterScope {
284284
fn_id, body_id } => mywrite!(w, "P[{}|{}]", fn_id, body_id),
285-
region::CodeExtent::Misc(node_id) => mywrite!(w, "M{}", node_id),
286-
region::CodeExtent::Remainder(region::BlockRemainder {
285+
region::CodeExtentData::Misc(node_id) => mywrite!(w, "M{}", node_id),
286+
region::CodeExtentData::Remainder(region::BlockRemainder {
287287
block: b, first_statement_index: i }) => mywrite!(w, "B[{}|{}]", b, i),
288-
region::CodeExtent::DestructionScope(node_id) => mywrite!(w, "D{}", node_id),
288+
region::CodeExtentData::DestructionScope(node_id) => mywrite!(w, "D{}", node_id),
289289
}
290290
}
291291

@@ -396,17 +396,6 @@ pub fn enc_existential_bounds<'a,'tcx>(w: &mut Encoder,
396396
mywrite!(w, ".");
397397
}
398398

399-
pub fn enc_region_bounds<'a, 'tcx>(w: &mut Encoder,
400-
cx: &ctxt<'a, 'tcx>,
401-
rs: &[ty::Region]) {
402-
for &r in rs {
403-
mywrite!(w, "R");
404-
enc_region(w, cx, r);
405-
}
406-
407-
mywrite!(w, ".");
408-
}
409-
410399
pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
411400
v: &ty::TypeParameterDef<'tcx>) {
412401
mywrite!(w, "{}:{}|{}|{}|{}|",
@@ -416,6 +405,18 @@ pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
416405
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
417406
}
418407

408+
pub fn enc_region_param_def(w: &mut Encoder, cx: &ctxt,
409+
v: &ty::RegionParameterDef) {
410+
mywrite!(w, "{}:{}|{}|{}|",
411+
v.name, (cx.ds)(v.def_id),
412+
v.space.to_uint(), v.index);
413+
for &r in &v.bounds {
414+
mywrite!(w, "R");
415+
enc_region(w, cx, r);
416+
}
417+
mywrite!(w, ".");
418+
}
419+
419420
fn enc_object_lifetime_default<'a, 'tcx>(w: &mut Encoder,
420421
cx: &ctxt<'a, 'tcx>,
421422
default: ty::ObjectLifetimeDefault)

0 commit comments

Comments
 (0)