Skip to content

Commit afc00b0

Browse files
committed
rustc_const_eval: demand that the MIR qualify_consts ran on each evaluated body.
1 parent 2029c71 commit afc00b0

File tree

13 files changed

+148
-112
lines changed

13 files changed

+148
-112
lines changed

src/librustc/ty/maps.rs

+5
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ define_maps! { <'tcx>
361361
/// (in the `RefCell` sense) to prevent accidental mutation.
362362
pub mir: Mir(DefId) -> &'tcx RefCell<mir::Mir<'tcx>>,
363363

364+
/// Maps DefId's that have an associated Mir to the result
365+
/// of the MIR qualify_consts pass. The actual meaning of
366+
/// the value isn't known except to the pass itself.
367+
pub mir_const_qualif: Mir(DefId) -> u8,
368+
364369
/// Records the type of each closure. The def ID is the ID of the
365370
/// expression defining the closure.
366371
pub closure_kind: ItemSignature(DefId) -> ty::ClosureKind,

src/librustc_const_eval/eval.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::util::nodemap::DefIdMap;
2727
use graphviz::IntoCow;
2828
use syntax::ast;
2929
use rustc::hir::{self, Expr};
30-
use syntax_pos::Span;
30+
use syntax_pos::{Span, DUMMY_SP};
3131

3232
use std::borrow::Cow;
3333
use std::cmp::Ordering;
@@ -228,6 +228,7 @@ pub struct ConstContext<'a, 'tcx: 'a> {
228228
impl<'a, 'tcx> ConstContext<'a, 'tcx> {
229229
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, body: hir::BodyId) -> Self {
230230
let def_id = tcx.hir.body_owner_def_id(body);
231+
ty::queries::mir_const_qualif::get(tcx, DUMMY_SP, def_id);
231232
ConstContext::with_tables(tcx, tcx.item_tables(def_id))
232233
}
233234

src/librustc_driver/driver.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
872872
let index = stability::Index::new(&hir_map);
873873

874874
let mut local_providers = ty::maps::Providers::default();
875-
mir::mir_map::provide(&mut local_providers);
875+
mir::provide(&mut local_providers);
876876
typeck::provide(&mut local_providers);
877877

878878
let mut extern_providers = ty::maps::Providers::default();
@@ -958,8 +958,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
958958
// in stage 4 below.
959959
passes.push_hook(box mir::transform::dump_mir::DumpMir);
960960
passes.push_pass(box mir::transform::simplify::SimplifyCfg::new("initial"));
961-
passes.push_pass(
962-
box mir::transform::qualify_consts::QualifyAndPromoteConstants::default());
961+
passes.push_pass(box mir::transform::qualify_consts::QualifyAndPromoteConstants);
963962
passes.push_pass(box mir::transform::type_check::TypeckMir);
964963
passes.push_pass(
965964
box mir::transform::simplify_branches::SimplifyBranches::new("initial"));

src/librustc_metadata/cstore_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ provide! { <'tcx> tcx, def_id, cdata
101101

102102
mir
103103
}
104+
mir_const_qualif => { cdata.mir_const_qualif(def_id.index) }
104105
typeck_tables => { cdata.item_body_tables(def_id.index, tcx) }
105106
closure_kind => { cdata.closure_kind(def_id.index) }
106107
closure_type => { cdata.closure_ty(def_id.index, tcx) }

src/librustc_metadata/decoder.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ impl<'a, 'tcx> MetadataBlob {
411411
impl<'tcx> EntryKind<'tcx> {
412412
fn to_def(&self, did: DefId) -> Option<Def> {
413413
Some(match *self {
414-
EntryKind::Const => Def::Const(did),
415-
EntryKind::AssociatedConst(_) => Def::AssociatedConst(did),
414+
EntryKind::Const(_) => Def::Const(did),
415+
EntryKind::AssociatedConst(..) => Def::AssociatedConst(did),
416416
EntryKind::ImmStatic |
417417
EntryKind::ForeignImmStatic => Def::Static(did, false),
418418
EntryKind::MutStatic |
@@ -825,14 +825,25 @@ impl<'a, 'tcx> CrateMetadata {
825825
}
826826
}
827827

828+
pub fn mir_const_qualif(&self, id: DefIndex) -> u8 {
829+
match self.entry(id).kind {
830+
EntryKind::Const(qualif) |
831+
EntryKind::AssociatedConst(AssociatedContainer::ImplDefault, qualif) |
832+
EntryKind::AssociatedConst(AssociatedContainer::ImplFinal, qualif) => {
833+
qualif
834+
}
835+
_ => bug!(),
836+
}
837+
}
838+
828839
pub fn get_associated_item(&self, id: DefIndex) -> ty::AssociatedItem {
829840
let item = self.entry(id);
830841
let def_key = self.def_key(id);
831842
let parent = self.local_def_id(def_key.parent.unwrap());
832843
let name = def_key.disambiguated_data.data.get_opt_name().unwrap();
833844

834845
let (kind, container, has_self) = match item.kind {
835-
EntryKind::AssociatedConst(container) => {
846+
EntryKind::AssociatedConst(container, _) => {
836847
(ty::AssociatedKind::Const, container, false)
837848
}
838849
EntryKind::Method(data) => {

src/librustc_metadata/encoder.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
457457
};
458458

459459
let kind = match trait_item.kind {
460-
ty::AssociatedKind::Const => EntryKind::AssociatedConst(container),
460+
ty::AssociatedKind::Const => {
461+
EntryKind::AssociatedConst(container, 0)
462+
}
461463
ty::AssociatedKind::Method => {
462464
let fn_data = if let hir::TraitItemKind::Method(_, ref m) = ast_item.node {
463465
let arg_names = match *m {
@@ -533,7 +535,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
533535
};
534536

535537
let kind = match impl_item.kind {
536-
ty::AssociatedKind::Const => EntryKind::AssociatedConst(container),
538+
ty::AssociatedKind::Const => {
539+
EntryKind::AssociatedConst(container,
540+
ty::queries::mir_const_qualif::get(self.tcx, ast_item.span, def_id))
541+
}
537542
ty::AssociatedKind::Method => {
538543
let fn_data = if let hir::ImplItemKind::Method(ref sig, body) = ast_item.node {
539544
FnData {
@@ -637,7 +642,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
637642
let kind = match item.node {
638643
hir::ItemStatic(_, hir::MutMutable, _) => EntryKind::MutStatic,
639644
hir::ItemStatic(_, hir::MutImmutable, _) => EntryKind::ImmStatic,
640-
hir::ItemConst(..) => EntryKind::Const,
645+
hir::ItemConst(..) => {
646+
EntryKind::Const(ty::queries::mir_const_qualif::get(tcx, item.span, def_id))
647+
}
641648
hir::ItemFn(_, _, constness, .., body) => {
642649
let data = FnData {
643650
constness: constness,

src/librustc_metadata/schema.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub struct Entry<'tcx> {
221221

222222
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
223223
pub enum EntryKind<'tcx> {
224-
Const,
224+
Const(u8),
225225
ImmStatic,
226226
MutStatic,
227227
ForeignImmStatic,
@@ -243,7 +243,7 @@ pub enum EntryKind<'tcx> {
243243
DefaultImpl(Lazy<ImplData<'tcx>>),
244244
Method(Lazy<MethodData>),
245245
AssociatedType(AssociatedContainer),
246-
AssociatedConst(AssociatedContainer),
246+
AssociatedConst(AssociatedContainer, u8),
247247
}
248248

249249
#[derive(RustcEncodable, RustcDecodable)]

src/librustc_mir/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,9 @@ pub mod mir_map;
5353
pub mod pretty;
5454
pub mod transform;
5555

56+
use rustc::ty::maps::Providers;
57+
58+
pub fn provide(providers: &mut Providers) {
59+
mir_map::provide(providers);
60+
transform::qualify_consts::provide(providers);
61+
}

0 commit comments

Comments
 (0)