Skip to content

Commit 455945f

Browse files
committed
Remove HIR based const qualification
1 parent 22bc9e1 commit 455945f

File tree

19 files changed

+66
-916
lines changed

19 files changed

+66
-916
lines changed

src/librustc/middle/expr_use_visitor.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::ty::{self, DefIdTree, TyCtxt, adjustment};
2020
use crate::hir::{self, PatKind};
2121
use std::rc::Rc;
2222
use syntax_pos::Span;
23-
use crate::util::nodemap::ItemLocalSet;
2423

2524
///////////////////////////////////////////////////////////////////////////
2625
// The Delegate trait
@@ -261,9 +260,6 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
261260
/// - `param_env` --- parameter environment for trait lookups (esp. pertaining to `Copy`)
262261
/// - `region_scope_tree` --- region scope tree for the code being analyzed
263262
/// - `tables` --- typeck results for the code being analyzed
264-
/// - `rvalue_promotable_map` --- if you care about rvalue promotion, then provide
265-
/// the map here (it can be computed with `tcx.rvalue_promotable_map(def_id)`).
266-
/// `None` means that rvalues will be given more conservative lifetimes.
267263
///
268264
/// See also `with_infer`, which is used *during* typeck.
269265
pub fn new(
@@ -273,15 +269,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
273269
param_env: ty::ParamEnv<'tcx>,
274270
region_scope_tree: &'a region::ScopeTree,
275271
tables: &'a ty::TypeckTables<'tcx>,
276-
rvalue_promotable_map: Option<&'tcx ItemLocalSet>,
277272
) -> Self {
278273
ExprUseVisitor {
279274
mc: mc::MemCategorizationContext::new(tcx,
280275
param_env,
281276
body_owner,
282277
region_scope_tree,
283-
tables,
284-
rvalue_promotable_map),
278+
tables),
285279
delegate,
286280
param_env,
287281
}
@@ -317,16 +311,9 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
317311
let param_ty = return_if_err!(self.mc.pat_ty_adjusted(&param.pat));
318312
debug!("consume_body: param_ty = {:?}", param_ty);
319313

320-
let fn_body_scope_r =
321-
self.tcx().mk_region(ty::ReScope(
322-
region::Scope {
323-
id: body.value.hir_id.local_id,
324-
data: region::ScopeData::Node
325-
}));
326314
let param_cmt = Rc::new(self.mc.cat_rvalue(
327315
param.hir_id,
328316
param.pat.span,
329-
fn_body_scope_r, // Parameters live only as long as the fn body.
330317
param_ty));
331318

332319
self.walk_irrefutable_pat(param_cmt, &param.pat);

src/librustc/middle/mem_categorization.rs

+11-55
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ use std::fmt;
7979
use std::hash::{Hash, Hasher};
8080
use rustc_data_structures::fx::FxIndexMap;
8181
use std::rc::Rc;
82-
use crate::util::nodemap::ItemLocalSet;
8382

