Skip to content

Commit cb4145e

Browse files
authored
Rollup merge of rust-lang#64874 - matthewjasper:simplify-euv, r=eddyb
Simplify ExprUseVisitor * Remove HIR const qualification * Remove parts of ExprUseVisitor that aren't being used r? @eddyb
2 parents 17e1f23 + b4ad612 commit cb4145e

File tree

19 files changed

+149
-1344
lines changed

19 files changed

+149
-1344
lines changed

src/librustc/middle/expr_use_visitor.rs

+79-394
Large diffs are not rendered by default.

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
};
@@ -878,16 +866,6 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
878866
ret
879867
}
880868

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

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

925882
pub fn cat_rvalue(&self,
926883
cmt_hir_id: hir::HirId,
927884
span: Span,
928-
temp_scope: ty::Region<'tcx>,
929885
expr_ty: Ty<'tcx>) -> cmt_<'tcx> {
930886
let ret = cmt_ {
931887
hir_id: cmt_hir_id,
932888
span:span,
933-
cat:Categorization::Rvalue(temp_scope),
889+
cat:Categorization::Rvalue,
934890
mutbl:McDeclared,
935891
ty:expr_ty,
936892
note: NoteNone
@@ -1378,9 +1334,9 @@ impl<'tcx> cmt_<'tcx> {
13781334
//! determines how long the value in `self` remains live.
13791335
13801336
match self.cat {
1381-
Categorization::Rvalue(..) |
1337+
Categorization::Rvalue |
13821338
Categorization::StaticItem |
1383-
Categorization::ThreadLocal(..) |
1339+
Categorization::ThreadLocal |
13841340
Categorization::Local(..) |
13851341
Categorization::Deref(_, UnsafePtr(..)) |
13861342
Categorization::Deref(_, BorrowedPtr(..)) |
@@ -1411,8 +1367,8 @@ impl<'tcx> cmt_<'tcx> {
14111367
b.freely_aliasable()
14121368
}
14131369

1414-
Categorization::Rvalue(..) |
1415-
Categorization::ThreadLocal(..) |
1370+
Categorization::Rvalue |
1371+
Categorization::ThreadLocal |
14161372
Categorization::Local(..) |
14171373
Categorization::Upvar(..) |
14181374
Categorization::Deref(_, UnsafePtr(..)) => { // yes, it's aliasable, but...
@@ -1459,10 +1415,10 @@ impl<'tcx> cmt_<'tcx> {
14591415
Categorization::StaticItem => {
14601416
"static item".into()
14611417
}
1462-
Categorization::ThreadLocal(..) => {
1418+
Categorization::ThreadLocal => {
14631419
"thread-local static item".into()
14641420
}
1465-
Categorization::Rvalue(..) => {
1421+
Categorization::Rvalue => {
14661422
"non-place".into()
14671423
}
14681424
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
@@ -917,9 +917,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
917917

918918
time(sess, "misc checking 2", || {
919919
parallel!({
920-
time(sess, "rvalue promotion + match checking", || {
920+
time(sess, "match checking", || {
921921
tcx.par_body_owners(|def_id| {
922-
tcx.ensure().const_is_rvalue_promotable_to_static(def_id);
923922
tcx.ensure().check_match(def_id);
924923
});
925924
});

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)