Skip to content
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

Rollup of 12 pull requests #35769

Merged
merged 32 commits into from
Aug 18, 2016
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
127489a
Update compiler error 0093 to use new error format
stanislav-tkach Aug 9, 2016
1cf9caf
add mips-uclibc targets
Aug 16, 2016
f0ff2d3
E0403 update error format
circuitfox Aug 17, 2016
34f856e
Update LLVM to include 4 backported commits by @majnemer.
eddyb Aug 17, 2016
4254b31
Update minimum CMake version in README
spladug Aug 17, 2016
7675e4b
Update E0009 to new format
Aug 17, 2016
12a159a
Add 'make help' for rustbuild
SimonSapin Aug 17, 2016
feeed0b
Fixes issue #11004
GuillaumeGomez Aug 17, 2016
d01bfb1
Remove trailing white space
Aug 17, 2016
6a1efbd
Merge branch 'master' into E0403-update-error-format
circuitfox Aug 17, 2016
2179def
New output for E0407
tvladyslav Aug 16, 2016
2d36642
Properly invalidate the early exit cache
nagisa Aug 17, 2016
2c3250a
Nice graphs
nagisa Aug 17, 2016
8d78237
Add new error code tests
GuillaumeGomez Aug 17, 2016
de5aaee
Updated test for E0221
tvladyslav Aug 17, 2016
3c4ecc9
Display secondary span for E0053 for Sort TypeErrors
KiChjang Aug 10, 2016
34bc3c9
Display secondary span for E0053 for Mutability TypeErrors
KiChjang Aug 17, 2016
31d56cb
Add UI test for E0053
KiChjang Aug 17, 2016
ed54226
Fix tidy check.
tvladyslav Aug 17, 2016
612506b
Rollup merge of #35346 - DarkEld3r:e0093-formatting, r=jonathandturner
eddyb Aug 18, 2016
5e9a5b3
Rollup merge of #35734 - japaric:mips-uclibc, r=alexcrichton
eddyb Aug 18, 2016
71759ec
Rollup merge of #35739 - circuitfox:E0403-update-error-format, r=jona…
eddyb Aug 18, 2016
99e5efd
Rollup merge of #35740 - eddyb:llvm-prl-fix, r=alexcrichton
eddyb Aug 18, 2016
7a27444
Rollup merge of #35742 - spladug:readme-cmake-version, r=nikomatsakis
eddyb Aug 18, 2016
394c449
Rollup merge of #35744 - DevShep:ds/update_E0009, r=jonathandturner
eddyb Aug 18, 2016
f1861b8
Rollup merge of #35749 - GuillaumeGomez:raw_field, r=jonathandturner
eddyb Aug 18, 2016
1e13de8
Rollup merge of #35750 - SimonSapin:help, r=alexcrichton
eddyb Aug 18, 2016
64c1aef
Rollup merge of #35751 - nagisa:mir-scope-fix-again, r=eddyb
eddyb Aug 18, 2016
c3601d4
Rollup merge of #35756 - crypto-universe:E0407, r=GuillaumeGomez
eddyb Aug 18, 2016
8ccc11b
Rollup merge of #35765 - KiChjang:e0053-bonus, r=jonathandturner
eddyb Aug 18, 2016
d36b296
Rollup merge of #35768 - GuillaumeGomez:err_codes, r=jonathandturner
eddyb Aug 18, 2016
d69cd72
Rollup merge of #35770 - crypto-universe:E0221, r=jonathandturner
eddyb Aug 18, 2016
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
Prev Previous commit
Next Next commit
Properly invalidate the early exit cache
Fixes #35737
  • Loading branch information
nagisa committed Aug 17, 2016
commit 2d366428cc50d1f20c139ffc854a603de1c1470c
43 changes: 23 additions & 20 deletions src/librustc_mir/build/scope.rs
Original file line number Diff line number Diff line change
@@ -198,8 +198,11 @@ impl<'tcx> Scope<'tcx> {
///
/// Should always be run for all inner scopes when a drop is pushed into some scope enclosing a
/// larger extent of code.
fn invalidate_cache(&mut self) {
self.cached_exits = FnvHashMap();
///
/// `unwind` controls whether caches for the unwind branch are also invalidated.
fn invalidate_cache(&mut self, unwind: bool) {
self.cached_exits.clear();
if !unwind { return; }
for dropdata in &mut self.drops {
if let DropKind::Value { ref mut cached_block } = dropdata.kind {
*cached_block = None;
@@ -455,25 +458,29 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
};

for scope in self.scopes.iter_mut().rev() {
if scope.extent == extent {
let this_scope = scope.extent == extent;
// We must invalidate all the caches leading up to the scope we’re looking for, because
// the cached blocks will branch into build of scope not containing the new drop. If we
// add stuff to the currently inspected scope, then in some cases the non-unwind caches
// may become invalid, therefore we should invalidate these as well. The unwind caches
// will stay correct, because the already generated unwind blocks cannot be influenced
// by just added drop.
//
// If we’re scheduling cleanup for non-droppable type (i.e. DropKind::Storage), then we
// do not need to invalidate unwind branch, because DropKind::Storage does not end up
// built in the unwind branch currently.
let invalidate_unwind = needs_drop && !this_scope;
scope.invalidate_cache(invalidate_unwind);
if this_scope {
if let DropKind::Value { .. } = drop_kind {
scope.needs_cleanup = true;
}

// No need to invalidate any caches here. The just-scheduled drop will branch into
// the drop that comes before it in the vector.
scope.drops.push(DropData {
span: span,
location: lvalue.clone(),
kind: drop_kind
});
return;
} else {
// We must invalidate all the cached_blocks leading up to the scope we’re
// looking for, because all of the blocks in the chain will become incorrect.
if let DropKind::Value { .. } = drop_kind {
scope.invalidate_cache()
}
}
}
span_bug!(span, "extent {:?} not in scope to drop {:?}", extent, lvalue);
@@ -490,11 +497,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
value: &Lvalue<'tcx>,
item_ty: Ty<'tcx>) {
for scope in self.scopes.iter_mut().rev() {
// We must invalidate all the caches leading up to and including the scope we’re
// looking for, because otherwise some of the blocks in the chain will become
// incorrect and must be rebuilt.
scope.invalidate_cache(true);
if scope.extent == extent {
assert!(scope.free.is_none(), "scope already has a scheduled free!");
// We also must invalidate the caches in the scope for which the free is scheduled
// because the drops must branch into the free we schedule here.
scope.invalidate_cache();
scope.needs_cleanup = true;
scope.free = Some(FreeData {
span: span,
@@ -503,11 +511,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
cached_block: None
});
return;
} else {
// We must invalidate all the cached_blocks leading up to the scope we’re looking
// for, because otherwise some/most of the blocks in the chain will become
// incorrect.
scope.invalidate_cache();
}
}
span_bug!(span, "extent {:?} not in scope to free {:?}", extent, value);
37 changes: 37 additions & 0 deletions src/test/run-pass/mir_early_return_scope.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

static mut DROP: bool = false;

struct ConnWrap(Conn);
impl ::std::ops::Deref for ConnWrap {
type Target=Conn;
fn deref(&self) -> &Conn { &self.0 }
}

struct Conn;
impl Drop for Conn {
fn drop(&mut self) { unsafe { DROP = true; } }
}

fn inner() {
let conn = &*match Some(ConnWrap(Conn)) {
Some(val) => val,
None => return,
};
return;
}

fn main() {
inner();
unsafe {
assert_eq!(DROP, true);
}
}