Skip to content

Commit 18890f0

Browse files
committed
Auto merge of #107343 - JohnTitor:rollup-s6l94aj, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #105784 (update stdarch) - #106856 (core: Support variety of atomic widths in width-agnostic functions) - #107171 (rustc_metadata: Fix `encode_attrs`) - #107242 (rustdoc: make item links consistently use `title="{shortty} {path}"`) - #107279 (Use new solver during selection) - #107284 (rustdoc: use smarter encoding for playground URL) - #107325 (rustdoc: Stop using `HirId`s) - #107336 (rustdoc: remove mostly-unused CSS classes `import-item` and `module-item`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents db137ba + 17a2e1f commit 18890f0

38 files changed

+302
-253
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+48-29
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::rmeta::def_path_hash_map::DefPathHashMapRef;
33
use crate::rmeta::table::TableBuilder;
44
use crate::rmeta::*;
55

6+
use rustc_ast::util::comments;
67
use rustc_ast::Attribute;
78
use rustc_data_structures::fingerprint::Fingerprint;
89
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
@@ -759,36 +760,54 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
759760
}
760761
}
761762

763+
struct AnalyzeAttrState {
764+
is_exported: bool,
765+
may_have_doc_links: bool,
766+
is_doc_hidden: bool,
767+
}
768+
762769
/// Returns whether an attribute needs to be recorded in metadata, that is, if it's usable and
763770
/// useful in downstream crates. Local-only attributes are an obvious example, but some
764771
/// rustdoc-specific attributes can equally be of use while documenting the current crate only.
765772
///
766773
/// Removing these superfluous attributes speeds up compilation by making the metadata smaller.
767774
///
768-
/// Note: the `is_def_id_public` parameter is used to cache whether the given `DefId` has a public
775+
/// Note: the `is_exported` parameter is used to cache whether the given `DefId` has a public
769776
/// visibility: this is a piece of data that can be computed once per defid, and not once per
770777
/// attribute. Some attributes would only be usable downstream if they are public.
771778
#[inline]
772-
fn should_encode_attr(
773-
tcx: TyCtxt<'_>,
774-
attr: &Attribute,
775-
def_id: LocalDefId,
776-
is_def_id_public: &mut Option<bool>,
777-
) -> bool {
779+
fn analyze_attr(attr: &Attribute, state: &mut AnalyzeAttrState) -> bool {
780+
let mut should_encode = false;
778781
if rustc_feature::is_builtin_only_local(attr.name_or_empty()) {
779782
// Attributes marked local-only don't need to be encoded for downstream crates.
780-
false
781-
} else if attr.doc_str().is_some() {
782-
// We keep all public doc comments because they might be "imported" into downstream crates
783-
// if they use `#[doc(inline)]` to copy an item's documentation into their own.
784-
*is_def_id_public.get_or_insert_with(|| tcx.effective_visibilities(()).is_exported(def_id))
783+
} else if let Some(s) = attr.doc_str() {
784+
// We keep all doc comments reachable to rustdoc because they might be "imported" into
785+
// downstream crates if they use `#[doc(inline)]` to copy an item's documentation into
786+
// their own.
787+
if state.is_exported {
788+
should_encode = true;
789+
if comments::may_have_doc_links(s.as_str()) {
790+
state.may_have_doc_links = true;
791+
}
792+
}
785793
} else if attr.has_name(sym::doc) {
786-
// If this is a `doc` attribute, and it's marked `inline` (as in `#[doc(inline)]`), we can
787-
// remove it. It won't be inlinable in downstream crates.
788-
attr.meta_item_list().map(|l| l.iter().any(|l| !l.has_name(sym::inline))).unwrap_or(false)
794+
// If this is a `doc` attribute that doesn't have anything except maybe `inline` (as in
795+
// `#[doc(inline)]`), then we can remove it. It won't be inlinable in downstream crates.
796+
if let Some(item_list) = attr.meta_item_list() {
797+
for item in item_list {
798+
if !item.has_name(sym::inline) {
799+
should_encode = true;
800+
if item.has_name(sym::hidden) {
801+
state.is_doc_hidden = true;
802+
break;
803+
}
804+
}
805+
}
806+
}
789807
} else {
790-
true
808+
should_encode = true;
791809
}
810+
should_encode
792811
}
793812

794813
fn should_encode_visibility(def_kind: DefKind) -> bool {
@@ -1108,24 +1127,24 @@ fn should_encode_trait_impl_trait_tys(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
11081127
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11091128
fn encode_attrs(&mut self, def_id: LocalDefId) {
11101129
let tcx = self.tcx;
1111-
let mut is_public: Option<bool> = None;
1112-
1113-
let hir_attrs = tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(def_id));
1114-
let mut attrs = hir_attrs
1130+
let mut state = AnalyzeAttrState {
1131+
is_exported: tcx.effective_visibilities(()).is_exported(def_id),
1132+
may_have_doc_links: false,
1133+
is_doc_hidden: false,
1134+
};
1135+
let attr_iter = tcx
1136+
.hir()
1137+
.attrs(tcx.hir().local_def_id_to_hir_id(def_id))
11151138
.iter()
1116-
.filter(move |attr| should_encode_attr(tcx, attr, def_id, &mut is_public));
1139+
.filter(|attr| analyze_attr(attr, &mut state));
1140+
1141+
record_array!(self.tables.attributes[def_id.to_def_id()] <- attr_iter);
11171142

1118-
record_array!(self.tables.attributes[def_id.to_def_id()] <- attrs.clone());
11191143
let mut attr_flags = AttrFlags::empty();
1120-
if attrs.any(|attr| attr.may_have_doc_links()) {
1144+
if state.may_have_doc_links {
11211145
attr_flags |= AttrFlags::MAY_HAVE_DOC_LINKS;
11221146
}
1123-
if hir_attrs
1124-
.iter()
1125-
.filter(|attr| attr.has_name(sym::doc))
1126-
.filter_map(|attr| attr.meta_item_list())
1127-
.any(|items| items.iter().any(|item| item.has_name(sym::hidden)))
1128-
{
1147+
if state.is_doc_hidden {
11291148
attr_flags |= AttrFlags::IS_DOC_HIDDEN;
11301149
}
11311150
if !attr_flags.is_empty() {

compiler/rustc_session/src/config.rs

+8
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
945945
if sess.target.has_thread_local {
946946
ret.insert((sym::target_thread_local, None));
947947
}
948+
let mut has_atomic = false;
948949
for (i, align) in [
949950
(8, layout.i8_align.abi),
950951
(16, layout.i16_align.abi),
@@ -953,6 +954,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
953954
(128, layout.i128_align.abi),
954955
] {
955956
if i >= min_atomic_width && i <= max_atomic_width {
957+
has_atomic = true;
956958
let mut insert_atomic = |s, align: Align| {
957959
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
958960
if atomic_cas {
@@ -969,6 +971,12 @@ fn default_configuration(sess: &Session) -> CrateConfig {
969971
}
970972
}
971973
}
974+
if sess.is_nightly_build() && has_atomic {
975+
ret.insert((sym::target_has_atomic_load_store, None));
976+
if atomic_cas {
977+
ret.insert((sym::target_has_atomic, None));
978+
}
979+
}
972980

973981
let panic_strategy = sess.panic_strategy();
974982
ret.insert((sym::panic, Some(panic_strategy.desc_symbol())));

compiler/rustc_trait_selection/src/traits/select/mod.rs

+43-14
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ use rustc_errors::Diagnostic;
3838
use rustc_hir as hir;
3939
use rustc_hir::def_id::DefId;
4040
use rustc_infer::infer::LateBoundRegionConversionTime;
41+
use rustc_infer::traits::TraitEngine;
42+
use rustc_infer::traits::TraitEngineExt;
4143
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
4244
use rustc_middle::mir::interpret::ErrorHandled;
4345
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
@@ -47,6 +49,7 @@ use rustc_middle::ty::relate::TypeRelation;
4749
use rustc_middle::ty::SubstsRef;
4850
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
4951
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitable};
52+
use rustc_session::config::TraitSolver;
5053
use rustc_span::symbol::sym;
5154

5255
use std::cell::{Cell, RefCell};
@@ -544,10 +547,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
544547
obligation: &PredicateObligation<'tcx>,
545548
) -> Result<EvaluationResult, OverflowError> {
546549
self.evaluation_probe(|this| {
547-
this.evaluate_predicate_recursively(
548-
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
549-
obligation.clone(),
550-
)
550+
if this.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
551+
this.evaluate_predicate_recursively(
552+
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
553+
obligation.clone(),
554+
)
555+
} else {
556+
this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])
557+
}
551558
})
552559
}
553560

@@ -586,18 +593,40 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
586593
where
587594
I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
588595
{
589-
let mut result = EvaluatedToOk;
590-
for obligation in predicates {
591-
let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
592-
if let EvaluatedToErr = eval {
593-
// fast-path - EvaluatedToErr is the top of the lattice,
594-
// so we don't need to look on the other predicates.
595-
return Ok(EvaluatedToErr);
596-
} else {
597-
result = cmp::max(result, eval);
596+
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
597+
let mut result = EvaluatedToOk;
598+
for obligation in predicates {
599+
let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
600+
if let EvaluatedToErr = eval {
601+
// fast-path - EvaluatedToErr is the top of the lattice,
602+
// so we don't need to look on the other predicates.
603+
return Ok(EvaluatedToErr);
604+
} else {
605+
result = cmp::max(result, eval);
606+
}
598607
}
608+
Ok(result)
609+
} else {
610+
self.evaluate_predicates_recursively_in_new_solver(predicates)
599611
}
600-
Ok(result)
612+
}
613+
614+
/// Evaluates the predicates using the new solver when `-Ztrait-solver=next` is enabled
615+
fn evaluate_predicates_recursively_in_new_solver(
616+
&mut self,
617+
predicates: impl IntoIterator<Item = PredicateObligation<'tcx>>,
618+
) -> Result<EvaluationResult, OverflowError> {
619+
let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
620+
fulfill_cx.register_predicate_obligations(self.infcx, predicates);
621+
// True errors
622+
if !fulfill_cx.select_where_possible(self.infcx).is_empty() {
623+
return Ok(EvaluatedToErr);
624+
}
625+
if !fulfill_cx.select_all_or_error(self.infcx).is_empty() {
626+
return Ok(EvaluatedToAmbig);
627+
}
628+
// Regions and opaques are handled in the `evaluation_probe` by looking at the snapshot
629+
Ok(EvaluatedToOk)
601630
}
602631

603632
#[instrument(

library/core/src/sync/atomic.rs

+30-15
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,8 @@ macro_rules! if_not_8_bit {
18611861
($_:ident, $($tt:tt)*) => { $($tt)* };
18621862
}
18631863

1864-
#[cfg(target_has_atomic_load_store = "8")]
1864+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic_load_store))]
1865+
#[cfg_attr(bootstrap, cfg(target_has_atomic_load_store = "8"))]
18651866
macro_rules! atomic_int {
18661867
($cfg_cas:meta,
18671868
$cfg_align:meta,
@@ -2988,7 +2989,8 @@ atomic_int_ptr_sized! {
29882989
}
29892990

29902991
#[inline]
2991-
#[cfg(target_has_atomic = "8")]
2992+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
2993+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
29922994
fn strongest_failure_ordering(order: Ordering) -> Ordering {
29932995
match order {
29942996
Release => Relaxed,
@@ -3030,7 +3032,8 @@ unsafe fn atomic_load<T: Copy>(dst: *const T, order: Ordering) -> T {
30303032
}
30313033

30323034
#[inline]
3033-
#[cfg(target_has_atomic = "8")]
3035+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3036+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
30343037
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
30353038
unsafe fn atomic_swap<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
30363039
// SAFETY: the caller must uphold the safety contract for `atomic_swap`.
@@ -3047,7 +3050,8 @@ unsafe fn atomic_swap<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
30473050

30483051
/// Returns the previous value (like __sync_fetch_and_add).
30493052
#[inline]
3050-
#[cfg(target_has_atomic = "8")]
3053+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3054+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
30513055
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
30523056
unsafe fn atomic_add<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
30533057
// SAFETY: the caller must uphold the safety contract for `atomic_add`.
@@ -3064,7 +3068,8 @@ unsafe fn atomic_add<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
30643068

30653069
/// Returns the previous value (like __sync_fetch_and_sub).
30663070
#[inline]
3067-
#[cfg(target_has_atomic = "8")]
3071+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3072+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
30683073
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
30693074
unsafe fn atomic_sub<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
30703075
// SAFETY: the caller must uphold the safety contract for `atomic_sub`.
@@ -3080,7 +3085,8 @@ unsafe fn atomic_sub<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
30803085
}
30813086

30823087
#[inline]
3083-
#[cfg(target_has_atomic = "8")]
3088+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3089+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
30843090
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
30853091
unsafe fn atomic_compare_exchange<T: Copy>(
30863092
dst: *mut T,
@@ -3115,7 +3121,8 @@ unsafe fn atomic_compare_exchange<T: Copy>(
31153121
}
31163122

31173123
#[inline]
3118-
#[cfg(target_has_atomic = "8")]
3124+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3125+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
31193126
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
31203127
unsafe fn atomic_compare_exchange_weak<T: Copy>(
31213128
dst: *mut T,
@@ -3150,7 +3157,8 @@ unsafe fn atomic_compare_exchange_weak<T: Copy>(
31503157
}
31513158

31523159
#[inline]
3153-
#[cfg(target_has_atomic = "8")]
3160+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3161+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
31543162
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
31553163
unsafe fn atomic_and<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
31563164
// SAFETY: the caller must uphold the safety contract for `atomic_and`
@@ -3166,7 +3174,8 @@ unsafe fn atomic_and<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
31663174
}
31673175

31683176
#[inline]
3169-
#[cfg(target_has_atomic = "8")]
3177+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3178+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
31703179
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
31713180
unsafe fn atomic_nand<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
31723181
// SAFETY: the caller must uphold the safety contract for `atomic_nand`
@@ -3182,7 +3191,8 @@ unsafe fn atomic_nand<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
31823191
}
31833192

31843193
#[inline]
3185-
#[cfg(target_has_atomic = "8")]
3194+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3195+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
31863196
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
31873197
unsafe fn atomic_or<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
31883198
// SAFETY: the caller must uphold the safety contract for `atomic_or`
@@ -3198,7 +3208,8 @@ unsafe fn atomic_or<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
31983208
}
31993209

32003210
#[inline]
3201-
#[cfg(target_has_atomic = "8")]
3211+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3212+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
32023213
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
32033214
unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32043215
// SAFETY: the caller must uphold the safety contract for `atomic_xor`
@@ -3215,7 +3226,8 @@ unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32153226

32163227
/// returns the max value (signed comparison)
32173228
#[inline]
3218-
#[cfg(target_has_atomic = "8")]
3229+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3230+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
32193231
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
32203232
unsafe fn atomic_max<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32213233
// SAFETY: the caller must uphold the safety contract for `atomic_max`
@@ -3232,7 +3244,8 @@ unsafe fn atomic_max<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32323244

32333245
/// returns the min value (signed comparison)
32343246
#[inline]
3235-
#[cfg(target_has_atomic = "8")]
3247+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3248+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
32363249
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
32373250
unsafe fn atomic_min<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32383251
// SAFETY: the caller must uphold the safety contract for `atomic_min`
@@ -3249,7 +3262,8 @@ unsafe fn atomic_min<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32493262

32503263
/// returns the max value (unsigned comparison)
32513264
#[inline]
3252-
#[cfg(target_has_atomic = "8")]
3265+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3266+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
32533267
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
32543268
unsafe fn atomic_umax<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32553269
// SAFETY: the caller must uphold the safety contract for `atomic_umax`
@@ -3266,7 +3280,8 @@ unsafe fn atomic_umax<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32663280

32673281
/// returns the min value (unsigned comparison)
32683282
#[inline]
3269-
#[cfg(target_has_atomic = "8")]
3283+
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
3284+
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
32703285
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
32713286
unsafe fn atomic_umin<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
32723287
// SAFETY: the caller must uphold the safety contract for `atomic_umin`

0 commit comments

Comments
 (0)