Skip to content

Commit d106808

Browse files
committed
Auto merge of #57592 - Centril:rollup, r=Centril
Rollup of 6 pull requests Successful merges: - #57232 (Parallelize and optimize parts of HIR map creation) - #57418 (MetadataOnlyCodegenBackend: run the collector only once) - #57465 (Stabilize cfg_target_vendor) - #57477 (clarify resolve typo suggestion) - #57556 (privacy: Fix private-in-public check for existential types) - #57584 (Remove the `connect_timeout_unroutable` test.) Failed merges: r? @ghost
2 parents 1a3a3df + 47ccf2a commit d106808

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+340
-253
lines changed

src/libpanic_abort/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![panic_runtime]
1313
#![allow(unused_features)]
1414

15-
#![feature(cfg_target_vendor)]
15+
#![cfg_attr(stage0, feature(cfg_target_vendor))]
1616
#![feature(core_intrinsics)]
1717
#![feature(libc)]
1818
#![feature(nll)]

src/librustc/hir/def.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl Def {
284284
}
285285
}
286286

287-
/// A human readable kind name
287+
/// A human readable name for the def kind ("function", "module", etc.).
288288
pub fn kind_name(&self) -> &'static str {
289289
match *self {
290290
Def::Fn(..) => "function",
@@ -324,6 +324,7 @@ impl Def {
324324
}
325325
}
326326

327+
/// An English article for the def.
327328
pub fn article(&self) -> &'static str {
328329
match *self {
329330
Def::AssociatedTy(..) | Def::AssociatedConst(..) | Def::AssociatedExistential(..) |

src/librustc/hir/map/collector.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_data_structures::svh::Svh;
66
use ich::Fingerprint;
77
use middle::cstore::CrateStore;
88
use session::CrateDisambiguator;
9+
use session::Session;
910
use std::iter::repeat;
1011
use syntax::ast::{NodeId, CRATE_NODE_ID};
1112
use syntax::source_map::SourceMap;
@@ -92,11 +93,11 @@ where
9293
}
9394

9495
impl<'a, 'hir> NodeCollector<'a, 'hir> {
95-
pub(super) fn root(krate: &'hir Crate,
96+
pub(super) fn root(sess: &'a Session,
97+
krate: &'hir Crate,
9698
dep_graph: &'a DepGraph,
9799
definitions: &'a definitions::Definitions,
98-
mut hcx: StableHashingContext<'a>,
99-
source_map: &'a SourceMap)
100+
mut hcx: StableHashingContext<'a>)
100101
-> NodeCollector<'a, 'hir> {
101102
let root_mod_def_path_hash = definitions.def_path_hash(CRATE_DEF_INDEX);
102103

@@ -141,8 +142,8 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
141142

142143
let mut collector = NodeCollector {
143144
krate,
144-
source_map,
145-
map: vec![],
145+
source_map: sess.source_map(),
146+
map: repeat(None).take(sess.current_node_id_count()).collect(),
146147
parent_node: CRATE_NODE_ID,
147148
current_signature_dep_index: root_mod_sig_dep_index,
148149
current_full_dep_index: root_mod_full_dep_index,
@@ -219,10 +220,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
219220

220221
fn insert_entry(&mut self, id: NodeId, entry: Entry<'hir>) {
221222
debug!("hir_map: {:?} => {:?}", id, entry);
222-
let len = self.map.len();
223-
if id.as_usize() >= len {
224-
self.map.extend(repeat(None).take(id.as_usize() - len + 1));
225-
}
226223
self.map[id.as_usize()] = Some(entry);
227224
}
228225

src/librustc/hir/map/hir_id_validator.rs

+26-19
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ use hir::{self, intravisit, HirId, ItemLocalId};
33
use syntax::ast::NodeId;
44
use hir::itemlikevisit::ItemLikeVisitor;
55
use rustc_data_structures::fx::FxHashMap;
6+
use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter};
67

78
pub fn check_crate<'hir>(hir_map: &hir::map::Map<'hir>) {
8-
let mut outer_visitor = OuterVisitor {
9-
hir_map,
10-
errors: vec![],
11-
};
12-
139
hir_map.dep_graph.assert_ignored();
1410

15-
hir_map.krate().visit_all_item_likes(&mut outer_visitor);
16-
if !outer_visitor.errors.is_empty() {
17-
let message = outer_visitor
18-
.errors
11+
let errors = Lock::new(Vec::new());
12+
13+
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
14+
hir_map.visit_item_likes_in_module(hir_map.local_def_id(*module_id), &mut OuterVisitor {
15+
hir_map,
16+
errors: &errors,
17+
});
18+
});
19+
20+
let errors = errors.into_inner();
21+
22+
if !errors.is_empty() {
23+
let message = errors
1924
.iter()
2025
.fold(String::new(), |s1, s2| s1 + "\n" + s2);
2126
bug!("{}", message);
@@ -26,12 +31,12 @@ struct HirIdValidator<'a, 'hir: 'a> {
2631
hir_map: &'a hir::map::Map<'hir>,
2732
owner_def_index: Option<DefIndex>,
2833
hir_ids_seen: FxHashMap<ItemLocalId, NodeId>,
29-
errors: Vec<String>,
34+
errors: &'a Lock<Vec<String>>,
3035
}
3136

3237
struct OuterVisitor<'a, 'hir: 'a> {
3338
hir_map: &'a hir::map::Map<'hir>,
34-
errors: Vec<String>,
39+
errors: &'a Lock<Vec<String>>,
3540
}
3641

3742
impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> {
@@ -42,7 +47,7 @@ impl<'a, 'hir: 'a> OuterVisitor<'a, 'hir> {
4247
hir_map,
4348
owner_def_index: None,
4449
hir_ids_seen: Default::default(),
45-
errors: Vec::new(),
50+
errors: self.errors,
4651
}
4752
}
4853
}
@@ -51,23 +56,25 @@ impl<'a, 'hir: 'a> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
5156
fn visit_item(&mut self, i: &'hir hir::Item) {
5257
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
5358
inner_visitor.check(i.id, |this| intravisit::walk_item(this, i));
54-
self.errors.extend(inner_visitor.errors.drain(..));
5559
}
5660

