Skip to content

Commit 536635c

Browse files
committed
Auto merge of rust-lang#112890 - GuillaumeGomez:rollup-7e01q69, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - rust-lang#99587 (Document memory orderings of `thread::{park, unpark}`) - rust-lang#112836 ([rustdoc] partially fix invalid files creation) - rust-lang#112853 (Add `lazy_type_alias` feature gate) - rust-lang#112863 (Fix copy-paste typo in `eprint(ln)` docs) - rust-lang#112883 (Make queries traceable again) - rust-lang#112885 (Fix msg passed to span_bug) - rust-lang#112886 (Revert 'Rename profile=user to profile=dist') r? `@ghost` `@rustbot` modify labels: rollup
2 parents 38b44eb + a687a96 commit 536635c

File tree

22 files changed

+246
-49
lines changed

22 files changed

+246
-49
lines changed

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ pub fn compile_declarative_macro(
535535
.pop()
536536
.unwrap();
537537
}
538-
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
538+
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured rhs")
539539
})
540540
.collect::<Vec<mbe::TokenTree>>(),
541541
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured rhs"),

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ declare_features! (
442442
(active, intra_doc_pointers, "1.51.0", Some(80896), None),
443443
// Allows setting the threshold for the `large_assignments` lint.
444444
(active, large_assignments, "1.52.0", Some(83518), None),
445+
/// Allow to have type alias types for inter-crate use.
446+
(active, lazy_type_alias, "CURRENT_RUSTC_VERSION", Some(112792), None),
445447
/// Allows `if/while p && let q = r && ...` chains.
446448
(active, let_chains, "1.37.0", Some(53667), None),
447449
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
896896
let ty = self.tcx().at(span).type_of(did);
897897

898898
if matches!(self.tcx().def_kind(did), DefKind::TyAlias)
899-
&& ty.skip_binder().has_opaque_types()
899+
&& (ty.skip_binder().has_opaque_types() || self.tcx().features().lazy_type_alias)
900900
{
901901
// Type aliases referring to types that contain opaque types (but aren't just directly
902902
// referencing a single opaque type) get encoded as a type alias that normalization will

compiler/rustc_query_impl/src/plumbing.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ macro_rules! define_queries {
531531
key: queries::$name::Key<'tcx>,
532532
mode: QueryMode,
533533
) -> Option<Erase<queries::$name::Value<'tcx>>> {
534+
#[cfg(debug_assertions)]
535+
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();
534536
get_query_incr(
535537
QueryType::config(tcx),
536538
QueryCtxt::new(tcx),
@@ -571,10 +573,16 @@ macro_rules! define_queries {
571573
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
572574
execute_query: |tcx, key| erase(tcx.$name(key)),
573575
compute: |tcx, key| {
576+
#[cfg(debug_assertions)]
577+
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();
574578
__rust_begin_short_backtrace(||
575579
queries::$name::provided_to_erased(
576580
tcx,
577-
call_provider!([$($modifiers)*][tcx, $name, key])
581+
{
582+
let ret = call_provider!([$($modifiers)*][tcx, $name, key]);
583+
tracing::trace!(?ret);
584+
ret
585+
}
578586
)
579587
)
580588
},

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ symbols! {
871871
large_assignments,
872872
lateout,
873873
lazy_normalization_consts,
874+
lazy_type_alias,
874875
le,
875876
len,
876877
let_chains,

library/std/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ macro_rules! println {
154154
///
155155
/// Panics if writing to `io::stderr` fails.
156156
///
157-
/// Writing to non-blocking stdout can cause an error, which will lead
157+
/// Writing to non-blocking stderr can cause an error, which will lead
158158
/// this macro to panic.
159159
///
160160
/// # Examples
@@ -189,7 +189,7 @@ macro_rules! eprint {
189189
///
190190
/// Panics if writing to `io::stderr` fails.
191191
///
192-
/// Writing to non-blocking stdout can cause an error, which will lead
192+
/// Writing to non-blocking stderr can cause an error, which will lead
193193
/// this macro to panic.
194194
///
195195
/// # Examples

library/std/src/thread/mod.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ impl Drop for PanicGuard {
889889
/// it is guaranteed that this function will not panic (it may abort the
890890
/// process if the implementation encounters some rare errors).
891891
///
892-
/// # park and unpark
892+
/// # `park` and `unpark`
893893
///
894894
/// Every thread is equipped with some basic low-level blocking support, via the
895895
/// [`thread::park`][`park`] function and [`thread::Thread::unpark`][`unpark`]
@@ -910,14 +910,6 @@ impl Drop for PanicGuard {
910910
/// if it wasn't already. Because the token is initially absent, [`unpark`]
911911
/// followed by [`park`] will result in the second call returning immediately.
912912
///
913-
/// In other words, each [`Thread`] acts a bit like a spinlock that can be
914-
/// locked and unlocked using `park` and `unpark`.
915-
///
916-
/// Notice that being unblocked does not imply any synchronization with someone
917-
/// that unparked this thread, it could also be spurious.
918-
/// For example, it would be a valid, but inefficient, implementation to make both [`park`] and
919-
/// [`unpark`] return immediately without doing anything.
920-
///
921913
/// The API is typically used by acquiring a handle to the current thread,
922914
/// placing that handle in a shared data structure so that other threads can
923915
/// find it, and then `park`ing in a loop. When some desired condition is met, another
@@ -931,6 +923,23 @@ impl Drop for PanicGuard {
931923
///
932924
/// * It can be implemented very efficiently on many platforms.
933925
///
926+
/// # Memory Ordering
927+
///
928+
/// Calls to `park` _synchronize-with_ calls to `unpark`, meaning that memory
929+
/// operations performed before a call to `unpark` are made visible to the thread that
930+
/// consumes the token and returns from `park`. Note that all `park` and `unpark`
931+
/// operations for a given thread form a total order and `park` synchronizes-with
932+
/// _all_ prior `unpark` operations.
933+
///
934+
/// In atomic ordering terms, `unpark` performs a `Release` operation and `park`
935+
/// performs the corresponding `Acquire` operation. Calls to `unpark` for the same
936+
/// thread form a [release sequence].
937+
///
938+
/// Note that being unblocked does not imply a call was made to `unpark`, because
939+
/// wakeups can also be spurious. For example, a valid, but inefficient,
940+
/// implementation could have `park` and `unpark` return immediately without doing anything,
941+
/// making *all* wakeups spurious.
942+
///
934943
/// # Examples
935944
///
936945
/// ```
@@ -944,7 +953,7 @@ impl Drop for PanicGuard {
944953
/// let parked_thread = thread::spawn(move || {
945954
/// // We want to wait until the flag is set. We *could* just spin, but using
946955
/// // park/unpark is more efficient.
947-
/// while !flag2.load(Ordering::Acquire) {
956+
/// while !flag2.load(Ordering::Relaxed) {
948957
/// println!("Parking thread");
949958
/// thread::park();
950959
/// // We *could* get here spuriously, i.e., way before the 10ms below are over!
@@ -961,7 +970,7 @@ impl Drop for PanicGuard {
961970
/// // There is no race condition here, if `unpark`
962971
/// // happens first, `park` will return immediately.
963972
/// // Hence there is no risk of a deadlock.
964-
/// flag.store(true, Ordering::Release);
973+
/// flag.store(true, Ordering::Relaxed);
965974
/// println!("Unpark the thread");
966975
/// parked_thread.thread().unpark();
967976
///
@@ -970,6 +979,7 @@ impl Drop for PanicGuard {
970979
///
971980
/// [`unpark`]: Thread::unpark
972981
/// [`thread::park_timeout`]: park_timeout
982+
/// [release sequence]: https://en.cppreference.com/w/cpp/atomic/memory_order#Release_sequence
973983
#[stable(feature = "rust1", since = "1.0.0")]
974984
pub fn park() {
975985
let guard = PanicGuard;

src/bootstrap/setup.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Profile {
2020
Codegen,
2121
Library,
2222
Tools,
23-
Dist,
23+
User,
2424
None,
2525
}
2626

@@ -43,7 +43,7 @@ impl Profile {
4343
pub fn all() -> impl Iterator<Item = Self> {
4444
use Profile::*;
4545
// N.B. these are ordered by how they are displayed, not alphabetically
46-
[Library, Compiler, Codegen, Tools, Dist, None].iter().copied()
46+
[Library, Compiler, Codegen, Tools, User, None].iter().copied()
4747
}
4848

4949
pub fn purpose(&self) -> String {
@@ -53,7 +53,7 @@ impl Profile {
5353
Compiler => "Contribute to the compiler itself",
5454
Codegen => "Contribute to the compiler, and also modify LLVM or codegen",
5555
Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)",
56-
Dist => "Install Rust from source",
56+
User => "Install Rust from source",
5757
None => "Do not modify `config.toml`"
5858
}
5959
.to_string()
@@ -73,7 +73,7 @@ impl Profile {
7373
Profile::Codegen => "codegen",
7474
Profile::Library => "library",
7575
Profile::Tools => "tools",
76-
Profile::Dist => "dist",
76+
Profile::User => "user",
7777
Profile::None => "none",
7878
}
7979
}
@@ -87,7 +87,7 @@ impl FromStr for Profile {
8787
"lib" | "library" => Ok(Profile::Library),
8888
"compiler" => Ok(Profile::Compiler),
8989
"llvm" | "codegen" => Ok(Profile::Codegen),
90-
"maintainer" | "dist" => Ok(Profile::Dist),
90+
"maintainer" | "user" => Ok(Profile::User),
9191
"tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => {
9292
Ok(Profile::Tools)
9393
}
@@ -160,7 +160,7 @@ pub fn setup(config: &Config, profile: Profile) {
160160
"test src/tools/rustfmt",
161161
],
162162
Profile::Library => &["check", "build", "test library/std", "doc"],
163-
Profile::Dist => &["dist", "build"],
163+
Profile::User => &["dist", "build"],
164164
};
165165

166166
println!();
@@ -170,7 +170,7 @@ pub fn setup(config: &Config, profile: Profile) {
170170
println!("- `x.py {}`", cmd);
171171
}
172172

173-
if profile != Profile::Dist {
173+
if profile != Profile::User {
174174
println!(
175175
"For more suggestions, see https://rustc-dev-guide.rust-lang.org/building/suggested.html"
176176
);

src/librustdoc/clean/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -2023,8 +2023,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
20232023
Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect())
20242024
}
20252025

2026-
ty::Alias(ty::Projection, ref data) => {
2027-
clean_projection(bound_ty.rebind(*data), cx, parent_def_id)
2026+
ty::Alias(ty::Projection, data) => {
2027+
clean_projection(bound_ty.rebind(data), cx, parent_def_id)
20282028
}
20292029

20302030
ty::Alias(ty::Inherent, alias_ty) => {
@@ -2052,8 +2052,21 @@ pub(crate) fn clean_middle_ty<'tcx>(
20522052
}
20532053

20542054
ty::Alias(ty::Weak, data) => {
2055-
let ty = cx.tcx.type_of(data.def_id).subst(cx.tcx, data.substs);
2056-
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
2055+
if cx.tcx.features().lazy_type_alias {
2056+
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
2057+
// we need to use `type_of`.
2058+
let path = external_path(
2059+
cx,
2060+
data.def_id,
2061+
false,
2062+
ThinVec::new(),
2063+
bound_ty.rebind(data.substs),
2064+
);
2065+
Type::Path { path }
2066+
} else {
2067+
let ty = cx.tcx.type_of(data.def_id).subst(cx.tcx, data.substs);
2068+
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
2069+
}
20572070
}
20582071

20592072
ty::Param(ref p) => {

src/librustdoc/clean/types.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,15 @@ fn is_field_vis_inherited(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
358358

359359
impl Item {
360360
pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
361-
self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did))
361+
self.def_id().and_then(|did| tcx.lookup_stability(did))
362362
}
363363

364364
pub(crate) fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
365-
self.item_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did))
365+
self.def_id().and_then(|did| tcx.lookup_const_stability(did))
366366
}
367367

368368
pub(crate) fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> {
369-
self.item_id.as_def_id().and_then(|did| tcx.lookup_deprecation(did))
369+
self.def_id().and_then(|did| tcx.lookup_deprecation(did))
370370
}
371371

372372
pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool {
@@ -391,7 +391,7 @@ impl Item {
391391
panic!("blanket impl item has non-blanket ID")
392392
}
393393
}
394-
_ => self.item_id.as_def_id().map(|did| rustc_span(did, tcx)),
394+
_ => self.def_id().map(|did| rustc_span(did, tcx)),
395395
}
396396
}
397397

@@ -501,7 +501,7 @@ impl Item {
501501
}
502502

503503
pub(crate) fn is_crate(&self) -> bool {
504-
self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.is_crate_root())
504+
self.is_mod() && self.def_id().map_or(false, |did| did.is_crate_root())
505505
}
506506
pub(crate) fn is_mod(&self) -> bool {
507507
self.type_() == ItemType::Module
@@ -638,11 +638,11 @@ impl Item {
638638
}
639639
let header = match *self.kind {
640640
ItemKind::ForeignFunctionItem(_) => {
641-
let def_id = self.item_id.as_def_id().unwrap();
641+
let def_id = self.def_id().unwrap();
642642
let abi = tcx.fn_sig(def_id).skip_binder().abi();
643643
hir::FnHeader {
644644
unsafety: if abi == Abi::RustIntrinsic {
645-
intrinsic_operation_unsafety(tcx, self.item_id.as_def_id().unwrap())
645+
intrinsic_operation_unsafety(tcx, self.def_id().unwrap())
646646
} else {
647647
hir::Unsafety::Unsafe
648648
},
@@ -659,7 +659,7 @@ impl Item {
659659
}
660660
}
661661
ItemKind::FunctionItem(_) | ItemKind::MethodItem(_, _) | ItemKind::TyMethodItem(_) => {
662-
let def_id = self.item_id.as_def_id().unwrap();
662+
let def_id = self.def_id().unwrap();
663663
build_fn_header(def_id, tcx, tcx.asyncness(def_id))
664664
}
665665
_ => return None,
@@ -738,7 +738,7 @@ impl Item {
738738
}
739739
})
740740
.collect();
741-
if let Some(def_id) = self.item_id.as_def_id() &&
741+
if let Some(def_id) = self.def_id() &&
742742
!def_id.is_local() &&
743743
// This check is needed because `adt_def` will panic if not a compatible type otherwise...
744744
matches!(self.type_(), ItemType::Struct | ItemType::Enum | ItemType::Union)
@@ -787,6 +787,10 @@ impl Item {
787787
pub fn is_doc_hidden(&self) -> bool {
788788
self.attrs.is_doc_hidden()
789789
}
790+
791+
pub fn def_id(&self) -> Option<DefId> {
792+
self.item_id.as_def_id()
793+
}
790794
}
791795

792796
#[derive(Clone, Debug)]

src/librustdoc/formats/cache.rs

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ pub(crate) struct Cache {
121121
pub(crate) intra_doc_links: FxHashMap<ItemId, FxIndexSet<clean::ItemLink>>,
122122
/// Cfg that have been hidden via #![doc(cfg_hide(...))]
123123
pub(crate) hidden_cfg: FxHashSet<clean::cfg::Cfg>,
124+
125+
/// Contains the list of `DefId`s which have been inlined. It is used when generating files
126+
/// to check if a stripped item should get its file generated or not: if it's inside a
127+
/// `#[doc(hidden)]` item or a private one and not inlined, it shouldn't get a file.
128+
pub(crate) inlined_items: DefIdSet,
124129
}
125130

126131
/// This struct is used to wrap the `cache` and `tcx` in order to run `DocFolder`.

0 commit comments

Comments
 (0)