Skip to content

Commit 4de31b2

Browse files
committed
Fix remaining compilation issues
1 parent fc6b58d commit 4de31b2

File tree

20 files changed

+102
-50
lines changed

20 files changed

+102
-50
lines changed

src/librustc/mir/cache.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ impl BodyCache<'tcx> {
151151
}
152152
}
153153

154+
#[macro_export]
155+
macro_rules! read_only {
156+
($body_cache:expr) => {
157+
{
158+
$body_cache.ensure_predecessors();
159+
$body_cache.unwrap_read_only()
160+
}
161+
};
162+
}
163+
154164
impl BodyCache<'tcx> {
155165
pub fn ensure_predecessors(&mut self) {
156166
self.cache.ensure_predecessors(&self.body);
@@ -160,12 +170,8 @@ impl BodyCache<'tcx> {
160170
self.cache.predecessors(&self.body)
161171
}
162172

163-
pub fn read_only(&self) -> ReadOnlyBodyCache<'_, '_> {
164-
assert!(self.cache.predecessors.is_some(), "");
165-
ReadOnlyBodyCache {
166-
cache: &self.cache,
167-
body: &self.body,
168-
}
173+
pub fn unwrap_read_only(&self) -> ReadOnlyBodyCache<'_, 'tcx> {
174+
ReadOnlyBodyCache::new(&self.cache, &self.body)
169175
}
170176

171177
pub fn body(&self) -> &Body<'tcx> {
@@ -176,6 +182,8 @@ impl BodyCache<'tcx> {
176182
&mut self.body
177183
}
178184

185+
pub fn cache(&self) -> &Cache { &self.cache }
186+
179187
pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
180188
self.cache.basic_blocks_mut(&mut self.body)
181189
}
@@ -223,6 +231,24 @@ pub struct ReadOnlyBodyCache<'a, 'tcx> {
223231
}
224232

225233
impl ReadOnlyBodyCache<'a, 'tcx> {
234+
fn new(cache: &'a Cache, body: &'a Body<'tcx>) -> Self {
235+
assert!(
236+
cache.predecessors.is_some(),
237+
"Cannot construct ReadOnlyBodyCache without computed predecessors");
238+
Self {
239+
cache,
240+
body,
241+
}
242+
}
243+
244+
pub fn from_external_cache(cache: &'a mut Cache, body: &'a Body<'tcx>) -> Self {
245+
cache.ensure_predecessors(body);
246+
Self {
247+
cache,
248+
body,
249+
}
250+
}
251+
226252
#[inline]
227253
pub fn predecessors(&self) -> &IndexVec<BasicBlock, Vec<BasicBlock>> {
228254
self.cache.predecessors.as_ref().unwrap()

src/librustc/mir/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ use syntax::symbol::Symbol;
3838
use syntax_pos::{Span, DUMMY_SP};
3939

4040
pub use crate::mir::interpret::AssertMessage;
41-
pub use crate::mir::cache::{BodyCache, ReadOnlyBodyCache};
41+
// TODO(nashenas88) Cache only exported for use in librustc_mir/transform/check_unsafety.rs
42+
pub use crate::mir::cache::{BodyCache, Cache, ReadOnlyBodyCache};
43+
pub use crate::read_only;
4244

4345
pub mod cache;
4446
pub mod interpret;

src/librustc/query/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ rustc_queries! {
147147
crate::mir::Promoted,
148148
crate::mir::BodyCache<'tcx>
149149
>> = tcx.queries.on_disk_cache.try_load_query_result(tcx, id);
150-
promoted.map(|p| &*tcx.arena.alloc(p))
150+
promoted.map(|p| {
151+
let cache = tcx.arena.alloc(p);
152+
for body_cache in cache.iter_mut() {
153+
body_cache.ensure_predecessors();
154+
}
155+
&*cache
156+
})
151157
}
152158
}
153159
}

