Skip to content

Commit fd9ecfd

Browse files
committed
Auto merge of #45736 - oli-obk:rvalue_promotable_map, r=nikomatsakis
Use a `Set<T>` instead of a `Map<T, bool>` r? @nikomatsakis introduced in #44501
2 parents fc77b62 + 2961937 commit fd9ecfd

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

src/librustc/middle/expr_use_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::rc::Rc;
3131
use syntax::ast;
3232
use syntax::ptr::P;
3333
use syntax_pos::Span;
34-
use util::nodemap::ItemLocalMap;
34+
use util::nodemap::ItemLocalSet;
3535

3636
///////////////////////////////////////////////////////////////////////////
3737
// The Delegate trait
@@ -279,7 +279,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> {
279279
param_env: ty::ParamEnv<'tcx>,
280280
region_scope_tree: &'a region::ScopeTree,
281281
tables: &'a ty::TypeckTables<'tcx>,
282-
rvalue_promotable_map: Option<Rc<ItemLocalMap<bool>>>)
282+
rvalue_promotable_map: Option<Rc<ItemLocalSet>>)
283283
-> Self
284284
{
285285
ExprUseVisitor {

src/librustc/middle/mem_categorization.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ use syntax_pos::Span;
8686

8787
use std::fmt;
8888
use std::rc::Rc;
89-
use util::nodemap::ItemLocalMap;
89+
use util::nodemap::ItemLocalSet;
9090

9191
#[derive(Clone, PartialEq)]
9292
pub enum Categorization<'tcx> {
@@ -286,7 +286,7 @@ pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
286286
pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
287287
pub region_scope_tree: &'a region::ScopeTree,
288288
pub tables: &'a ty::TypeckTables<'tcx>,
289-
rvalue_promotable_map: Option<Rc<ItemLocalMap<bool>>>,
289+
rvalue_promotable_map: Option<Rc<ItemLocalSet>>,
290290
infcx: Option<&'a InferCtxt<'a, 'gcx, 'tcx>>,
291291
}
292292

@@ -395,7 +395,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> {
395395
pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
396396
region_scope_tree: &'a region::ScopeTree,
397397
tables: &'a ty::TypeckTables<'tcx>,
398-
rvalue_promotable_map: Option<Rc<ItemLocalMap<bool>>>)
398+
rvalue_promotable_map: Option<Rc<ItemLocalSet>>)
399399
-> MemCategorizationContext<'a, 'tcx, 'tcx> {
400400
MemCategorizationContext {
401401
tcx,
@@ -897,7 +897,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
897897
expr_ty: Ty<'tcx>)
898898
-> cmt<'tcx> {
899899
let hir_id = self.tcx.hir.node_to_hir_id(id);
900-
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m[&hir_id.local_id])
900+
let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id))
901901
.unwrap_or(false);
902902

903903
// Always promote `[T; 0]` (even when e.g. borrowed mutably).

src/librustc/ty/maps/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use ty::{self, CrateInherentImpls, Ty, TyCtxt};
3737
use ty::layout::{Layout, LayoutError};
3838
use ty::steal::Steal;
3939
use ty::subst::Substs;
40-
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalMap};
40+
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
4141
use util::common::{profq_msg, ProfileQueriesMsg};
4242

4343
use rustc_data_structures::indexed_set::IdxSetBuf;
@@ -236,7 +236,7 @@ define_maps! { <'tcx>
236236
[] fn is_exported_symbol: IsExportedSymbol(DefId) -> bool,
237237
[] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> ExternBodyNestedBodies,
238238
[] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
239-
[] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Rc<ItemLocalMap<bool>>,
239+
[] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Rc<ItemLocalSet>,
240240
[] fn is_mir_available: IsMirAvailable(DefId) -> bool,
241241
[] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>)
242242
-> Rc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>,

src/librustc/util/nodemap.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ pub type ItemLocalMap<T> = FxHashMap<ItemLocalId, T>;
2525

2626
pub type NodeSet = FxHashSet<ast::NodeId>;
2727
pub type DefIdSet = FxHashSet<DefId>;
28+
pub type ItemLocalSet = FxHashSet<ItemLocalId>;
2829

2930
pub fn NodeMap<T>() -> NodeMap<T> { FxHashMap() }
3031
pub fn DefIdMap<T>() -> DefIdMap<T> { FxHashMap() }
3132
pub fn ItemLocalMap<T>() -> ItemLocalMap<T> { FxHashMap() }
3233
pub fn NodeSet() -> NodeSet { FxHashSet() }
3334
pub fn DefIdSet() -> DefIdSet { FxHashSet() }
35+
pub fn ItemLocalSet() -> ItemLocalSet { FxHashSet() }
3436

src/librustc_passes/consts.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc::ty::maps::{queries, Providers};
4343
use rustc::ty::subst::Substs;
4444
use rustc::traits::Reveal;
4545
use rustc::util::common::ErrorReported;
46-
use rustc::util::nodemap::{ItemLocalMap, NodeSet};
46+
use rustc::util::nodemap::{ItemLocalSet, NodeSet};
4747
use rustc::lint::builtin::CONST_ERR;
4848
use rustc::hir::{self, PatKind, RangeEnd};
4949
use std::rc::Rc;
@@ -79,12 +79,12 @@ fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7979
.expect("rvalue_promotable_map invoked with non-local def-id");
8080
let body_id = tcx.hir.body_owned_by(node_id);
8181
let body_hir_id = tcx.hir.node_to_hir_id(body_id.node_id);
82-
tcx.rvalue_promotable_map(def_id).contains_key(&body_hir_id.local_id)
82+
tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id)
8383
}
8484

8585
fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
8686
def_id: DefId)
87-
-> Rc<ItemLocalMap<bool>>
87+
-> Rc<ItemLocalSet>
8888
{
8989
let outer_def_id = tcx.closure_base_def_id(def_id);
9090
if outer_def_id != def_id {
@@ -100,7 +100,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
100100
mut_rvalue_borrows: NodeSet(),
101101
param_env: ty::ParamEnv::empty(Reveal::UserFacing),
102102
identity_substs: Substs::empty(),
103-
result_map: ItemLocalMap(),
103+
result: ItemLocalSet(),
104104
};
105105

106106
// `def_id` should be a `Body` owner
@@ -109,7 +109,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
109109
let body_id = tcx.hir.body_owned_by(node_id);
110110
visitor.visit_nested_body(body_id);
111111

112-
Rc::new(visitor.result_map)
112+
Rc::new(visitor.result)
113113
}
114114

115115
struct CheckCrateVisitor<'a, 'tcx: 'a> {
@@ -121,7 +121,7 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> {
121121
param_env: ty::ParamEnv<'tcx>,
122122
identity_substs: &'tcx Substs<'tcx>,
123123
tables: &'a ty::TypeckTables<'tcx>,
124-
result_map: ItemLocalMap<bool>,
124+
result: ItemLocalSet,
125125
}
126126

127127
impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
@@ -322,7 +322,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> {
322322
}
323323
}
324324

325-
self.result_map.insert(ex.hir_id.local_id, self.promotable);
325+
if self.promotable {
326+
self.result.insert(ex.hir_id.local_id);
327+
}
326328
self.promotable &= outer;
327329
}
328330
}

0 commit comments

Comments
 (0)