Skip to content

rustc: remove {FxHash,Node,DefId,HirId,ItemLocal}{Map,Set} "constructor" fns. #52591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,14 @@ dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "ena"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "env_logger"
version = "0.5.12"
Expand Down Expand Up @@ -2196,7 +2204,7 @@ name = "rustc_data_structures"
version = "0.0.0"
dependencies = [
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ena 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"graphviz 0.0.0",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -3261,6 +3269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
"checksum elasticlunr-rs 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4837d77a1e157489a3933b743fd774ae75074e0e390b2b7f071530048a0d87ee"
"checksum ena 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "25b4e5febb25f08c49f1b07dc33a182729a6b21edfb562b5aef95f78e0dbe5bb"
"checksum ena 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "88dc8393b3c7352f94092497f6b52019643e493b6b890eb417cdb7c46117e621"
"checksum env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)" = "f4d7e69c283751083d53d01eac767407343b8b69c4bd70058e08adc2637cb257"
"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ impl DepGraph {
DepGraph {
data: Some(Lrc::new(DepGraphData {
previous_work_products: prev_work_products,
dep_node_debug: Lock::new(Default::default()),
dep_node_debug: Default::default(),
current: Lock::new(CurrentDepGraph::new()),
previous: prev_graph,
colors: Lock::new(DepNodeColorMap::new(prev_graph_node_count)),
loaded_from_cache: Lock::new(Default::default()),
loaded_from_cache: Default::default(),
})),
fingerprints: Lrc::new(Lock::new(fingerprints)),
}
Expand Down
17 changes: 10 additions & 7 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ pub fn lower_crate(
loop_scopes: Vec::new(),
is_in_loop_condition: false,
anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough,
type_def_lifetime_params: DefIdMap(),
type_def_lifetime_params: Default::default(),
current_hir_id_owner: vec![(CRATE_DEF_INDEX, 0)],
item_local_id_counters: NodeMap(),
item_local_id_counters: Default::default(),
node_id_to_hir_id: IndexVec::new(),
is_generator: false,
is_in_trait_impl: false,
Expand Down Expand Up @@ -1168,7 +1168,7 @@ impl<'a> LoweringContext<'a> {
hir::TyKind::BareFn(P(hir::BareFnTy {
generic_params: this.lower_generic_params(
&f.generic_params,
&NodeMap(),
&NodeMap::default(),
ImplTraitContext::disallowed(),
),
unsafety: this.lower_unsafety(f.unsafety),
Expand Down Expand Up @@ -2467,7 +2467,7 @@ impl<'a> LoweringContext<'a> {
// FIXME: This could probably be done with less rightward drift. Also looks like two control
// paths where report_error is called are also the only paths that advance to after
// the match statement, so the error reporting could probably just be moved there.
let mut add_bounds: NodeMap<Vec<_>> = NodeMap();
let mut add_bounds: NodeMap<Vec<_>> = Default::default();
for pred in &generics.where_clause.predicates {
if let WherePredicate::BoundPredicate(ref bound_pred) = *pred {
'next_bound: for bound in &bound_pred.bounds {
Expand Down Expand Up @@ -2552,7 +2552,7 @@ impl<'a> LoweringContext<'a> {
hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
bound_generic_params: this.lower_generic_params(
bound_generic_params,
&NodeMap(),
&NodeMap::default(),
ImplTraitContext::disallowed(),
),
bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::disallowed()),
Expand Down Expand Up @@ -2636,8 +2636,11 @@ impl<'a> LoweringContext<'a> {
p: &PolyTraitRef,
mut itctx: ImplTraitContext<'_>,
) -> hir::PolyTraitRef {
let bound_generic_params =
self.lower_generic_params(&p.bound_generic_params, &NodeMap(), itctx.reborrow());
let bound_generic_params = self.lower_generic_params(
&p.bound_generic_params,
&NodeMap::default(),
itctx.reborrow(),
);
let trait_ref = self.with_parent_impl_lifetime_defs(
&bound_generic_params,
|this| this.lower_trait_ref(&p.trait_ref, itctx),
Expand Down
19 changes: 4 additions & 15 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use util::nodemap::NodeMap;
/// Internally the DefPathTable holds a tree of DefKeys, where each DefKey
/// stores the DefIndex of its parent.
/// There is one DefPathTable for each crate.
#[derive(Default)]
pub struct DefPathTable {
index_to_key: [Vec<DefKey>; 2],
def_path_hashes: [Vec<DefPathHash>; 2],
Expand Down Expand Up @@ -153,7 +154,7 @@ impl Decodable for DefPathTable {
/// The definition table containing node definitions.
/// It holds the DefPathTable for local DefIds/DefPaths and it also stores a
/// mapping from NodeIds to local DefIds.
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct Definitions {
table: DefPathTable,
node_to_def_index: NodeMap<DefIndex>,
Expand Down Expand Up @@ -412,20 +413,8 @@ impl Definitions {
/// ascending order.
///
/// FIXME: there is probably a better place to put this comment.
pub fn new() -> Definitions {
Definitions {
table: DefPathTable {
index_to_key: [vec![], vec![]],
def_path_hashes: [vec![], vec![]],
},
node_to_def_index: NodeMap(),
def_index_to_node: [vec![], vec![]],
node_to_hir_id: IndexVec::new(),
parent_modules_of_macro_defs: Default::default(),
expansions_that_defined: Default::default(),
next_disambiguator: Default::default(),
def_index_to_span: Default::default(),
}
pub fn new() -> Self {
Self::default()
}

pub fn def_path_table(&self) -> &DefPathTable {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for Span {
// times, we cache a stable hash of it and hash that instead of
// recursing every time.
thread_local! {
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> =
RefCell::new(Default::default());
static CACHE: RefCell<FxHashMap<hygiene::Mark, u64>> = Default::default();
}

let sub_hash: u64 = CACHE.with(|cache| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
parent_def_id,
body_id,
param_env,
opaque_types: DefIdMap(),
opaque_types: Default::default(),
obligations: vec![],
};
let value = instantiator.instantiate_opaque_types_in_map(value);
Expand Down
14 changes: 3 additions & 11 deletions src/librustc/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::{cmp, fmt, mem, u32};

mod taint;

#[derive(Default)]
pub struct RegionConstraintCollector<'tcx> {
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
var_infos: IndexVec<RegionVid, RegionVariableInfo>,
Expand Down Expand Up @@ -341,17 +342,8 @@ impl TaintDirections {
}

impl<'tcx> RegionConstraintCollector<'tcx> {
pub fn new() -> RegionConstraintCollector<'tcx> {
RegionConstraintCollector {
var_infos: VarInfos::default(),
data: RegionConstraintData::default(),
lubs: Default::default(),
glbs: Default::default(),
bound_count: 0,
undo_log: Vec::new(),
unification_table: ut::UnificationTable::new(),
any_unifications: false,
}
pub fn new() -> Self {
Self::default()
}

pub fn num_region_vars(&self) -> usize {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ pub fn check_ast_crate(
let (passes, buffered) = if pre_expansion {
(
sess.lint_store.borrow_mut().pre_expansion_passes.take(),
LintBuffer::new(),
LintBuffer::default(),
)
} else {
(
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,12 @@ mod levels;

pub use self::levels::{LintLevelSets, LintLevelMap};

#[derive(Default)]
pub struct LintBuffer {
map: NodeMap<Vec<BufferedEarlyLint>>,
}

impl LintBuffer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can have a derive(Default) now

pub fn new() -> LintBuffer {
LintBuffer { map: NodeMap() }
}

pub fn add_lint(&mut self,
lint: &'static Lint,
id: ast::NodeId,
Expand Down
8 changes: 7 additions & 1 deletion src/librustc/middle/borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
pub enum SignalledError { SawSomeError, NoErrorsSeen }

impl Default for SignalledError {
fn default() -> SignalledError {
SignalledError::NoErrorsSeen
}
}

impl_stable_hash_for!(enum self::SignalledError { SawSomeError, NoErrorsSeen });

#[derive(Debug, RustcEncodable, RustcDecodable)]
#[derive(Debug, Default, RustcEncodable, RustcDecodable)]
pub struct BorrowCheckResult {
pub used_mut_nodes: FxHashSet<HirId>,
pub signalled_any_error: SignalledError,
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
tcx,
num_live_nodes: 0,
num_vars: 0,
live_node_map: HirIdMap(),
variable_map: HirIdMap(),
capture_info_map: NodeMap(),
live_node_map: HirIdMap::default(),
variable_map: HirIdMap::default(),
capture_info_map: Default::default(),
var_kinds: Vec::new(),
lnks: Vec::new(),
}
Expand Down Expand Up @@ -397,7 +397,7 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
fn add_from_pat<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, pat: &P<hir::Pat>) {
// For struct patterns, take note of which fields used shorthand
// (`x` rather than `x: x`).
let mut shorthand_field_ids = HirIdSet();
let mut shorthand_field_ids = HirIdSet::default();
let mut pats = VecDeque::new();
pats.push_back(pat);
while let Some(pat) = pats.pop_front() {
Expand Down Expand Up @@ -691,8 +691,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
s: specials,
successors: vec![invalid_node(); num_live_nodes],
rwu_table: RWUTable::new(num_live_nodes * num_vars),
break_ln: NodeMap(),
cont_ln: NodeMap(),
break_ln: Default::default(),
cont_ln: Default::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
let mut reachable_context = ReachableContext {
tcx,
tables: &ty::TypeckTables::empty(None),
reachable_symbols: NodeSet(),
reachable_symbols: Default::default(),
worklist: Vec::new(),
any_library,
};
Expand Down
21 changes: 9 additions & 12 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ fn resolve_lifetimes<'tcx>(
fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
let krate = tcx.hir.krate();
let mut map = NamedRegionMap {
defs: NodeMap(),
late_bound: NodeSet(),
defs: Default::default(),
late_bound: Default::default(),
object_lifetime_defaults: compute_object_lifetime_defaults(tcx),
};
{
Expand All @@ -437,8 +437,8 @@ fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
trait_ref_hack: false,
is_in_fn_syntax: false,
labels_in_fn: vec![],
xcrate_object_lifetime_defaults: DefIdMap(),
lifetime_uses: &mut DefIdMap(),
xcrate_object_lifetime_defaults: Default::default(),
lifetime_uses: &mut Default::default(),
};
for (_, item) in &krate.items {
visitor.visit_item(item);
Expand Down Expand Up @@ -1278,7 +1278,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
fn compute_object_lifetime_defaults(
tcx: TyCtxt<'_, '_, '_>,
) -> NodeMap<Vec<ObjectLifetimeDefault>> {
let mut map = NodeMap();
let mut map = NodeMap::default();
for item in tcx.hir.krate().items.values() {
match item.node {
hir::ItemKind::Struct(_, ref generics)
Expand Down Expand Up @@ -1432,7 +1432,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
} = self;
let labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
let xcrate_object_lifetime_defaults =
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap());
replace(&mut self.xcrate_object_lifetime_defaults, DefIdMap::default());
let mut this = LifetimeContext {
tcx: *tcx,
map: map,
Expand Down Expand Up @@ -2741,9 +2741,7 @@ fn insert_late_bound_lifetimes(
constrained_by_input.visit_ty(arg_ty);
}

let mut appears_in_output = AllCollector {
regions: Default::default(),
};
let mut appears_in_output = AllCollector::default();
intravisit::walk_fn_ret_ty(&mut appears_in_output, &decl.output);

debug!(
Expand All @@ -2755,9 +2753,7 @@ fn insert_late_bound_lifetimes(
//
// Subtle point: because we disallow nested bindings, we can just
// ignore binders here and scrape up all names we see.
let mut appears_in_where_clause = AllCollector {
regions: Default::default(),
};
let mut appears_in_where_clause = AllCollector::default();
appears_in_where_clause.visit_generics(generics);

for param in &generics.params {
Expand Down Expand Up @@ -2854,6 +2850,7 @@ fn insert_late_bound_lifetimes(
}
}

#[derive(Default)]
struct AllCollector {
regions: FxHashSet<hir::LifetimeName>,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ pub fn build_session_(
local_crate_source_file,
working_dir,
lint_store: RwLock::new(lint::LintStore::new()),
buffered_lints: Lock::new(Some(lint::LintBuffer::new())),
buffered_lints: Lock::new(Some(Default::default())),
one_time_diagnostics: Default::default(),
plugin_llvm_passes: OneThread::new(RefCell::new(Vec::new())),
plugin_attributes: OneThread::new(RefCell::new(Vec::new())),
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,22 @@ impl<'tcx> TypeckTables<'tcx> {
pub fn empty(local_id_root: Option<DefId>) -> TypeckTables<'tcx> {
TypeckTables {
local_id_root,
type_dependent_defs: ItemLocalMap(),
field_indices: ItemLocalMap(),
user_provided_tys: ItemLocalMap(),
type_dependent_defs: Default::default(),
field_indices: Default::default(),
user_provided_tys: Default::default(),
user_provided_sigs: Default::default(),
node_types: ItemLocalMap(),
node_substs: ItemLocalMap(),
user_substs: ItemLocalMap(),
adjustments: ItemLocalMap(),
pat_binding_modes: ItemLocalMap(),
pat_adjustments: ItemLocalMap(),
node_types: Default::default(),
node_substs: Default::default(),
user_substs: Default::default(),
adjustments: Default::default(),
pat_binding_modes: Default::default(),
pat_adjustments: Default::default(),
upvar_capture_map: Default::default(),
closure_kind_origins: ItemLocalMap(),
liberated_fn_sigs: ItemLocalMap(),
fru_field_types: ItemLocalMap(),
cast_kinds: ItemLocalMap(),
used_trait_imports: Lrc::new(DefIdSet()),
closure_kind_origins: Default::default(),
liberated_fn_sigs: Default::default(),
fru_field_types: Default::default(),
cast_kinds: Default::default(),
used_trait_imports: Lrc::new(Default::default()),
tainted_by_errors: false,
free_region_map: Default::default(),
concrete_existential_types: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3183,7 +3183,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
/// rather, you should request the vector for a specific type via
/// `tcx.inherent_impls(def_id)` so as to minimize your dependencies
/// (constructing this map requires touching the entire crate).
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct CrateInherentImpls {
pub inherent_impls: DefIdMap<Lrc<Vec<DefId>>>,
}
Expand Down
Loading