src/librustc/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,7 +2988,7 @@ impl<'tcx> TyCtxt<'tcx> {
29882988
pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> ReadOnlyBodyCache<'tcx, 'tcx> {
29892989
match instance {
29902990
ty::InstanceDef::Item(did) => {
2991-
self.optimized_mir(did).read_only()
2991+
self.optimized_mir(did).unwrap_read_only()
29922992
}
29932993
ty::InstanceDef::VtableShim(..) |
29942994
ty::InstanceDef::ReifyShim(..) |
@@ -2998,7 +2998,7 @@ impl<'tcx> TyCtxt<'tcx> {
29982998
ty::InstanceDef::ClosureOnceShim { .. } |
29992999
ty::InstanceDef::DropGlue(..) |
30003000
ty::InstanceDef::CloneShim(..) => {
3001-
self.mir_shims(instance).read_only()
3001+
self.mir_shims(instance).unwrap_read_only()
30023002
}
30033003
}
30043004
}

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,25 +1080,31 @@ impl<'a, 'tcx> CrateMetadata {
10801080
}
10811081

10821082
fn get_optimized_mir(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> BodyCache<'tcx> {
1083-
self.root.per_def.mir.get(self, id)
1083+
let mut cache = self.root.per_def.mir.get(self, id)
10841084
.filter(|_| !self.is_proc_macro(id))
10851085
.unwrap_or_else(|| {
10861086
bug!("get_optimized_mir: missing MIR for `{:?}`", self.local_def_id(id))
10871087
})
1088-
.decode((self, tcx))
1088+
.decode((self, tcx));
1089+
cache.ensure_predecessors();
1090+
cache
10891091
}
10901092

10911093
fn get_promoted_mir(
10921094
&self,
10931095
tcx: TyCtxt<'tcx>,
10941096
id: DefIndex,
10951097
) -> IndexVec<Promoted, BodyCache<'tcx>> {
1096-
self.root.per_def.promoted_mir.get(self, id)
1098+
let mut cache = self.root.per_def.promoted_mir.get(self, id)
10971099
.filter(|_| !self.is_proc_macro(id))
10981100
.unwrap_or_else(|| {
10991101
bug!("get_promoted_mir: missing MIR for `{:?}`", self.local_def_id(id))
11001102
})
1101-
.decode((self, tcx))
1103+
.decode((self, tcx));
1104+
for body_cache in cache.iter_mut() {
1105+
body_cache.ensure_predecessors();
1106+
}
1107+
cache
11021108
}
11031109

11041110
fn mir_const_qualif(&self, id: DefIndex) -> mir::ConstQualifs {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT};
1010
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
1111
use rustc::mir::{
1212
ClearCrossCrate, Local, Location, Body, BodyCache, Mutability, Operand, Place, PlaceBase,
13-
PlaceElem, PlaceRef, ReadOnlyBodyCache, Static, StaticKind
13+
PlaceElem, PlaceRef, ReadOnlyBodyCache, Static, StaticKind, read_only
1414
};
1515
use rustc::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind};
1616
use rustc::mir::{Terminator, TerminatorKind};
@@ -167,8 +167,8 @@ fn do_mir_borrowck<'a, 'tcx>(
167167
let mut body_cache = BodyCache::new(body);
168168
let free_regions =
169169
nll::replace_regions_in_mir(infcx, def_id, param_env, &mut body_cache, &mut promoted);
170-
let body_cache = body_cache.read_only(); // no further changes
171-
let promoted: IndexVec<_, _> = promoted.iter().map(|body_cache| body_cache.read_only()).collect();
170+
let body_cache = read_only!(body_cache); // no further changes
171+
let promoted: IndexVec<_, _> = promoted.iter_mut().map(|body_cache| read_only!(body_cache)).collect();
172172

173173
let location_table = &LocationTable::new(&body_cache);
174174

@@ -492,7 +492,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx
492492
type FlowState = Flows<'cx, 'tcx>;
493493

494494
fn body(&self) -> &'cx Body<'tcx> {
495-
&self.body_cache
495+
self.body_cache.body()
496496
}
497497

498498
fn visit_block_entry(&mut self, bb: BasicBlock, flow_state: &Self::FlowState) {

src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
302302
}
303303
}
304304

305-
for &pred_block in self.cx.body_cache.predecessors_for(block).iter() {
305+
let body_cache = self.cx.body_cache;
306+
for &pred_block in body_cache.predecessors_for(block).iter() {
306307
debug!("compute_drop_live_points_for_block: pred_block = {:?}", pred_block,);
307308

308309
// Check whether the variable is (at least partially)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
540540
// checker on the promoted MIR, then transfer the constraints back to
541541
// the main MIR, changing the locations to the provided location.
542542

543-
let parent_body = mem::replace(&mut self.body, &promoted_body_cache);
543+
let parent_body = mem::replace(&mut self.body, promoted_body_cache.body());
544544

545545
// Use new sets of constraints and closure bounds so that we can
546546
// modify their locations.

src/librustc_mir/borrow_check/prefixes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
5656
Prefixes {
5757
next: Some(place_ref),
5858
kind,
59-
body: &self.body_cache,
59+
body: self.body_cache.body(),
6060
tcx: self.infcx.tcx,
6161
}
6262
}

src/librustc_mir/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
303303
}
304304
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
305305
if let Some(promoted) = promoted {
306-
return Ok(self.tcx.promoted_mir(did)[promoted].read_only());
306+
return Ok(self.tcx.promoted_mir(did)[promoted].unwrap_read_only());
307307
}
308308
match instance {
309309
ty::InstanceDef::Item(def_id) => if self.tcx.is_mir_available(did) {
310-
Ok(self.tcx.optimized_mir(did).read_only())
310+
Ok(self.tcx.optimized_mir(did).unwrap_read_only())
311311
} else {
312312
throw_unsup!(NoMirFor(self.tcx.def_path_str(def_id)))
313313
},

0 commit comments

Comments
 (0)