Skip to content

Commit 265c74d

Browse files
committed
Auto merge of #143676 - Kobzol:rollup-njrvwsa, r=Kobzol
Rollup of 6 pull requests Successful merges: - #143398 (tidy: add support for `--extra-checks=auto:` feature) - #143446 (use `--dynamic-list` for exporting executable symbols) - #143644 (Add triagebot stdarch mention ping) - #143660 (Disable docs for `compiler-builtins` and `sysroot`) - #143666 (Re-expose nested bodies in rustc_borrowck::consumers) - #143668 (Fix VxWorks build errors) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6b3ae3f + 5b59dbd commit 265c74d

File tree

27 files changed

+418
-132
lines changed

27 files changed

+418
-132
lines changed

compiler/rustc_borrowck/src/consumers.rs

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! This file provides API for compiler consumers.
22
3+
use rustc_data_structures::fx::FxHashMap;
34
use rustc_hir::def_id::LocalDefId;
45
use rustc_index::IndexVec;
6+
use rustc_middle::bug;
57
use rustc_middle::mir::{Body, Promoted};
68
use rustc_middle::ty::TyCtxt;
79

@@ -17,7 +19,39 @@ pub use super::polonius::legacy::{
1719
pub use super::region_infer::RegionInferenceContext;
1820
use crate::{BorrowCheckRootCtxt, do_mir_borrowck};
1921

20-
/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
22+
/// Struct used during mir borrowck to collect bodies with facts for a typeck root and all
23+
/// its nested bodies.
24+
pub(crate) struct BorrowckConsumer<'tcx> {
25+
options: ConsumerOptions,
26+
bodies: FxHashMap<LocalDefId, BodyWithBorrowckFacts<'tcx>>,
27+
}
28+
29+
impl<'tcx> BorrowckConsumer<'tcx> {
30+
pub(crate) fn new(options: ConsumerOptions) -> Self {
31+
Self { options, bodies: Default::default() }
32+
}
33+
34+
pub(crate) fn insert_body(&mut self, def_id: LocalDefId, body: BodyWithBorrowckFacts<'tcx>) {
35+
if self.bodies.insert(def_id, body).is_some() {
36+
bug!("unexpected previous body for {def_id:?}");
37+
}
38+
}
39+
40+
/// Should the Polonius input facts be computed?
41+
pub(crate) fn polonius_input(&self) -> bool {
42+
matches!(
43+
self.options,
44+
ConsumerOptions::PoloniusInputFacts | ConsumerOptions::PoloniusOutputFacts
45+
)
46+
}
47+
48+
/// Should we run Polonius and collect the output facts?
49+
pub(crate) fn polonius_output(&self) -> bool {
50+
matches!(self.options, ConsumerOptions::PoloniusOutputFacts)
51+
}
52+
}
53+
54+
/// Options determining the output behavior of [`get_bodies_with_borrowck_facts`].
2155
///
2256
/// If executing under `-Z polonius` the choice here has no effect, and everything as if
2357
/// [`PoloniusOutputFacts`](ConsumerOptions::PoloniusOutputFacts) had been selected
@@ -43,17 +77,6 @@ pub enum ConsumerOptions {
4377
PoloniusOutputFacts,
4478
}
4579

46-
impl ConsumerOptions {
47-
/// Should the Polonius input facts be computed?
48-
pub(crate) fn polonius_input(&self) -> bool {
49-
matches!(self, Self::PoloniusInputFacts | Self::PoloniusOutputFacts)
50-
}
51-
/// Should we run Polonius and collect the output facts?
52-
pub(crate) fn polonius_output(&self) -> bool {
53-
matches!(self, Self::PoloniusOutputFacts)
54-
}
55-
}
56-
5780
/// A `Body` with information computed by the borrow checker. This struct is
5881
/// intended to be consumed by compiler consumers.
5982
///
@@ -82,25 +105,35 @@ pub struct BodyWithBorrowckFacts<'tcx> {
82105
pub output_facts: Option<Box<PoloniusOutput>>,
83106
}
84107