8483
#[derive(Clone, Debug, PartialEq)]
8584
pub enum Categorization<'tcx> {
86-
Rvalue(ty::Region<'tcx>), // temporary val, argument is its scope
87-
ThreadLocal(ty::Region<'tcx>), // value that cannot move, but still restricted in scope
85+
Rvalue, // temporary val
86+
ThreadLocal, // value that cannot move, but still restricted in scope
8887
StaticItem,
8988
Upvar(Upvar), // upvar referenced by closure env
9089
Local(hir::HirId), // local variable
@@ -219,7 +218,6 @@ pub struct MemCategorizationContext<'a, 'tcx> {
219218
pub upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
220219
pub region_scope_tree: &'a region::ScopeTree,
221220
pub tables: &'a ty::TypeckTables<'tcx>,
222-
rvalue_promotable_map: Option<&'tcx ItemLocalSet>,
223221
infcx: Option<&'a InferCtxt<'a, 'tcx>>,
224222
}
225223

@@ -335,15 +333,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
335333
body_owner: DefId,
336334
region_scope_tree: &'a region::ScopeTree,
337335
tables: &'a ty::TypeckTables<'tcx>,
338-
rvalue_promotable_map: Option<&'tcx ItemLocalSet>,
339336
) -> MemCategorizationContext<'a, 'tcx> {
340337
MemCategorizationContext {
341338
tcx,
342339
body_owner,
343340
upvars: tcx.upvars(body_owner),
344341
region_scope_tree,
345342
tables,
346-
rvalue_promotable_map,
347343
infcx: None,
348344
param_env,
349345
}
@@ -369,19 +365,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
369365
) -> MemCategorizationContext<'a, 'tcx> {
370366
let tcx = infcx.tcx;
371367

372-
// Subtle: we can't do rvalue promotion analysis until the
373-
// typeck phase is complete, which means that you can't trust
374-
// the rvalue lifetimes that result, but that's ok, since we
375-
// don't need to know those during type inference.
376-
let rvalue_promotable_map = None;
377-
378368
MemCategorizationContext {
379369
tcx,
380370
body_owner,
381371
upvars: tcx.upvars(body_owner),
382372
region_scope_tree,
383373
tables,
384-
rvalue_promotable_map,
385374
infcx: Some(infcx),
386375
param_env,
387376
}
@@ -664,8 +653,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
664653
.any(|attr| attr.check_name(sym::thread_local));
665654

666655
let cat = if is_thread_local {
667-
let re = self.temporary_scope(hir_id.local_id);
668-
Categorization::ThreadLocal(re)
656+
Categorization::ThreadLocal
669657
} else {
670658
Categorization::StaticItem
671659
};
@@ -876,16 +864,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
876864
ret
877865
}
878866

879-
/// Returns the lifetime of a temporary created by expr with id `id`.
880-
/// This could be `'static` if `id` is part of a constant expression.
881-
pub fn temporary_scope(&self, id: hir::ItemLocalId) -> ty::Region<'tcx> {
882-
let scope = self.region_scope_tree.temporary_scope(id);
883-
self.tcx.mk_region(match scope {
884-
Some(scope) => ty::ReScope(scope),
885-
None => ty::ReStatic
886-
})
887-
}
888-
889867
pub fn cat_rvalue_node(&self,
890868
hir_id: hir::HirId,
891869
span: Span,
@@ -894,41 +872,19 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
894872
debug!("cat_rvalue_node(id={:?}, span={:?}, expr_ty={:?})",
895873
hir_id, span, expr_ty);
896874

897-
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
898-
.unwrap_or(false);
899-
900-
debug!("cat_rvalue_node: promotable = {:?}", promotable);
901-
902-
// Always promote `[T; 0]` (even when e.g., borrowed mutably).
903-
let promotable = match expr_ty.kind {
904-
ty::Array(_, len) if len.try_eval_usize(self.tcx, self.param_env) == Some(0) => true,
905-
_ => promotable,
906-
};
907-
908-
debug!("cat_rvalue_node: promotable = {:?} (2)", promotable);
909-
910-
// Compute maximum lifetime of this rvalue. This is 'static if
911-
// we can promote to a constant, otherwise equal to enclosing temp
912-
// lifetime.
913-
let re = if promotable {
914-
self.tcx.lifetimes.re_static
915-
} else {
916-
self.temporary_scope(hir_id.local_id)
917-
};
918-
let ret = self.cat_rvalue(hir_id, span, re, expr_ty);
875+
let ret = self.cat_rvalue(hir_id, span, expr_ty);
919876
debug!("cat_rvalue_node ret {:?}", ret);
920877
ret
921878
}
922879

