Skip to content

Commit 60a052f

Browse files
committed
Handle MIR in a single place.
1 parent b94d421 commit 60a052f

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -1162,15 +1162,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11621162
if should_encode_type(tcx, local_id, def_kind) {
11631163
record!(self.tables.type_of[def_id] <- self.tcx.type_of(def_id));
11641164
}
1165-
if should_encode_const(def_kind) && tcx.is_mir_available(def_id) {
1166-
let qualifs = tcx.at(def_span).mir_const_qualif(def_id);
1167-
record!(self.tables.mir_const_qualif[def_id] <- qualifs);
1168-
let body_id = tcx.hir().maybe_body_owned_by(local_id);
1169-
if let Some(body_id) = body_id {
1170-
let const_data = self.encode_rendered_const_for_body(body_id);
1171-
record!(self.tables.rendered_const[def_id] <- const_data);
1172-
}
1173-
}
11741165
if let DefKind::TyParam | DefKind::ConstParam = def_kind {
11751166
if let Some(default) = self.tcx.object_lifetime_default(def_id) {
11761167
record!(self.tables.object_lifetime_default[def_id] <- default);
@@ -1385,12 +1376,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13851376
return;
13861377
}
13871378

1388-
let keys_and_jobs = self
1389-
.tcx
1379+
let tcx = self.tcx;
1380+
1381+
let keys_and_jobs = tcx
13901382
.mir_keys(())
13911383
.iter()
13921384
.filter_map(|&def_id| {
1393-
let (encode_const, encode_opt) = should_encode_mir(self.tcx, def_id);
1385+
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
13941386
if encode_const || encode_opt {
13951387
Some((def_id, encode_const, encode_opt))
13961388
} else {
@@ -1403,22 +1395,32 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14031395

14041396
debug!("EntryBuilder::encode_mir({:?})", def_id);
14051397
if encode_opt {
1406-
record!(self.tables.optimized_mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
1398+
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
14071399
}
14081400
if encode_const {
1409-
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));
1401+
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id));
14101402

14111403
// FIXME(generic_const_exprs): this feels wrong to have in `encode_mir`
1412-
let abstract_const = self.tcx.thir_abstract_const(def_id);
1404+
let abstract_const = tcx.thir_abstract_const(def_id);
14131405
if let Ok(Some(abstract_const)) = abstract_const {
14141406
record!(self.tables.thir_abstract_const[def_id.to_def_id()] <- abstract_const);
14151407
}
1408+
1409+
if should_encode_const(tcx.def_kind(def_id)) {
1410+
let qualifs = tcx.mir_const_qualif(def_id);
1411+
record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
1412+
let body_id = tcx.hir().maybe_body_owned_by(def_id);
1413+
if let Some(body_id) = body_id {
1414+
let const_data = self.encode_rendered_const_for_body(body_id);
1415+
record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
1416+
}
1417+
}
14161418
}
1417-
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
1419+
record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
14181420

14191421
let instance =
14201422
ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id()));
1421-
let unused = self.tcx.unused_generic_params(instance);
1423+
let unused = tcx.unused_generic_params(instance);
14221424
if !unused.is_empty() {
14231425
record!(self.tables.unused_generic_params[def_id.to_def_id()] <- unused);
14241426
}

0 commit comments

Comments
 (0)