Skip to content

Commit 3783ef6

Browse files
Stop returning promotables from mir_const_qualif
1 parent 9e34664 commit 3783ef6

File tree

7 files changed

+16
-66
lines changed

7 files changed

+16
-66
lines changed

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ rustc_queries! {
9393
/// Maps DefId's that have an associated `mir::Body` to the result
9494
/// of the MIR qualify_consts pass. The actual meaning of
9595
/// the value isn't known except to the pass itself.
96-
query mir_const_qualif(key: DefId) -> (u8, &'tcx BitSet<mir::Local>) {
96+
query mir_const_qualif(key: DefId) -> u8 {
9797
desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
9898
cache_on_disk_if { key.is_local() }
9999
}

src/librustc/ty/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use crate::util::common::ErrorReported;
4242
use crate::util::profiling::ProfileCategory::*;
4343

4444
use rustc_data_structures::svh::Svh;
45-
use rustc_index::bit_set::BitSet;
4645
use rustc_index::vec::IndexVec;
4746
use rustc_data_structures::fx::{FxIndexMap, FxHashMap, FxHashSet};
4847
use rustc_data_structures::stable_hasher::StableVec;

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use syntax::parse::parser::emit_unclosed_delims;
3232
use syntax::source_map::Spanned;
3333
use syntax::symbol::Symbol;
3434
use syntax_pos::{Span, FileName};
35-
use rustc_index::bit_set::BitSet;
3635

3736
macro_rules! provide {
3837
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
@@ -122,9 +121,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
122121
}
123122
optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) }
124123
promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) }
125-
mir_const_qualif => {
126-
(cdata.mir_const_qualif(def_id.index), tcx.arena.alloc(BitSet::new_empty(0)))
127-
}
124+
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
128125
fn_sig => { cdata.fn_sig(def_id.index, tcx) }
129126
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
130127
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }

