Skip to content

Commit bc35734

Browse files
committed
Auto merge of #27943 - arielb1:fast-region, r=nikomatsakis
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. r? @nikomatsakis
2 parents 4c99649 + 06563fe commit bc35734

File tree

33 files changed

+664
-664
lines changed

33 files changed

+664
-664
lines changed

src/librustc/metadata/tydecode.rs

+45-14
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
207207
}
208208
'B' => {
209209
assert_eq!(self.next(), '[');
210+
// this is the wrong NodeId, but `param_id` is only accessed
211+
// by the receiver-matching code in collect, which won't
212+
// be going down this code path, and anyway I will kill it
213+
// the moment wfcheck becomes the standard.
210214
let node_id = self.parse_uint() as ast::NodeId;
211215
assert_eq!(self.next(), '|');
212216
let space = self.parse_param_space();
@@ -223,7 +227,7 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
223227
}
224228
'f' => {
225229
assert_eq!(self.next(), '[');
226-
let scope = self.parse_destruction_scope_data();
230+
let scope = self.parse_scope();
227231
assert_eq!(self.next(), '|');
228232
let br = self.parse_bound_region();
229233
assert_eq!(self.next(), ']');
@@ -246,43 +250,44 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
246250
}
247251

248252
fn parse_scope(&mut self) -> region::CodeExtent {
249-
match self.next() {
253+
self.tcx.region_maps.bogus_code_extent(match self.next() {
254+
// This creates scopes with the wrong NodeId. This isn't
255+
// actually a problem because scopes only exist *within*
256+
// functions, and functions aren't loaded until trans which
257+
// doesn't care about regions.
258+
//
259+
// May still be worth fixing though.
250260
'P' => {
251261
assert_eq!(self.next(), '[');
252262
let fn_id = self.parse_uint() as ast::NodeId;
253263
assert_eq!(self.next(), '|');
254264
let body_id = self.parse_uint() as ast::NodeId;
255265
assert_eq!(self.next(), ']');
256-
region::CodeExtent::ParameterScope {
266+
region::CodeExtentData::ParameterScope {
257267
fn_id: fn_id, body_id: body_id
258268
}
259269
}
260270
'M' => {
261271
let node_id = self.parse_uint() as ast::NodeId;
262-
region::CodeExtent::Misc(node_id)
272+
region::CodeExtentData::Misc(node_id)
263273
}
264274
'D' => {
265275
let node_id = self.parse_uint() as ast::NodeId;
266-
region::CodeExtent::DestructionScope(node_id)
276+
region::CodeExtentData::DestructionScope(node_id)
267277
}
268278
'B' => {
269279
assert_eq!(self.next(), '[');
270280
let node_id = self.parse_uint() as ast::NodeId;
271281
assert_eq!(self.next(), '|');
272-
let first_stmt_index = self.parse_uint();
282+
let first_stmt_index = self.parse_u32();
273283
assert_eq!(self.next(), ']');
274284
let block_remainder = region::BlockRemainder {
275285
block: node_id, first_statement_index: first_stmt_index,
276286
};
277-
region::CodeExtent::Remainder(block_remainder)
287+
region::CodeExtentData::Remainder(block_remainder)
278288
}
279289
_ => panic!("parse_scope: bad input")
280-
}
281-
}
282-
283-
fn parse_destruction_scope_data(&mut self) -> region::DestructionScopeData {
284-
let node_id = self.parse_uint() as ast::NodeId;
285-
region::DestructionScopeData::new(node_id)
290+
})
286291
}
287292

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

627+
pub fn parse_region_param_def(&mut self) -> ty::RegionParameterDef {
628+
let name = self.parse_name(':');
629+
let def_id = self.parse_def(NominalType);
630+
let space = self.parse_param_space();
631+
assert_eq!(self.next(), '|');
632+
let index = self.parse_u32();
633+
assert_eq!(self.next(), '|');
634+
let mut bounds = vec![];
635+
loop {
636+
match self.next() {
637+
'R' => bounds.push(self.parse_region()),
638+
'.' => { break; }
639+
c => {
640+
panic!("parse_region_param_def: bad bounds ('{}')", c)
641+
}
642+
}
643+
}
644+
ty::RegionParameterDef {
645+
name: name,
646+
def_id: def_id,
647+
space: space,
648+
index: index,
649+
bounds: bounds
650+
}
651+
}
652+
653+
622654
fn parse_object_lifetime_default(&mut self) -> ty::ObjectLifetimeDefault {
623655
match self.next() {
624656
'a' => ty::ObjectLifetimeDefault::Ambiguous,
@@ -717,4 +749,3 @@ fn parse_unsafety(c: char) -> ast::Unsafety {
717749
_ => panic!("parse_unsafety: bad unsafety {}", c)
718750
}
719751
}
720-

src/librustc/metadata/tyencode.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
255255
}
256256
ty::ReFree(ref fr) => {
257257
mywrite!(w, "f[");
258-
enc_destruction_scope_data(w, fr.scope);
258+
enc_scope(w, cx, fr.scope);
259259
mywrite!(w, "|");
260260
enc_bound_region(w, cx, fr.bound_region);
261261
mywrite!(w, "]");
@@ -271,29 +271,24 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
271271
ty::ReEmpty => {
272272
mywrite!(w, "e");
273273
}
274-
ty::ReInfer(_) => {
274+
ty::ReVar(_) | ty::ReSkolemized(..) => {
275275
// these should not crop up after typeck
276276
cx.diag.handler().bug("cannot encode region variables");
277277
}
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

292-
fn enc_destruction_scope_data(w: &mut Encoder,
293-
d: region::DestructionScopeData) {
294-
mywrite!(w, "{}", d.node_id);
295-
}
296-
297292
fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
298293
match br {
299294
ty::BrAnon(idx) => {
@@ -396,17 +391,6 @@ pub fn enc_existential_bounds<'a,'tcx>(w: &mut Encoder,
396391
mywrite!(w, ".");
397392
}
398393

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-
410394
pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
411395
v: &ty::TypeParameterDef<'tcx>) {
412396
mywrite!(w, "{}:{}|{}|{}|{}|",
@@ -416,6 +400,18 @@ pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
416400
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
417401
}
418402

403+
pub fn enc_region_param_def(w: &mut Encoder, cx: &ctxt,
404+
v: &ty::RegionParameterDef) {
405+
mywrite!(w, "{}:{}|{}|{}|",
406+
v.name, (cx.ds)(v.def_id),
407+
v.space.to_uint(), v.index);
408+
for &r in &v.bounds {
409+
mywrite!(w, "R");
410+
enc_region(w, cx, r);
411+
}
412+
mywrite!(w, ".");
413+
}
414+
419415
fn enc_object_lifetime_default<'a, 'tcx>(w: &mut Encoder,
420416
cx: &ctxt<'a, 'tcx>,
421417
default: ty::ObjectLifetimeDefault)

0 commit comments

Comments
 (0)