85-
/// This function computes borrowck facts for the given body. The [`ConsumerOptions`]
86-
/// determine which facts are returned. This function makes a copy of the body because
87-
/// it needs to regenerate the region identifiers. It should never be invoked during a
88-
/// typical compilation session due to the unnecessary overhead of returning
89-
/// [`BodyWithBorrowckFacts`].
108+
/// This function computes borrowck facts for the given def id and all its nested bodies.
109+
/// It must be called with a typeck root which will then borrowck all nested bodies as well.
110+
/// The [`ConsumerOptions`] determine which facts are returned. This function makes a copy
111+
/// of the bodies because it needs to regenerate the region identifiers. It should never be
112+
/// invoked during a typical compilation session due to the unnecessary overhead of
113+
/// returning [`BodyWithBorrowckFacts`].
90114
///
91115
/// Note:
92-
/// * This function will panic if the required body was already stolen. This
116+
/// * This function will panic if the required bodies were already stolen. This
93117
/// can, for example, happen when requesting a body of a `const` function
94118
/// because they are evaluated during typechecking. The panic can be avoided
95119
/// by overriding the `mir_borrowck` query. You can find a complete example
96-
/// that shows how to do this at `tests/run-make/obtain-borrowck/`.
120+
/// that shows how to do this at `tests/ui-fulldeps/obtain-borrowck.rs`.
97121
///
98122
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
99-
pub fn get_body_with_borrowck_facts(
123+
pub fn get_bodies_with_borrowck_facts(
100124
tcx: TyCtxt<'_>,
101-
def_id: LocalDefId,
125+
root_def_id: LocalDefId,
102126
options: ConsumerOptions,
103-
) -> BodyWithBorrowckFacts<'_> {
104-
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def_id);
105-
*do_mir_borrowck(&mut root_cx, def_id, Some(options)).1.unwrap()
127+
) -> FxHashMap<LocalDefId, BodyWithBorrowckFacts<'_>> {
128+
let mut root_cx =
129+
BorrowCheckRootCtxt::new(tcx, root_def_id, Some(BorrowckConsumer::new(options)));
130+
131+
// See comment in `rustc_borrowck::mir_borrowck`
132+
let nested_bodies = tcx.nested_bodies_within(root_def_id);
133+
for def_id in nested_bodies {
134+
root_cx.get_or_insert_nested(def_id);
135+
}
136+
137+
do_mir_borrowck(&mut root_cx, root_def_id);
138+
root_cx.consumer.unwrap().bodies
106139
}

compiler/rustc_borrowck/src/lib.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use smallvec::SmallVec;
5151
use tracing::{debug, instrument};
5252

5353
use crate::borrow_set::{BorrowData, BorrowSet};
54-
use crate::consumers::{BodyWithBorrowckFacts, ConsumerOptions};
54+
use crate::consumers::BodyWithBorrowckFacts;
5555
use crate::dataflow::{BorrowIndex, Borrowck, BorrowckDomain, Borrows};
5656
use crate::diagnostics::{
5757
AccessKind, BorrowckDiagnosticsBuffer, IllegalMoveOriginKind, MoveError, RegionName,
@@ -124,7 +124,7 @@ fn mir_borrowck(
124124
let opaque_types = ConcreteOpaqueTypes(Default::default());
125125
Ok(tcx.arena.alloc(opaque_types))
126126
} else {
127-
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def);
127+
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def, None);
128128
// We need to manually borrowck all nested bodies from the HIR as
129129
// we do not generate MIR for dead code. Not doing so causes us to
130130
// never check closures in dead code.
@@ -134,7 +134,7 @@ fn mir_borrowck(
134134
}
135135

136136
let PropagatedBorrowCheckResults { closure_requirements, used_mut_upvars } =
137-
do_mir_borrowck(&mut root_cx, def, None).0;
137+
do_mir_borrowck(&mut root_cx, def);
138138
debug_assert!(closure_requirements.is_none());
139139
debug_assert!(used_mut_upvars.is_empty());
140140
root_cx.finalize()
@@ -289,17 +289,12 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
289289

290290
/// Perform the actual borrow checking.
291291
///
292-
/// Use `consumer_options: None` for the default behavior of returning
293-
/// [`PropagatedBorrowCheckResults`] only. Otherwise, return [`BodyWithBorrowckFacts`]
294-
/// according to the given [`ConsumerOptions`].
295-
///
296292
/// For nested bodies this should only be called through `root_cx.get_or_insert_nested`.
297293
#[instrument(skip(root_cx), level = "debug")]
298294
fn do_mir_borrowck<'tcx>(
299295
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
300296
def: LocalDefId,
301-
consumer_options: Option<ConsumerOptions>,
302-
) -> (PropagatedBorrowCheckResults<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
297+
) -> PropagatedBorrowCheckResults<'tcx> {
303298
let tcx = root_cx.tcx;
304299
let infcx = BorrowckInferCtxt::new(tcx, def);
305300
let (input_body, promoted) = tcx.mir_promoted(def);
@@ -343,7 +338,6 @@ fn do_mir_borrowck<'tcx>(
343338
&location_table,
344339
&move_data,
345340
&borrow_set,
346-
consumer_options,
347341
);
348342

349343
// Dump MIR results into a file, if that is enabled. This lets us
@@ -483,23 +477,24 @@ fn do_mir_borrowck<'tcx>(
483477
used_mut_upvars: mbcx.used_mut_upvars,
484478
};
485479