src/librustc_metadata/rmeta/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ impl EncodeContext<'tcx> {
955955
record!(self.per_def.kind[def_id] <- match impl_item.kind {
956956
ty::AssocKind::Const => {
957957
if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
958-
let mir = self.tcx.at(ast_item.span).mir_const_qualif(def_id).0;
958+
let mir = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
959959

960960
EntryKind::AssocConst(container,
961961
ConstQualif { mir },
@@ -1089,7 +1089,7 @@ impl EncodeContext<'tcx> {
10891089
hir::ItemKind::Static(_, hir::MutMutable, _) => EntryKind::MutStatic,
10901090
hir::ItemKind::Static(_, hir::MutImmutable, _) => EntryKind::ImmStatic,
10911091
hir::ItemKind::Const(_, body_id) => {
1092-
let mir = self.tcx.at(item.span).mir_const_qualif(def_id).0;
1092+
let mir = self.tcx.at(item.span).mir_const_qualif(def_id);
10931093
EntryKind::Const(
10941094
ConstQualif { mir },
10951095
self.encode_rendered_const_for_body(body_id)
@@ -1368,7 +1368,7 @@ impl EncodeContext<'tcx> {
13681368
let id = self.tcx.hir().as_local_hir_id(def_id).unwrap();
13691369
let body_id = self.tcx.hir().body_owned_by(id);
13701370
let const_data = self.encode_rendered_const_for_body(body_id);
1371-
let mir = self.tcx.mir_const_qualif(def_id).0;
1371+
let mir = self.tcx.mir_const_qualif(def_id);
13721372

13731373
record!(self.per_def.kind[def_id] <- EntryKind::Const(ConstQualif { mir }, const_data));
13741374
record!(self.per_def.visibility[def_id] <- ty::Visibility::Public);

src/librustc_mir/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait Qualif {
123123
if cx.tcx.trait_of_item(def_id).is_some() {
124124
Self::in_any_value_of_ty(cx, constant.literal.ty)
125125
} else {
126-
let (bits, _) = cx.tcx.at(constant.span).mir_const_qualif(def_id);
126+
let bits = cx.tcx.at(constant.span).mir_const_qualif(def_id);
127127

128128
let qualif = QualifSet(bits).contains::<Self>();
129129

src/librustc_mir/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ impl<'tcx> Validator<'_, 'tcx> {
538538
// is gone - we can always promote constants even if they
539539
// fail to pass const-checking, as compilation would've
540540
// errored independently and promotion can't change that.
541-
let (bits, _) = self.tcx.at(constant.span).mir_const_qualif(def_id);
541+
let bits = self.tcx.at(constant.span).mir_const_qualif(def_id);
542542
if bits == super::qualify_consts::QUALIF_ERROR_BIT {
543543
self.tcx.sess.delay_span_bug(
544544
constant.span,

src/librustc_mir/transform/qualify_consts.rs

+9-55
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ trait Qualif {
258258
if cx.tcx.trait_of_item(def_id).is_some() {
259259
Self::in_any_value_of_ty(cx, constant.literal.ty).unwrap_or(false)
260260
} else {
261-
let (bits, _) = cx.tcx.at(constant.span).mir_const_qualif(def_id);
261+
let bits = cx.tcx.at(constant.span).mir_const_qualif(def_id);
262262

263263
let qualif = PerQualif::decode_from_bits(bits).0[Self::IDX];
264264

@@ -682,7 +682,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
682682
}
683683

684684
/// Check a whole const, static initializer or const fn.
685-
fn check_const(&mut self) -> (u8, &'tcx BitSet<Local>) {
685+
fn check_const(&mut self) -> u8 {
686686
use crate::transform::check_consts as new_checker;
687687

688688
debug!("const-checking {} {:?}", self.mode, self.def_id);
@@ -704,7 +704,6 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
704704

705705
let mut seen_blocks = BitSet::new_empty(body.basic_blocks().len());
706706
let mut bb = START_BLOCK;
707-
let mut has_controlflow_error = false;
708707
loop {
709708
seen_blocks.insert(bb.index());
710709

@@ -745,7 +744,6 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
745744
bb = target;
746745
}
747746
_ => {
748-
has_controlflow_error = true;
749747
self.not_const(ops::Loop);
750748
validator.check_op(ops::Loop);
751749
break;
@@ -772,51 +770,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
772770
}
773771
}
774772

775-
// Collect all the temps we need to promote.
776-
let mut promoted_temps = BitSet::new_empty(self.temp_promotion_state.len());
777-
778-
// HACK: if parts of the control-flow graph were skipped due to an error, don't try to
779-
// promote anything, since that can cause errors in a `const` if e.g. rvalue static
780-
// promotion is attempted within a loop body.
781-
let unleash_miri = self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you;
782-
let promotion_candidates = if has_controlflow_error && !unleash_miri {
783-
self.tcx.sess.delay_span_bug(
784-
body.span,
785-
"check_const: expected control-flow error(s)",
786-
);
787-
788-
vec![]
789-
} else {
790-
promote_consts::validate_candidates(
791-
self.tcx,
792-
self.body,
793-
self.def_id,
794-
&self.temp_promotion_state,
795-
&self.unchecked_promotion_candidates,
796-
)
797-
};
798-
799-
debug!("qualify_const: promotion_candidates={:?}", promotion_candidates);
800-
for candidate in promotion_candidates {
801-
match candidate {
802-
Candidate::Ref(Location { block: bb, statement_index: stmt_idx }) => {
803-
if let StatementKind::Assign(box( _, Rvalue::Ref(_, _, place)))
804-
= &self.body[bb].statements[stmt_idx].kind
805-
{
806-
if let PlaceBase::Local(local) = place.base {
807-
promoted_temps.insert(local);
808-
}
809-
}
810-
}
811-
812-
// Only rvalue-static promotion requires extending the lifetime of the promoted
813-
// local.
814-
Candidate::Argument { .. } | Candidate::Repeat(_) => {}
815-
}
816-
}
817-
818-
let qualifs = self.qualifs_in_local(RETURN_PLACE);
819-
(qualifs.encode_to_bits(), self.tcx.arena.alloc(promoted_temps))
773+
self.qualifs_in_local(RETURN_PLACE).encode_to_bits()
820774
}
821775
}
822776

@@ -1346,7 +1300,7 @@ pub fn provide(providers: &mut Providers<'_>) {
13461300
// in `promote_consts`, see the comment in `validate_operand`.
13471301
pub(super) const QUALIF_ERROR_BIT: u8 = 1 << 2;
13481302

1349-
fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> (u8, &BitSet<Local>) {
1303+
fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
13501304
// N.B., this `borrow()` is guaranteed to be valid (i.e., the value
13511305
// cannot yet be stolen), because `mir_validated()`, which steals
13521306
// from `mir_const(), forces this query to execute before
@@ -1355,7 +1309,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> (u8, &BitSet<Local>) {
13551309

13561310
if body.return_ty().references_error() {
13571311
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");
1358-
return (QUALIF_ERROR_BIT, tcx.arena.alloc(BitSet::new_empty(0)));
1312+
return QUALIF_ERROR_BIT;
13591313
}
13601314

13611315
Checker::new(tcx, def_id, body, Mode::Const).check_const()
@@ -1436,11 +1390,11 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
14361390
} else {
14371391
check_short_circuiting_in_const_local(tcx, body, mode);
14381392

1439-
let promoted_temps = match mode {
1440-
Mode::Const => tcx.mir_const_qualif(def_id).1,
1441-
_ => Checker::new(tcx, def_id, body, mode).check_const().1,
1393+
match mode {
1394+
Mode::Const => tcx.mir_const_qualif(def_id),
1395+
_ => Checker::new(tcx, def_id, body, mode).check_const(),
14421396
};
1443-
remove_drop_and_storage_dead_on_promoted_locals(body, promoted_temps);
1397+
remove_drop_and_storage_dead_on_promoted_locals(body, unimplemented!());
14441398
}
14451399

14461400
if mode == Mode::Static && !tcx.has_attr(def_id, sym::thread_local) {

0 commit comments

Comments
 (0)