923880
pub fn cat_rvalue(&self,
924881
cmt_hir_id: hir::HirId,
925882
span: Span,
926-
temp_scope: ty::Region<'tcx>,
927883
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
928884
let ret = cmt_ {
929885
hir_id: cmt_hir_id,
930886
span:span,
931-
cat:Categorization::Rvalue(temp_scope),
887+
cat:Categorization::Rvalue,
932888
mutbl:McDeclared,
933889
ty:expr_ty,
934890
note: NoteNone
@@ -1376,9 +1332,9 @@ impl<'tcx> cmt_<'tcx> {
13761332
//! determines how long the value in `self` remains live.
13771333
13781334
match self.cat {
1379-
Categorization::Rvalue(..) |
1335+
Categorization::Rvalue |
13801336
Categorization::StaticItem |
1381-
Categorization::ThreadLocal(..) |
1337+
Categorization::ThreadLocal |
13821338
Categorization::Local(..) |
13831339
Categorization::Deref(_, UnsafePtr(..)) |
13841340
Categorization::Deref(_, BorrowedPtr(..)) |
@@ -1409,8 +1365,8 @@ impl<'tcx> cmt_<'tcx> {
14091365
b.freely_aliasable()
14101366
}
14111367

1412-
Categorization::Rvalue(..) |
1413-
Categorization::ThreadLocal(..) |
1368+
Categorization::Rvalue |
1369+
Categorization::ThreadLocal |
14141370
Categorization::Local(..) |
14151371
Categorization::Upvar(..) |
14161372
Categorization::Deref(_, UnsafePtr(..)) => { // yes, it's aliasable, but...
@@ -1457,10 +1413,10 @@ impl<'tcx> cmt_<'tcx> {
14571413
Categorization::StaticItem => {
14581414
"static item".into()
14591415
}
1460-
Categorization::ThreadLocal(..) => {
1416+
Categorization::ThreadLocal => {
14611417
"thread-local static item".into()
14621418
}
1463-
Categorization::Rvalue(..) => {
1419+
Categorization::Rvalue => {
14641420
"non-place".into()
14651421
}
14661422
Categorization::Local(vid) => {

src/librustc/query/mod.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ rustc_queries! {
9494
/// of the MIR qualify_consts pass. The actual meaning of
9595
/// the value isn't known except to the pass itself.
9696
query mir_const_qualif(key: DefId) -> (u8, &'tcx BitSet<mir::Local>) {
97+
desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
9798
cache_on_disk_if { key.is_local() }
9899
}
99100

@@ -530,19 +531,6 @@ rustc_queries! {
530531

531532
TypeChecking {
532533
query trait_of_item(_: DefId) -> Option<DefId> {}
533-
query const_is_rvalue_promotable_to_static(key: DefId) -> bool {
534-
desc { |tcx|
535-
"const checking if rvalue is promotable to static `{}`",
536-
tcx.def_path_str(key)
537-
}
538-
cache_on_disk_if { true }
539-
}
540-
query rvalue_promotable_map(key: DefId) -> &'tcx ItemLocalSet {
541-
desc { |tcx|
542-
"checking which parts of `{}` are promotable to static",
543-
tcx.def_path_str(key)
544-
}
545-
}
546534
}
547535

548536
Codegen {

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt, AdtSizedConst
3737
use crate::ty::steal::Steal;
3838
use crate::ty::util::NeedsDrop;
3939
use crate::ty::subst::SubstsRef;
40-
use crate::util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
40+
use crate::util::nodemap::{DefIdSet, DefIdMap};
4141
use crate::util::common::ErrorReported;
4242
use crate::util::profiling::ProfileCategory::*;
4343

src/librustc_interface/passes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -916,9 +916,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
916916

917917
time(sess, "misc checking 2", || {
918918
parallel!({
919-
time(sess, "rvalue promotion + match checking", || {
919+
time(sess, "match checking", || {
920920
tcx.par_body_owners(|def_id| {
921-
tcx.ensure().const_is_rvalue_promotable_to_static(def_id);
922921
tcx.ensure().check_match(def_id);
923922
});
924923
});

src/librustc_metadata/cstore_impl.rs

-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
154154
rendered_const => { cdata.get_rendered_const(def_id.index) }
155155
impl_parent => { cdata.get_parent_impl(def_id.index) }
156156
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
157-
const_is_rvalue_promotable_to_static => {
158-
cdata.const_is_rvalue_promotable_to_static(def_id.index)
159-
}
160157
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
161158

162159
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }

src/librustc_metadata/decoder.rs

-8
Original file line numberDiff line numberDiff line change
@@ -915,14 +915,6 @@ impl<'a, 'tcx> CrateMetadata {
915915
}
916916
}
917917

918-
pub fn const_is_rvalue_promotable_to_static(&self, id: DefIndex) -> bool {
919-
match self.entry(id).kind {
920-
EntryKind::AssocConst(_, data, _) |
921-
EntryKind::Const(data, _) => data.ast_promotable,
922-
_ => bug!(),
923-
}
924-
}
925-
926918
pub fn is_item_mir_available(&self, id: DefIndex) -> bool {
927919
!self.is_proc_macro(id) &&
928920
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()

src/librustc_metadata/encoder.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -861,18 +861,11 @@ impl EncodeContext<'tcx> {
861861

862862
let kind = match trait_item.kind {
863863
ty::AssocKind::Const => {
864-
let const_qualif =
865-
if let hir::TraitItemKind::Const(_, Some(body)) = ast_item.kind {
866-
self.const_qualif(0, body)
867-
} else {
868-
ConstQualif { mir: 0, ast_promotable: false }
869-
};
870-
871864
let rendered =
872865
hir::print::to_string(self.tcx.hir(), |s| s.print_trait_item(ast_item));
873866
let rendered_const = self.lazy(RenderedConst(rendered));
874867

875-
EntryKind::AssocConst(container, const_qualif, rendered_const)
868+
EntryKind::AssocConst(container, ConstQualif { mir: 0 }, rendered_const)
876869
}
877870
ty::AssocKind::Method => {
878871
let fn_data = if let hir::TraitItemKind::Method(method_sig, m) = &ast_item.kind {
@@ -946,13 +939,6 @@ impl EncodeContext<'tcx> {
946939
!self.tcx.sess.opts.output_types.should_codegen()
947940
}
948941

949-
fn const_qualif(&self, mir: u8, body_id: hir::BodyId) -> ConstQualif {
950-
let body_owner_def_id = self.tcx.hir().body_owner_def_id(body_id);
951-
let ast_promotable = self.tcx.const_is_rvalue_promotable_to_static(body_owner_def_id);
952-
953-
ConstQualif { mir, ast_promotable }
954-
}
955-
956942
fn encode_info_for_impl_item(&mut self, def_id: DefId) -> Entry<'tcx> {
957943
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
958944
let tcx = self.tcx;
@@ -974,7 +960,7 @@ impl EncodeContext<'tcx> {
974960
let mir = self.tcx.at(ast_item.span).mir_const_qualif(def_id).0;
975961

976962
EntryKind::AssocConst(container,
977-
self.const_qualif(mir, body_id),
963+
ConstQualif { mir },
978964
self.encode_rendered_const_for_body(body_id))
979965
} else {
980966
bug!()
@@ -1123,7 +1109,7 @@ impl EncodeContext<'tcx> {
11231109
hir::ItemKind::Const(_, body_id) => {
11241110
let mir = tcx.at(item.span).mir_const_qualif(def_id).0;
11251111
EntryKind::Const(
1126-
self.const_qualif(mir, body_id),
1112+
ConstQualif { mir },
11271113
self.encode_rendered_const_for_body(body_id)
11281114
)
11291115
}
@@ -1475,7 +1461,7 @@ impl EncodeContext<'tcx> {
14751461
let mir = tcx.mir_const_qualif(def_id).0;
14761462

14771463
Entry {
1478-
kind: EntryKind::Const(self.const_qualif(mir, body_id), const_data),
1464+
kind: EntryKind::Const(ConstQualif { mir }, const_data),
14791465
visibility: self.lazy(ty::Visibility::Public),
14801466
span: self.lazy(tcx.def_span(def_id)),
14811467
attributes: Lazy::empty(),

src/librustc_metadata/schema.rs

-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ pub enum EntryKind<'tcx> {
274274
#[derive(Clone, Copy, RustcEncodable, RustcDecodable)]
275275
pub struct ConstQualif {
276276
pub mir: u8,
277-
pub ast_promotable: bool,
278277
}
279278

280279
/// Contains a constant which has been rendered to a String.

src/librustc_passes/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ use rustc::ty::query::Providers;
1919
pub mod error_codes;
2020

2121
pub mod ast_validation;
22-
pub mod rvalue_promotion;
2322
pub mod hir_stats;
2423
pub mod layout_test;
2524
pub mod loops;
2625

2726
pub fn provide(providers: &mut Providers<'_>) {
28-
rvalue_promotion::provide(providers);
2927
loops::provide(providers);
3028
}

0 commit comments

Comments
 (0)