Skip to content

Commit 612ca14

Browse files
committed
Auto merge of #50593 - nikomatsakis:nll-no-location, r=nikomatsakis
stop considering location when computing outlives relationships This doesn't (yet?) use SEME regions, but it does ignore the location for outlives constraints. This makes (I believe) NLL significantly faster -- but we should do some benchmarks. It regresses the "get-default" family of use cases for NLL, which is a shame, but keeps the other benefits, and thus represents a decent step forward. r? @pnkfelix
2 parents 90463a6 + a64ef13 commit 612ca14

File tree

12 files changed

+279
-569
lines changed

12 files changed

+279
-569
lines changed

src/librustc_data_structures/bitvec.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::collections::BTreeMap;
11+
use indexed_vec::{Idx, IndexVec};
1212
use std::collections::btree_map::Entry;
13-
use std::marker::PhantomData;
13+
use std::collections::BTreeMap;
1414
use std::iter::FromIterator;
15-
use indexed_vec::{Idx, IndexVec};
15+
use std::marker::PhantomData;
1616

1717
type Word = u128;
1818
const WORD_BITS: usize = 128;
@@ -317,14 +317,25 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
317317
if read != write {
318318
let (bit_set_read, bit_set_write) = self.vector.pick2_mut(read, write);
319319

320-
for read_val in bit_set_read.iter() {
321-
changed = changed | bit_set_write.insert(read_val);
320+
for read_chunk in bit_set_read.chunks() {
321+
changed = changed | bit_set_write.insert_chunk(read_chunk).any();
322322
}
323323
}
324324

325325
changed
326326
}
327327

328+
/// True if `sub` is a subset of `sup`
329+
pub fn is_subset(&self, sub: R, sup: R) -> bool {
330+
sub == sup || {
331+
let bit_set_sub = &self.vector[sub];
332+
let bit_set_sup = &self.vector[sup];
333+
bit_set_sub
334+
.chunks()
335+
.all(|read_chunk| read_chunk.bits_eq(bit_set_sup.contains_chunk(read_chunk)))
336+
}
337+
}
338+
328339
/// Iterates through all the columns set to true in a given row of
329340
/// the matrix.
330341
pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a {
@@ -346,6 +357,7 @@ pub struct SparseChunk<I> {
346357
}
347358

348359
impl<I: Idx> SparseChunk<I> {
360+
#[inline]
349361
pub fn one(index: I) -> Self {
350362
let index = index.index();
351363
let key_usize = index / 128;
@@ -358,10 +370,16 @@ impl<I: Idx> SparseChunk<I> {
358370
}
359371
}
360372

373+
#[inline]
361374
pub fn any(&self) -> bool {
362375
self.bits != 0
363376
}
364377

378+
#[inline]
379+
pub fn bits_eq(&self, other: SparseChunk<I>) -> bool {
380+
self.bits == other.bits
381+
}
382+
365383
pub fn iter(&self) -> impl Iterator<Item = I> {
366384
let base = self.key as usize * 128;
367385
let mut bits = self.bits;
@@ -394,6 +412,10 @@ impl<I: Idx> SparseBitSet<I> {
394412
self.chunk_bits.len() * 128
395413
}
396414

415+
/// Returns a chunk containing only those bits that are already
416+
/// present. You can test therefore if `self` contains all the
417+
/// bits in chunk already by doing `chunk ==
418+
/// self.contains_chunk(chunk)`.
397419
pub fn contains_chunk(&self, chunk: SparseChunk<I>) -> SparseChunk<I> {
398420
SparseChunk {
399421
bits: self.chunk_bits
@@ -403,6 +425,11 @@ impl<I: Idx> SparseBitSet<I> {
403425
}
404426
}
405427

428+
/// Modifies `self` to contain all the bits from `chunk` (in
429+
/// addition to any pre-existing bits); returns a new chunk that
430+
/// contains only those bits that were newly added. You can test
431+
/// if anything was inserted by invoking `any()` on the returned
432+
/// value.
406433
pub fn insert_chunk(&mut self, chunk: SparseChunk<I>) -> SparseChunk<I> {
407434
if chunk.bits == 0 {
408435
return chunk;

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! This query borrow-checks the MIR to (further) ensure it is not broken.
1212
13-
use borrow_check::nll::region_infer::{RegionCausalInfo, RegionInferenceContext};
13+
use borrow_check::nll::region_infer::RegionInferenceContext;
1414
use rustc::hir;
1515
use rustc::hir::def_id::DefId;
1616
use rustc::hir::map::definitions::DefPathData;
@@ -248,7 +248,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
248248
nonlexical_regioncx: regioncx,
249249
used_mut: FxHashSet(),
250250
used_mut_upvars: SmallVec::new(),
251-
nonlexical_cause_info: None,
252251
borrow_set,
253252
dominators,
254253
};
@@ -367,7 +366,6 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
367366
/// contains the results from region inference and lets us e.g.
368367
/// find out which CFG points are contained in each borrow region.
369368
nonlexical_regioncx: Rc<RegionInferenceContext<'tcx>>,
370-
nonlexical_cause_info: Option<RegionCausalInfo>,
371369

372370
/// The set of borrows extracted from the MIR
373371
borrow_set: Rc<BorrowSet<'tcx>>,

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
3232
let regioncx = &&self.nonlexical_regioncx;
3333
let mir = self.mir;
3434

35-
if self.nonlexical_cause_info.is_none() {
36-
self.nonlexical_cause_info = Some(regioncx.compute_causal_info(mir));
37-
}
38-
39-
let cause_info = self.nonlexical_cause_info.as_ref().unwrap();
40-
if let Some(cause) = cause_info.why_region_contains_point(borrow.region, context.loc) {
41-
match *cause.root_cause() {
35+
let borrow_region_vid = regioncx.to_region_vid(borrow.region);
36+
if let Some(cause) = regioncx.why_region_contains_point(borrow_region_vid, context.loc) {
37+
match cause {
4238
Cause::LiveVar(local, location) => {
4339
match find_regular_use(mir, regioncx, borrow, location, local) {
4440
Some(p) => {

src/librustc_mir/borrow_check/nll/region_infer/dfs.rs

Lines changed: 0 additions & 265 deletions
This file was deleted.

0 commit comments

Comments
 (0)