5761
fn visit_trait_item(&mut self, i: &'hir hir::TraitItem) {
5862
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
5963
inner_visitor.check(i.id, |this| intravisit::walk_trait_item(this, i));
60-
self.errors.extend(inner_visitor.errors.drain(..));
6164
}
6265

6366
fn visit_impl_item(&mut self, i: &'hir hir::ImplItem) {
6467
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
6568
inner_visitor.check(i.id, |this| intravisit::walk_impl_item(this, i));
66-
self.errors.extend(inner_visitor.errors.drain(..));
6769
}
6870
}
6971

7072
impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
73+
#[cold]
74+
#[inline(never)]
75+
fn error(&self, f: impl FnOnce() -> String) {
76+
self.errors.lock().push(f());
77+
}
7178

7279
fn check<F: FnOnce(&mut HirIdValidator<'a, 'hir>)>(&mut self,
7380
node_id: NodeId,
@@ -119,7 +126,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
119126
local_id,
120127
self.hir_map.node_to_string(node_id)));
121128
}
122-
self.errors.push(format!(
129+
self.error(|| format!(
123130
"ItemLocalIds not assigned densely in {}. \
124131
Max ItemLocalId = {}, missing IDs = {:?}; seens IDs = {:?}",
125132
self.hir_map.def_path(DefId::local(owner_def_index)).to_string_no_crate(),
@@ -145,14 +152,14 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
145152
let stable_id = self.hir_map.definitions().node_to_hir_id[node_id];
146153

147154
if stable_id == hir::DUMMY_HIR_ID {
148-
self.errors.push(format!("HirIdValidator: No HirId assigned for NodeId {}: {:?}",
155+
self.error(|| format!("HirIdValidator: No HirId assigned for NodeId {}: {:?}",
149156
node_id,
150157
self.hir_map.node_to_string(node_id)));
151158
return;
152159
}
153160

154161
if owner != stable_id.owner {
155-
self.errors.push(format!(
162+
self.error(|| format!(
156163
"HirIdValidator: The recorded owner of {} is {} instead of {}",
157164
self.hir_map.node_to_string(node_id),
158165
self.hir_map.def_path(DefId::local(stable_id.owner)).to_string_no_crate(),
@@ -161,7 +168,7 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
161168

162169
if let Some(prev) = self.hir_ids_seen.insert(stable_id.local_id, node_id) {
163170
if prev != node_id {
164-
self.errors.push(format!(
171+
self.error(|| format!(
165172
"HirIdValidator: Same HirId {}/{} assigned for nodes {} and {}",
166173
self.hir_map.def_path(DefId::local(stable_id.owner)).to_string_no_crate(),
167174
stable_id.local_id.as_usize(),

src/librustc/hir/map/mod.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use dep_graph::{DepGraph, DepNode, DepKind, DepNodeIndex};
77

88
use hir::def_id::{CRATE_DEF_INDEX, DefId, LocalDefId, DefIndexAddressSpace};
99

10-
use middle::cstore::CrateStore;
10+
use middle::cstore::CrateStoreDyn;
1111

1212
use rustc_target::spec::abi::Abi;
1313
use rustc_data_structures::svh::Svh;
14+
use rustc_data_structures::sync::join;
1415
use syntax::ast::{self, Name, NodeId, CRATE_NODE_ID};
1516
use syntax::source_map::Spanned;
1617
use syntax::ext::base::MacroKind;
@@ -20,6 +21,7 @@ use hir::*;
2021
use hir::itemlikevisit::ItemLikeVisitor;
2122
use hir::print::Nested;
2223
use util::nodemap::FxHashMap;
24+
use util::common::time;
2325

2426
use std::io;
2527
use std::result::Result::Err;
@@ -1045,26 +1047,32 @@ impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
10451047
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
10461048

10471049
pub fn map_crate<'hir>(sess: &::session::Session,
1048-
cstore: &dyn CrateStore,
1049-
forest: &'hir mut Forest,
1050+
cstore: &CrateStoreDyn,
1051+
forest: &'hir Forest,
10501052
definitions: &'hir Definitions)
10511053
-> Map<'hir> {
1052-
let (map, crate_hash) = {
1054+
let ((map, crate_hash), hir_to_node_id) = join(|| {
10531055
let hcx = ::ich::StableHashingContext::new(sess, &forest.krate, definitions, cstore);
10541056

1055-
let mut collector = NodeCollector::root(&forest.krate,
1057+
let mut collector = NodeCollector::root(sess,
1058+
&forest.krate,
10561059
&forest.dep_graph,
10571060
&definitions,
1058-
hcx,
1059-
sess.source_map());
1061+
hcx);
10601062
intravisit::walk_crate(&mut collector, &forest.krate);
10611063

10621064
let crate_disambiguator = sess.local_crate_disambiguator();
10631065
let cmdline_args = sess.opts.dep_tracking_hash();
1064-
collector.finalize_and_compute_crate_hash(crate_disambiguator,
1065-
cstore,
1066-
cmdline_args)
1067-
};
1066+
collector.finalize_and_compute_crate_hash(
1067+
crate_disambiguator,
1068+
cstore,
1069+
cmdline_args
1070+
)
1071+
}, || {
1072+
// Build the reverse mapping of `node_to_hir_id`.
1073+
definitions.node_to_hir_id.iter_enumerated()
1074+
.map(|(node_id, &hir_id)| (hir_id, node_id)).collect()
1075+
});
10681076

10691077
if log_enabled!(::log::Level::Debug) {
10701078
// This only makes sense for ordered stores; note the
@@ -1078,10 +1086,6 @@ pub fn map_crate<'hir>(sess: &::session::Session,
10781086
entries, vector_length, (entries as f64 / vector_length as f64) * 100.);
10791087
}
10801088

1081-
// Build the reverse mapping of `node_to_hir_id`.
1082-
let hir_to_node_id = definitions.node_to_hir_id.iter_enumerated()
1083-
.map(|(node_id, &hir_id)| (hir_id, node_id)).collect();
1084-
10851089
let map = Map {
10861090
forest,
10871091
dep_graph: forest.dep_graph.clone(),
@@ -1091,7 +1095,9 @@ pub fn map_crate<'hir>(sess: &::session::Session,
10911095
definitions,
10921096
};
10931097

1094-
hir_id_validator::check_crate(&map);
1098+
time(sess, "validate hir map", || {
1099+
hir_id_validator::check_crate(&map);
1100+
});
10951101

10961102
map
10971103
}

src/librustc/session/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ impl Session {
407407
pub fn next_node_id(&self) -> NodeId {
408408
self.reserve_node_ids(1)
409409
}
410+
pub(crate) fn current_node_id_count(&self) -> usize {
411+
self.next_node_id.get().as_u32() as usize
412+
}
410413
pub fn diagnostic<'a>(&'a self) -> &'a errors::Handler {
411414
&self.parse_sess.span_diagnostic
412415
}

src/librustc_codegen_utils/codegen_backend.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use rustc::middle::cstore::EncodedMetadata;
3131
use rustc::middle::cstore::MetadataLoader;
3232
use rustc::dep_graph::DepGraph;
3333
use rustc_target::spec::Target;
34-
use rustc_mir::monomorphize::collector;
3534
use link::out_filename;
3635

3736
pub use rustc_data_structures::sync::MetadataRef;
@@ -136,25 +135,15 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
136135
::symbol_names_test::report_symbol_names(tcx);
137136
::rustc_incremental::assert_dep_graph(tcx);
138137
::rustc_incremental::assert_module_sources::assert_module_sources(tcx);
139-
::rustc_mir::monomorphize::assert_symbols_are_distinct(tcx,
140-
collector::collect_crate_mono_items(
141-
tcx,
142-
collector::MonoItemCollectionMode::Eager
143-
).0.iter()
144-
);
145138
// FIXME: Fix this
146139
// ::rustc::middle::dependency_format::calculate(tcx);
147140
let _ = tcx.link_args(LOCAL_CRATE);
148141
let _ = tcx.native_libraries(LOCAL_CRATE);
149-
for mono_item in
150-
collector::collect_crate_mono_items(
151-
tcx,
152-
collector::MonoItemCollectionMode::Eager
153-
).0 {
142+
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
143+
for (mono_item, _) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
154144
if let MonoItem::Fn(inst) = mono_item {
155145
let def_id = inst.def_id();
156-
if def_id.is_local() {
157-
let _ = inst.def.is_inline(tcx);
146+
if def_id.is_local() {
158147
let _ = tcx.codegen_fn_attrs(def_id);
159148
}
160149
}

src/librustc_privacy/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod diagnostics;
4848
/// Default type visitor (`TypeVisitor`) does most of the job, but it has some shortcomings.
4949
/// First, it doesn't have overridable `fn visit_trait_ref`, so we have to catch trait def-ids
5050
/// manually. Second, it doesn't visit some type components like signatures of fn types, or traits
51-
/// in `impl Trait`, see individual commits in `DefIdVisitorSkeleton::visit_ty`.
51+
/// in `impl Trait`, see individual comments in `DefIdVisitorSkeleton::visit_ty`.
5252
trait DefIdVisitor<'a, 'tcx: 'a> {
5353
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
5454
fn shallow(&self) -> bool { false }
@@ -1579,10 +1579,15 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
15791579
// No subitems.
15801580
hir::ItemKind::GlobalAsm(..) => {}
15811581
// Subitems of these items have inherited publicity.
1582-
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) | hir::ItemKind::Fn(..) |
1583-
hir::ItemKind::Existential(..) | hir::ItemKind::Ty(..) => {
1582+
hir::ItemKind::Const(..) | hir::ItemKind::Static(..) |
1583+
hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => {
15841584
self.check(item.id, item_visibility).generics().predicates().ty();
15851585
}
1586+
hir::ItemKind::Existential(..) => {
1587+
// `ty()` for existential types is the underlying type,
1588+
// it's not a part of interface, so we skip it.
1589+
self.check(item.id, item_visibility).generics().predicates();
1590+
}
15861591
hir::ItemKind::Trait(.., ref trait_item_refs) => {
15871592
self.check(item.id, item_visibility).generics().predicates();
15881593

0 commit comments

Comments
 (0)