486-
let body_with_facts = if consumer_options.is_some() {
487-
Some(Box::new(BodyWithBorrowckFacts {
488-
body: body_owned,
489-
promoted,
490-
borrow_set,
491-
region_inference_context: regioncx,
492-
location_table: polonius_input.as_ref().map(|_| location_table),
493-
input_facts: polonius_input,
494-
output_facts: polonius_output,
495-
}))
496-
} else {
497-
None
498-
};
480+
if let Some(consumer) = &mut root_cx.consumer {
481+
consumer.insert_body(
482+
def,
483+
BodyWithBorrowckFacts {
484+
body: body_owned,
485+
promoted,
486+
borrow_set,
487+
region_inference_context: regioncx,
488+
location_table: polonius_input.as_ref().map(|_| location_table),
489+
input_facts: polonius_input,
490+
output_facts: polonius_output,
491+
},
492+
);
493+
}
499494

500495
debug!("do_mir_borrowck: result = {:#?}", result);
501496

502-
(result, body_with_facts)
497+
result
503498
}
504499

505500
fn get_flow_results<'a, 'tcx>(

compiler/rustc_borrowck/src/nll.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_span::sym;
1818
use tracing::{debug, instrument};
1919

2020
use crate::borrow_set::BorrowSet;
21-
use crate::consumers::ConsumerOptions;
2221
use crate::diagnostics::RegionErrors;
2322
use crate::handle_placeholders::compute_sccs_applying_placeholder_outlives_constraints;
2423
use crate::polonius::PoloniusDiagnosticsContext;
@@ -83,12 +82,11 @@ pub(crate) fn compute_regions<'tcx>(
8382
location_table: &PoloniusLocationTable,
8483
move_data: &MoveData<'tcx>,
8584
borrow_set: &BorrowSet<'tcx>,
86-
consumer_options: Option<ConsumerOptions>,
8785
) -> NllOutput<'tcx> {
8886
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
89-
let polonius_input = consumer_options.map(|c| c.polonius_input()).unwrap_or_default()
87+
let polonius_input = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_input())
9088
|| is_polonius_legacy_enabled;
91-
let polonius_output = consumer_options.map(|c| c.polonius_output()).unwrap_or_default()
89+
let polonius_output = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_output())
9290
|| is_polonius_legacy_enabled;
9391
let mut polonius_facts =
9492
(polonius_input || PoloniusFacts::enabled(infcx.tcx)).then_some(PoloniusFacts::default());

compiler/rustc_borrowck/src/root_cx.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_middle::ty::{OpaqueHiddenType, Ty, TyCtxt, TypeVisitableExt};
66
use rustc_span::ErrorGuaranteed;
77
use smallvec::SmallVec;
88

9+
use crate::consumers::BorrowckConsumer;
910
use crate::{ClosureRegionRequirements, ConcreteOpaqueTypes, PropagatedBorrowCheckResults};
1011

1112
/// The shared context used by both the root as well as all its nested
@@ -16,16 +17,24 @@ pub(super) struct BorrowCheckRootCtxt<'tcx> {
1617
concrete_opaque_types: ConcreteOpaqueTypes<'tcx>,
1718
nested_bodies: FxHashMap<LocalDefId, PropagatedBorrowCheckResults<'tcx>>,
1819
tainted_by_errors: Option<ErrorGuaranteed>,
20+
/// This should be `None` during normal compilation. See [`crate::consumers`] for more
21+
/// information on how this is used.
22+
pub(crate) consumer: Option<BorrowckConsumer<'tcx>>,
1923
}
2024

2125
impl<'tcx> BorrowCheckRootCtxt<'tcx> {
22-
pub(super) fn new(tcx: TyCtxt<'tcx>, root_def_id: LocalDefId) -> BorrowCheckRootCtxt<'tcx> {
26+
pub(super) fn new(
27+
tcx: TyCtxt<'tcx>,
28+
root_def_id: LocalDefId,
29+
consumer: Option<BorrowckConsumer<'tcx>>,
30+
) -> BorrowCheckRootCtxt<'tcx> {
2331
BorrowCheckRootCtxt {
2432
tcx,
2533
root_def_id,
2634
concrete_opaque_types: Default::default(),
2735
nested_bodies: Default::default(),
2836
tainted_by_errors: None,
37+
consumer,
2938
}
3039
}
3140

@@ -71,7 +80,7 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
7180
self.root_def_id.to_def_id()
7281
);
7382
if !self.nested_bodies.contains_key(&def_id) {
74-
let result = super::do_mir_borrowck(self, def_id, None).0;
83+
let result = super::do_mir_borrowck(self, def_id);
7584
if let Some(prev) = self.nested_bodies.insert(def_id, result) {
7685
bug!("unexpected previous nested body: {prev:?}");
7786
}

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,7 @@ impl<'a> Linker for GccLinker<'a> {
800800
return;
801801
}
802802

803-
let is_windows = self.sess.target.is_like_windows;
804-
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });
805-
803+
let path = tmpdir.join(if self.sess.target.is_like_windows { "list.def" } else { "list" });
806804
debug!("EXPORTED SYMBOLS:");
807805

