Skip to content

Commit c1d3610

Browse files
committed
Auto merge of rust-lang#109791 - compiler-errors:rollup-c3o710k, r=compiler-errors
Rollup of 6 pull requests Successful merges: - rust-lang#109347 (Skip no_mangle if the item has no name.) - rust-lang#109522 (Implement current_dll_path for AIX) - rust-lang#109679 (Freshen normalizes-to hack goal RHS in the evaluate loop) - rust-lang#109704 (resolve: Minor improvements to effective visibilities) - rust-lang#109739 (Closures always implement `FnOnce` in new solver) - rust-lang#109758 (Parallel compiler cleanups) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ec2f40c + 249198c commit c1d3610

File tree

17 files changed

+321
-217
lines changed

17 files changed

+321
-217
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+46-69
Original file line numberDiff line numberDiff line change
@@ -89,44 +89,39 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
8989
};
9090

9191
match name {
92-
sym::cold => {
93-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
94-
}
95-
sym::rustc_allocator => {
96-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR;
97-
}
92+
sym::cold => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
93+
sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
9894
sym::ffi_returns_twice => {
99-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_RETURNS_TWICE;
100-
}
101-
sym::ffi_pure => {
102-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE;
103-
}
104-
sym::ffi_const => {
105-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST;
106-
}
107-
sym::rustc_nounwind => {
108-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
109-
}
110-
sym::rustc_reallocator => {
111-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR;
112-
}
113-
sym::rustc_deallocator => {
114-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR;
95+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_RETURNS_TWICE
11596
}
97+
sym::ffi_pure => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
98+
sym::ffi_const => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST,
99+
sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
100+
sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
101+
sym::rustc_deallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR,
116102
sym::rustc_allocator_zeroed => {
117-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED;
118-
}
119-
sym::naked => {
120-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED;
103+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
121104
}
105+
sym::naked => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
122106
sym::no_mangle => {
123-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
124-
}
125-
sym::no_coverage => {
126-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
107+
if tcx.opt_item_name(did.to_def_id()).is_some() {
108+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE
109+
} else {
110+
tcx.sess
111+
.struct_span_err(
112+
attr.span,
113+
format!(
114+
"`#[no_mangle]` cannot be used on {} {} as it has no name",
115+
tcx.def_descr_article(did.to_def_id()),
116+
tcx.def_descr(did.to_def_id()),
117+
),
118+
)
119+
.emit();
120+
}
127121
}
122+
sym::no_coverage => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE,
128123
sym::rustc_std_internal_symbol => {
129-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
124+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
130125
}
131126
sym::used => {
132127
let inner = attr.meta_item_list();
@@ -207,11 +202,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
207202
struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension")
208203
.emit();
209204
}
210-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY;
211-
}
212-
sym::thread_local => {
213-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
205+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY
214206
}
207+
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
215208
sym::track_caller => {
216209
if !tcx.is_closure(did.to_def_id())
217210
&& let Some(fn_sig) = fn_sig()
@@ -229,7 +222,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
229222
)
230223
.emit();
231224
}
232-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
225+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER
233226
}
234227
sym::export_name => {
235228
if let Some(s) = attr.value_str() {
@@ -306,20 +299,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
306299
sym::link_section => {
307300
if let Some(val) = attr.value_str() {
308301
if val.as_str().bytes().any(|b| b == 0) {
309-
let msg = format!(
310-
"illegal null byte in link_section \
311-
value: `{}`",
312-
&val
313-
);
302+
let msg = format!("illegal null byte in link_section value: `{}`", &val);
314303
tcx.sess.span_err(attr.span, &msg);
315304
} else {
316305
codegen_fn_attrs.link_section = Some(val);
317306
}
318307
}
319308
}
320-
sym::link_name => {
321-
codegen_fn_attrs.link_name = attr.value_str();
322-
}
309+
sym::link_name => codegen_fn_attrs.link_name = attr.value_str(),
323310
sym::link_ordinal => {
324311
link_ordinal_span = Some(attr.span);
325312
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
@@ -330,37 +317,27 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
330317
no_sanitize_span = Some(attr.span);
331318
if let Some(list) = attr.meta_item_list() {
332319
for item in list.iter() {
333-
match item.ident().map(|ident| ident.name) {
334-
Some(sym::address) => {
320+
match item.name_or_empty() {
321+
sym::address => {
335322
codegen_fn_attrs.no_sanitize |=
336-
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS;
337-
}
338-
Some(sym::cfi) => {
339-
codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI;
323+
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
340324
}
341-
Some(sym::kcfi) => {
342-
codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI;
325+
sym::cfi => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
326+
sym::kcfi => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
327+
sym::memory => codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY,
328+
sym::memtag => codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG,
329+
sym::shadow_call_stack => {
330+
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK
343331
}
344-
Some(sym::memory) => {
345-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY;
346-
}
347-
Some(sym::memtag) => {
348-
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG;
349-
}
350-
Some(sym::shadow_call_stack) => {
351-
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK;
352-
}
353-
Some(sym::thread) => {
354-
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD;
355-
}
356-
Some(sym::hwaddress) => {
357-
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS;
332+
sym::thread => codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD,
333+
sym::hwaddress => {
334+
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS
358335
}
359336
_ => {
360337
tcx.sess
361-
.struct_span_err(item.span(), "invalid argument for `no_sanitize`")
362-
.note("expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`")
363-
.emit();
338+
.struct_span_err(item.span(), "invalid argument for `no_sanitize`")
339+
.note("expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`")
340+
.emit();
364341
}
365342
}
366343
}

compiler/rustc_data_structures/src/sharded.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::collections::hash_map::RawEntryMut;
55
use std::hash::{Hash, Hasher};
66
use std::mem;
77

8-
#[derive(Clone, Default)]
8+
#[derive(Default)]
99
#[cfg_attr(parallel_compiler, repr(align(64)))]
1010
struct CacheAligned<T>(T);
1111

@@ -21,7 +21,6 @@ const SHARD_BITS: usize = 0;
2121
pub const SHARDS: usize = 1 << SHARD_BITS;
2222

2323
/// An array of cache-line aligned inner locked structures with convenience methods.
24-
#[derive(Clone)]
2524
pub struct Sharded<T> {
2625
shards: [CacheAligned<Lock<T>>; SHARDS],
2726
}

compiler/rustc_data_structures/src/sync.rs

+39-26
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
1-
//! This module defines types which are thread safe if cfg!(parallel_compiler) is true.
1+
//! This module defines various operations and types that are implemented in
2+
//! one way for the serial compiler, and another way the parallel compiler.
23
//!
3-
//! `Lrc` is an alias of `Arc` if cfg!(parallel_compiler) is true, `Rc` otherwise.
4+
//! Operations
5+
//! ----------
6+
//! The parallel versions of operations use Rayon to execute code in parallel,
7+
//! while the serial versions degenerate straightforwardly to serial execution.
8+
//! The operations include `join`, `parallel`, `par_iter`, and `par_for_each`.
49
//!
5-
//! `Lock` is a mutex.
6-
//! It internally uses `parking_lot::Mutex` if cfg!(parallel_compiler) is true,
7-
//! `RefCell` otherwise.
10+
//! `rustc_erase_owner!` erases an `OwningRef` owner into `Erased` for the
11+
//! serial version and `Erased + Send + Sync` for the parallel version.
812
//!
9-
//! `RwLock` is a read-write lock.
10-
//! It internally uses `parking_lot::RwLock` if cfg!(parallel_compiler) is true,
11-
//! `RefCell` otherwise.
13+
//! Types
14+
//! -----
15+
//! The parallel versions of types provide various kinds of synchronization,
16+
//! while the serial compiler versions do not.
1217
//!
13-
//! `MTLock` is a mutex which disappears if cfg!(parallel_compiler) is false.
18+
//! The following table shows how the types are implemented internally. Except
19+
//! where noted otherwise, the type in column one is defined as a
20+
//! newtype around the type from column two or three.
1421
//!
15-
//! `MTRef` is an immutable reference if cfg!(parallel_compiler), and a mutable reference otherwise.
22+
//! | Type | Serial version | Parallel version |
23+
//! | ----------------------- | ------------------- | ------------------------------- |
24+
//! | `Lrc<T>` | `rc::Rc<T>` | `sync::Arc<T>` |
25+
//! |` Weak<T>` | `rc::Weak<T>` | `sync::Weak<T>` |
26+
//! | | | |
27+
//! | `AtomicBool` | `Cell<bool>` | `atomic::AtomicBool` |
28+
//! | `AtomicU32` | `Cell<u32>` | `atomic::AtomicU32` |
29+
//! | `AtomicU64` | `Cell<u64>` | `atomic::AtomicU64` |
30+
//! | `AtomicUsize` | `Cell<usize>` | `atomic::AtomicUsize` |
31+
//! | | | |
32+
//! | `Lock<T>` | `RefCell<T>` | `parking_lot::Mutex<T>` |
33+
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
34+
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
35+
//! | `MTLockRef<'a, T>` [^2] | `&'a mut MTLock<T>` | `&'a MTLock<T>` |
36+
//! | | | |
37+
//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
1638
//!
17-
//! `rustc_erase_owner!` erases an OwningRef owner into Erased or Erased + Send + Sync
18-
//! depending on the value of cfg!(parallel_compiler).
39+
//! [^1] `MTLock` is similar to `Lock`, but the serial version avoids the cost
40+
//! of a `RefCell`. This is appropriate when interior mutability is not
41+
//! required.
42+
//!
43+
//! [^2] `MTLockRef` is a typedef.
1944
2045
use crate::owning_ref::{Erased, OwningRef};
2146
use std::collections::HashMap;
@@ -209,7 +234,7 @@ cfg_if! {
209234
}
210235
}
211236

212-
pub type MTRef<'a, T> = &'a mut T;
237+
pub type MTLockRef<'a, T> = &'a mut MTLock<T>;
213238

214239
#[derive(Debug, Default)]
215240
pub struct MTLock<T>(T);
@@ -267,7 +292,7 @@ cfg_if! {
267292
pub use std::sync::Arc as Lrc;
268293
pub use std::sync::Weak as Weak;
269294

270-
pub type MTRef<'a, T> = &'a T;
295+
pub type MTLockRef<'a, T> = &'a MTLock<T>;
271296

272297
#[derive(Debug, Default)]
273298
pub struct MTLock<T>(Lock<T>);
@@ -553,18 +578,6 @@ impl<T> RwLock<T> {
553578
self.write()
554579
}
555580

556-
#[cfg(not(parallel_compiler))]
557-
#[inline(always)]
558-
pub fn clone_guard<'a>(rg: &ReadGuard<'a, T>) -> ReadGuard<'a, T> {
559-
ReadGuard::clone(rg)
560-
}
561-
562-
#[cfg(parallel_compiler)]
563-
#[inline(always)]
564-
pub fn clone_guard<'a>(rg: &ReadGuard<'a, T>) -> ReadGuard<'a, T> {
565-
ReadGuard::rwlock(&rg).read()
566-
}
567-
568581
#[cfg(not(parallel_compiler))]
569582
#[inline(always)]
570583
pub fn leak(&self) -> &T {

compiler/rustc_middle/src/middle/privacy.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_macros::HashStable;
88
use rustc_query_system::ich::StableHashingContext;
9-
use rustc_span::def_id::LocalDefId;
9+
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
1010
use std::hash::Hash;
1111

1212
/// Represents the levels of effective visibility an item can have.
@@ -107,6 +107,10 @@ impl EffectiveVisibilities {
107107
})
108108
}
109109

110+
pub fn update_root(&mut self) {
111+
self.map.insert(CRATE_DEF_ID, EffectiveVisibility::from_vis(Visibility::Public));
112+
}
113+
110114
// FIXME: Share code with `fn update`.
111115
pub fn update_eff_vis(
112116
&mut self,

compiler/rustc_monomorphize/src/collector.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
//! regardless of whether it is actually needed or not.
175175
176176
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
177-
use rustc_data_structures::sync::{par_for_each_in, MTLock, MTRef};
177+
use rustc_data_structures::sync::{par_for_each_in, MTLock, MTLockRef};
178178
use rustc_hir as hir;
179179
use rustc_hir::def::DefKind;
180180
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
@@ -341,8 +341,8 @@ pub fn collect_crate_mono_items(
341341
let recursion_limit = tcx.recursion_limit();
342342

343343
{
344-
let visited: MTRef<'_, _> = &mut visited;
345-
let inlining_map: MTRef<'_, _> = &mut inlining_map;
344+
let visited: MTLockRef<'_, _> = &mut visited;
345+
let inlining_map: MTLockRef<'_, _> = &mut inlining_map;
346346

347347
tcx.sess.time("monomorphization_collector_graph_walk", || {
348348
par_for_each_in(roots, |root| {
@@ -407,10 +407,10 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
407407
fn collect_items_rec<'tcx>(
408408
tcx: TyCtxt<'tcx>,
409409
starting_point: Spanned<MonoItem<'tcx>>,
410-
visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
410+
visited: MTLockRef<'_, FxHashSet<MonoItem<'tcx>>>,
411411
recursion_depths: &mut DefIdMap<usize>,
412412
recursion_limit: Limit,
413-
inlining_map: MTRef<'_, MTLock<InliningMap<'tcx>>>,
413+
inlining_map: MTLockRef<'_, InliningMap<'tcx>>,
414414
) {
415415
if !visited.lock_mut().insert(starting_point.node) {
416416
// We've been here already, no need to search again.

compiler/rustc_privacy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,7 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
21492149

21502150
let mut check_visitor =
21512151
TestReachabilityVisitor { tcx, effective_visibilities: &visitor.effective_visibilities };
2152+
check_visitor.effective_visibility_diagnostic(CRATE_DEF_ID);
21522153
tcx.hir().visit_all_item_likes_in_crate(&mut check_visitor);
21532154

21542155
tcx.arena.alloc(visitor.effective_visibilities)

compiler/rustc_query_system/src/query/caches.rs

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ pub trait QueryCache: Sized {
2121
type Value: Copy + Debug;
2222

2323
/// Checks if the query is already computed and in the cache.
24-
/// It returns the shard index and a lock guard to the shard,
25-
/// which will be used if the query is not in the cache and we need
26-
/// to compute it.
2724
fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>;
2825

2926
fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex);

0 commit comments

Comments
 (0)