Skip to content

Commit 2cb4e7d

Browse files
committed
Auto merge of #147340 - matthiaskrgr:rollup-icymmsc, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #142670 (Document fully-qualified syntax in `as`' keyword doc) - #145685 (add CloneFromCell and Cell::get_cloned) - #146330 (Bump unicode_data and printables to version 17.0.0) - #146451 (Fix atan2 inaccuracy in documentation) - #146479 (add mem::conjure_zst) - #147117 (interpret `#[used]` as `#[used(compiler)]` on illumos) - #147190 (std: `sys::net` cleanups) - #147251 (Do not assert that a change in global cache only happens when concurrent) - #147280 (Return to needs-llvm-components being info-only) - #147315 (bless autodiff batching test) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 99ca0ae + a84359c commit 2cb4e7d

File tree

37 files changed

+1141
-754
lines changed

37 files changed

+1141
-754
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
370370
pub(crate) struct UsedParser {
371371
first_compiler: Option<Span>,
372372
first_linker: Option<Span>,
373+
first_default: Option<Span>,
373374
}
374375

375376
// A custom `AttributeParser` is used rather than a Simple attribute parser because
@@ -382,7 +383,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
382383
template!(Word, List: &["compiler", "linker"]),
383384
|group: &mut Self, cx, args| {
384385
let used_by = match args {
385-
ArgParser::NoArgs => UsedBy::Linker,
386+
ArgParser::NoArgs => UsedBy::Default,
386387
ArgParser::List(list) => {
387388
let Some(l) = list.single() else {
388389
cx.expected_single_argument(list.span);
@@ -423,12 +424,29 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
423424
ArgParser::NameValue(_) => return,
424425
};
425426

427+
let attr_span = cx.attr_span;
428+
429+
// `#[used]` is interpreted as `#[used(linker)]` (though depending on target OS the
430+
// circumstances are more complicated). While we're checking `used_by`, also report
431+
// these cross-`UsedBy` duplicates to warn.
426432
let target = match used_by {
427433
UsedBy::Compiler => &mut group.first_compiler,
428-
UsedBy::Linker => &mut group.first_linker,
434+
UsedBy::Linker => {
435+
if let Some(prev) = group.first_default {
436+
cx.warn_unused_duplicate(prev, attr_span);
437+
return;
438+
}
439+
&mut group.first_linker
440+
}
441+
UsedBy::Default => {
442+
if let Some(prev) = group.first_linker {
443+
cx.warn_unused_duplicate(prev, attr_span);
444+
return;
445+
}
446+
&mut group.first_default
447+
}
429448
};
430449

431-
let attr_span = cx.attr_span;
432450
if let Some(prev) = *target {
433451
cx.warn_unused_duplicate(prev, attr_span);
434452
} else {
@@ -440,11 +458,13 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
440458
AllowedTargets::AllowList(&[Allow(Target::Static), Warn(Target::MacroCall)]);
441459

442460
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
443-
// Ratcheting behaviour, if both `linker` and `compiler` are specified, use `linker`
444-
Some(match (self.first_compiler, self.first_linker) {
445-
(_, Some(span)) => AttributeKind::Used { used_by: UsedBy::Linker, span },
446-
(Some(span), _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
447-
(None, None) => return None,
461+
// If a specific form of `used` is specified, it takes precedence over generic `#[used]`.
462+
// If both `linker` and `compiler` are specified, use `linker`.
463+
Some(match (self.first_compiler, self.first_linker, self.first_default) {
464+
(_, Some(span), _) => AttributeKind::Used { used_by: UsedBy::Linker, span },
465+
(Some(span), _, _) => AttributeKind::Used { used_by: UsedBy::Compiler, span },
466+
(_, _, Some(span)) => AttributeKind::Used { used_by: UsedBy::Default, span },
467+
(None, None, None) => return None,
448468
})
449469
}
450470
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,19 @@ fn process_builtin_attrs(
263263
AttributeKind::Used { used_by, .. } => match used_by {
264264
UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER,
265265
UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER,
266+
UsedBy::Default => {
267+
let used_form = if tcx.sess.target.os == "illumos" {
268+
// illumos' `ld` doesn't support a section header that would represent
269+
// `#[used(linker)]`, see
270+
// https://github.com/rust-lang/rust/issues/146169. For that target,
271+
// downgrade as if `#[used(compiler)]` was requested and hope for the
272+
// best.
273+
CodegenFnAttrFlags::USED_COMPILER
274+
} else {
275+
CodegenFnAttrFlags::USED_LINKER
276+
};
277+
codegen_fn_attrs.flags |= used_form;
278+
}
266279
},
267280
AttributeKind::FfiConst(_) => {
268281
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ impl Deprecation {
146146
}
147147

148148
/// There are three valid forms of the attribute:
149-
/// `#[used]`, which is semantically equivalent to `#[used(linker)]` except that the latter is currently unstable.
149+
/// `#[used]`, which is equivalent to `#[used(linker)]` on targets that support it, but `#[used(compiler)]` if not.
150150
/// `#[used(compiler)]`
151151
/// `#[used(linker)]`
152152
#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
153153
#[derive(HashStable_Generic, PrintAttribute)]
154154
pub enum UsedBy {
155+
Default,
155156
Compiler,
156157
Linker,
157158
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
207207
from_entry(entry)
208208
}
209209

210-
fn evaluation_is_concurrent(&self) -> bool {
211-
self.sess.threads() > 1
210+
fn assert_evaluation_is_concurrent(&self) {
211+
// Turns out, the assumption for this function isn't perfect.
212+
// See trait-system-refactor-initiative#234.
212213
}
213214

214215
fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {

compiler/rustc_type_ir/src/interner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ pub trait Interner:
183183
from_entry: impl FnOnce(&CanonicalParamEnvCacheEntry<Self>) -> R,
184184
) -> R;
185185

186-
fn evaluation_is_concurrent(&self) -> bool;
186+
/// Useful for testing. If a cache entry is replaced, this should
187+
/// (in theory) only happen when concurrent.
188+
fn assert_evaluation_is_concurrent(&self);
187189

188190
fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;
189191

@@ -567,7 +569,7 @@ impl<I: Interner> search_graph::Cx for I {
567569
fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
568570
I::with_global_cache(self, f)
569571
}
570-
fn evaluation_is_concurrent(&self) -> bool {
571-
self.evaluation_is_concurrent()
572+
fn assert_evaluation_is_concurrent(&self) {
573+
self.assert_evaluation_is_concurrent()
572574
}
573575
}

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ impl<X: Cx> GlobalCache<X> {
5656
let with_overflow = WithOverflow { nested_goals, result };
5757
let prev = entry.with_overflow.insert(required_depth, with_overflow);
5858
if let Some(prev) = &prev {
59-
assert!(cx.evaluation_is_concurrent());
59+
cx.assert_evaluation_is_concurrent();
6060
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6161
}
6262
} else {
6363
let prev = entry.success.replace(Success { required_depth, nested_goals, result });
6464
if let Some(prev) = &prev {
65-
assert!(cx.evaluation_is_concurrent());
65+
cx.assert_evaluation_is_concurrent();
6666
assert_eq!(cx.get_tracked(&prev.result), evaluation_result.result);
6767
}
6868
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub trait Cx: Copy {
5353

5454
fn with_global_cache<R>(self, f: impl FnOnce(&mut GlobalCache<Self>) -> R) -> R;
5555

56-
fn evaluation_is_concurrent(&self) -> bool;
56+
fn assert_evaluation_is_concurrent(&self);
5757
}
5858

5959
pub trait Delegate: Sized {

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#![feature(bstr)]
9797
#![feature(bstr_internals)]
9898
#![feature(cast_maybe_uninit)]
99+
#![feature(cell_get_cloned)]
99100
#![feature(char_internals)]
100101
#![feature(char_max_len)]
101102
#![feature(clone_to_uninit)]

library/alloc/src/rc.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
#![stable(feature = "rust1", since = "1.0.0")]
243243

244244
use core::any::Any;
245-
use core::cell::Cell;
245+
use core::cell::{Cell, CloneFromCell};
246246
#[cfg(not(no_global_oom_handling))]
247247
use core::clone::CloneToUninit;
248248
use core::clone::UseCloned;
@@ -340,6 +340,10 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Rc<U, A>> for
340340
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
341341
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T> {}
342342

343+
// SAFETY: `Rc::clone` doesn't access any `Cell`s which could contain the `Rc` being cloned.
344+
#[unstable(feature = "cell_get_cloned", issue = "145329")]
345+
unsafe impl<T: ?Sized> CloneFromCell for Rc<T> {}
346+
343347
impl<T: ?Sized> Rc<T> {
344348
#[inline]
345349
unsafe fn from_inner(ptr: NonNull<RcInner<T>>) -> Self {
@@ -3013,6 +3017,10 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Weak<U, A>> f
30133017
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
30143018
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
30153019

3020+
// SAFETY: `Weak::clone` doesn't access any `Cell`s which could contain the `Weak` being cloned.
3021+
#[unstable(feature = "cell_get_cloned", issue = "145329")]
3022+
unsafe impl<T: ?Sized> CloneFromCell for Weak<T> {}
3023+
30163024
impl<T> Weak<T> {
30173025
/// Constructs a new `Weak<T>`, without allocating any memory.
30183026
/// Calling [`upgrade`] on the return value always gives [`None`].

library/alloc/src/sync.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! `#[cfg(target_has_atomic = "ptr")]`.
1010
1111
use core::any::Any;
12+
use core::cell::CloneFromCell;
1213
#[cfg(not(no_global_oom_handling))]
1314
use core::clone::CloneToUninit;
1415
use core::clone::UseCloned;
@@ -281,6 +282,10 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Arc<U, A>> fo
281282
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
282283
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Arc<U>> for Arc<T> {}
283284

285+
// SAFETY: `Arc::clone` doesn't access any `Cell`s which could contain the `Arc` being cloned.
286+
#[unstable(feature = "cell_get_cloned", issue = "145329")]
287+
unsafe impl<T: ?Sized> CloneFromCell for Arc<T> {}
288+
284289
impl<T: ?Sized> Arc<T> {
285290
unsafe fn from_inner(ptr: NonNull<ArcInner<T>>) -> Self {
286291
unsafe { Self::from_inner_in(ptr, Global) }
@@ -356,6 +361,10 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Weak<U, A>> f
356361
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
357362
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Weak<U>> for Weak<T> {}
358363

364+
// SAFETY: `Weak::clone` doesn't access any `Cell`s which could contain the `Weak` being cloned.
365+
#[unstable(feature = "cell_get_cloned", issue = "145329")]
366+
unsafe impl<T: ?Sized> CloneFromCell for Weak<T> {}
367+
359368
#[stable(feature = "arc_weak", since = "1.4.0")]
360369
impl<T: ?Sized, A: Allocator> fmt::Debug for Weak<T, A> {
361370
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

0 commit comments

Comments
 (0)