808806
if self.sess.target.is_like_darwin {
@@ -817,7 +815,8 @@ impl<'a> Linker for GccLinker<'a> {
817815
if let Err(error) = res {
818816
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
819817
}
820-
} else if is_windows {
818+
self.link_arg("-exported_symbols_list").link_arg(path);
819+
} else if self.sess.target.is_like_windows {
821820
let res: io::Result<()> = try {
822821
let mut f = File::create_buffered(&path)?;
823822

@@ -835,6 +834,21 @@ impl<'a> Linker for GccLinker<'a> {
835834
if let Err(error) = res {
836835
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
837836
}
837+
self.link_arg(path);
838+
} else if crate_type == CrateType::Executable && !self.sess.target.is_like_solaris {
839+
let res: io::Result<()> = try {
840+
let mut f = File::create_buffered(&path)?;
841+
writeln!(f, "{{")?;
842+
for (sym, _) in symbols {
843+
debug!(sym);
844+
writeln!(f, " {sym};")?;
845+
}
846+
writeln!(f, "}};")?;
847+
};
848+
if let Err(error) = res {
849+
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
850+
}
851+
self.link_arg("--dynamic-list").link_arg(path);
838852
} else {
839853
// Write an LD version script
840854
let res: io::Result<()> = try {
@@ -852,18 +866,13 @@ impl<'a> Linker for GccLinker<'a> {
852866
if let Err(error) = res {
853867
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
854868
}
855-
}
856-
857-
if self.sess.target.is_like_darwin {
858-
self.link_arg("-exported_symbols_list").link_arg(path);
859-
} else if self.sess.target.is_like_solaris {
860-
self.link_arg("-M").link_arg(path);
861-
} else if is_windows {
862-
self.link_arg(path);
863-
} else {
864-
let mut arg = OsString::from("--version-script=");
865-
arg.push(path);
866-
self.link_arg(arg).link_arg("--no-undefined-version");
869+
if self.sess.target.is_like_solaris {
870+
self.link_arg("-M").link_arg(path);
871+
} else {
872+
let mut arg = OsString::from("--version-script=");
873+
arg.push(path);
874+
self.link_arg(arg).link_arg("--no-undefined-version");
875+
}
867876
}
868877
}
869878

library/compiler-builtins/compiler-builtins/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ links = "compiler-rt"
1919
bench = false
2020
doctest = false
2121
test = false
22+
# make sure this crate isn't included in public standard library docs
23+
doc = false
2224

2325
[dependencies]
2426
core = { path = "../../core", optional = true }

library/std/src/sys/fs/unix.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ impl File {
14911491
target_os = "redox",
14921492
target_os = "espidf",
14931493
target_os = "horizon",
1494-
target_os = "vxworks",
14951494
target_os = "nuttx",
14961495
)))]
14971496
let to_timespec = |time: Option<SystemTime>| match time {

library/std/src/sys/pal/unix/thread.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl Thread {
222222

223223
#[cfg(target_os = "vxworks")]
224224
pub fn set_name(name: &CStr) {
225-
let mut name = truncate_cstr::<{ libc::VX_TASK_RENAME_LENGTH - 1 }>(name);
225+
let mut name = truncate_cstr::<{ (libc::VX_TASK_RENAME_LENGTH - 1) as usize }>(name);
226226
let res = unsafe { libc::taskNameSet(libc::taskIdSelf(), name.as_mut_ptr()) };
227227
debug_assert_eq!(res, libc::OK);
228228
}

library/sysroot/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ name = "sysroot"
55
version = "0.0.0"
66
edition = "2024"
77

8+
[lib]
9+
# make sure this crate isn't included in public standard library docs
10+
doc = false
11+
812
# this is a dummy crate to ensure that all required crates appear in the sysroot
913
[dependencies]
1014
proc_macro = { path = "../proc_macro", public = true }

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,6 @@ fn doc_std(
739739
}
740740

741741
for krate in requested_crates {
742-
if krate == "sysroot" {
743-
// The sysroot crate is an implementation detail, don't include it in public docs.
744-
continue;
745-
}
746742
cargo.arg("-p").arg(krate);
747743
}
748744

0 commit comments

Comments
 (0)