From 651e8734620a07d25acab4a594e23e33b4d91f50 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Sat, 14 Jan 2023 21:33:42 +0800 Subject: [PATCH 1/7] BPF: Disable atomic CAS Enabling CAS for BPF targets (#105708) breaks the build of core library. The failure occurs both when building rustc for BPF targets and when building crates for BPF targets with the current nightly. The LLVM BPF backend does not correctly lower all `atomicrmw` operations and crashes for unsupported ones. Before we can enable CAS for BPF in Rust, we need to fix the LLVM BPF backend first. Fixes #106795 Signed-off-by: Michal Rostecki --- compiler/rustc_target/src/spec/bpf_base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/bpf_base.rs b/compiler/rustc_target/src/spec/bpf_base.rs index 2b00cda44b511..4d03747d0165f 100644 --- a/compiler/rustc_target/src/spec/bpf_base.rs +++ b/compiler/rustc_target/src/spec/bpf_base.rs @@ -6,7 +6,7 @@ pub fn opts(endian: Endian) -> TargetOptions { allow_asm: true, endian, linker_flavor: LinkerFlavor::Bpf, - atomic_cas: true, + atomic_cas: false, dynamic_linking: true, no_builtins: true, panic_strategy: PanicStrategy::Abort, From 11e002a001348e7ea035c0cb2665be806e2a832e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 14 Jan 2023 13:49:00 -0800 Subject: [PATCH 2/7] Make stage2 rustdoc and proc-macro-srv disableable in x.py install --- config.toml.example | 23 ++++++++++++++++++----- src/bootstrap/dist.rs | 22 ++++++++++++++++------ src/bootstrap/tool.rs | 6 ++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/config.toml.example b/config.toml.example index 5e1d2f2e314ff..299bfd779e57a 100644 --- a/config.toml.example +++ b/config.toml.example @@ -285,11 +285,24 @@ changelog-seen = 2 # be built if `extended = true`. #extended = false -# Installs chosen set of extended tools if `extended = true`. By default builds -# all extended tools except `rust-demangler`, unless the target is also being -# built with `profiler = true`. If chosen tool failed to build the installation -# fails. If `extended = false`, this option is ignored. -#tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"] # + "rust-demangler" if `profiler` +# Set of tools to be included in the installation. +# +# If `extended = false`, the only one of these built by default is rustdoc. +# +# If `extended = true`, they're all included, with the exception of +# rust-demangler which additionally requires `profiler = true` to be set. +# +# If any enabled tool fails to build, the installation fails. +#tools = [ +# "cargo", +# "clippy", +# "rustdoc", +# "rustfmt", +# "rust-analyzer", +# "analysis", +# "src", +# "rust-demangler", # if profiler = true +#] # Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose #verbose = 0 diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 68215790bed17..2bff0f21b5370 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -392,19 +392,29 @@ impl Step for Rustc { t!(fs::create_dir_all(image.join("bin"))); builder.cp_r(&src.join("bin"), &image.join("bin")); - builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755); + if builder + .config + .tools + .as_ref() + .map_or(true, |tools| tools.iter().any(|tool| tool == "rustdoc")) + { + let rustdoc = builder.rustdoc(compiler); + builder.install(&rustdoc, &image.join("bin"), 0o755); + } - let ra_proc_macro_srv = builder - .ensure(tool::RustAnalyzerProcMacroSrv { + if let Some(ra_proc_macro_srv) = builder.ensure_if_default( + tool::RustAnalyzerProcMacroSrv { compiler: builder.compiler_for( compiler.stage, builder.config.build, compiler.host, ), target: compiler.host, - }) - .expect("rust-analyzer-proc-macro-server always builds"); - builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755); + }, + builder.kind, + ) { + builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755); + } let libdir_relative = builder.libdir_relative(compiler); diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 9a2100c2fb785..ca5f500f93bc4 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -765,9 +765,15 @@ impl Step for RustAnalyzerProcMacroSrv { const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + let builder = run.builder; // Allow building `rust-analyzer-proc-macro-srv` both as part of the `rust-analyzer` and as a stand-alone tool. run.path("src/tools/rust-analyzer") .path("src/tools/rust-analyzer/crates/proc-macro-srv-cli") + .default_condition(builder.config.tools.as_ref().map_or(true, |tools| { + tools + .iter() + .any(|tool| tool == "rust-analyzer" || tool == "rust-analyzer-proc-macro-srv") + })) } fn make_run(run: RunConfig<'_>) { From 096f4547740ba0c945602ad6006f65bdd20f3418 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 20 Jan 2023 03:20:17 +0000 Subject: [PATCH 3/7] Filter predicates first for fast-path type flags --- .../src/traits/select/candidate_assembly.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 2733d9643fd77..87d574ff107b2 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -174,8 +174,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .param_env .caller_bounds() .iter() - .filter_map(|p| p.to_opt_poly_trait_pred()) - .filter(|p| !p.references_error()); + .filter(|p| !p.references_error()) + .filter_map(|p| p.to_opt_poly_trait_pred()); // Micro-optimization: filter out predicates relating to different traits. let matching_bounds = From 412798831792b4a67bea30bf53edd8a01f0c6bbe Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 20 Jan 2023 08:07:45 +0100 Subject: [PATCH 4/7] ThinBox: Add intra-doc-links for Metadata --- library/alloc/src/boxed/thin.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs index c1a82e452f6c3..ad48315fd70cc 100644 --- a/library/alloc/src/boxed/thin.rs +++ b/library/alloc/src/boxed/thin.rs @@ -48,7 +48,7 @@ unsafe impl Sync for ThinBox {} #[unstable(feature = "thin_box", issue = "92791")] impl ThinBox { - /// Moves a type to the heap with its `Metadata` stored in the heap allocation instead of on + /// Moves a type to the heap with its [`Metadata`] stored in the heap allocation instead of on /// the stack. /// /// # Examples @@ -59,6 +59,8 @@ impl ThinBox { /// /// let five = ThinBox::new(5); /// ``` + /// + /// [`Metadata`]: core::ptr::Pointee::Metadata #[cfg(not(no_global_oom_handling))] pub fn new(value: T) -> Self { let meta = ptr::metadata(&value); @@ -69,7 +71,7 @@ impl ThinBox { #[unstable(feature = "thin_box", issue = "92791")] impl ThinBox { - /// Moves a type to the heap with its `Metadata` stored in the heap allocation instead of on + /// Moves a type to the heap with its [`Metadata`] stored in the heap allocation instead of on /// the stack. /// /// # Examples @@ -80,6 +82,8 @@ impl ThinBox { /// /// let thin_slice = ThinBox::<[i32]>::new_unsize([1, 2, 3, 4]); /// ``` + /// + /// [`Metadata`]: core::ptr::Pointee::Metadata #[cfg(not(no_global_oom_handling))] pub fn new_unsize(value: T) -> Self where From ae39ee23fe45edb9031be8620b50b878b0cdffb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 20 Jan 2023 00:00:00 +0000 Subject: [PATCH 5/7] Instantiate dominators algorithm only once Remove inline from BasicBlocks::dominators to instantiate the dominator algorithm only once - in the rustc_middle crate. --- compiler/rustc_middle/src/mir/basic_blocks.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index 752cbdeae6b25..74e20beebad3f 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -35,7 +35,6 @@ impl<'tcx> BasicBlocks<'tcx> { self.is_cyclic.is_cyclic(self) } - #[inline] pub fn dominators(&self) -> Dominators { dominators(&self) } From 955e7fbb16e5015a493427dd2ab54aef97f2e23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 20 Jan 2023 00:00:00 +0000 Subject: [PATCH 6/7] Consistently use dominates instead of is_dominated_by There is a number of APIs that answer dominance queries. Previously they were named either "dominates" or "is_dominated_by". Consistently use the "dominates" form. No functional changes. --- .../src/graph/dominators/mod.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 2 +- .../rustc_mir_transform/src/coverage/counters.rs | 6 +++--- compiler/rustc_mir_transform/src/coverage/graph.rs | 14 +++++++------- compiler/rustc_mir_transform/src/coverage/spans.rs | 12 ++++++------ 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index fb2a22e94a527..6398e8360c0a2 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -289,7 +289,7 @@ impl Dominators { Iter { dominators: self, node: Some(node) } } - pub fn is_dominated_by(&self, node: Node, dom: Node) -> bool { + pub fn dominates(&self, dom: Node, node: Node) -> bool { // FIXME -- could be optimized by using post-order-rank self.dominators(node).any(|n| n == dom) } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index e52b243ecf635..3f43e2311abc1 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -3049,7 +3049,7 @@ impl Location { if self.block == other.block { self.statement_index <= other.statement_index } else { - dominators.is_dominated_by(other.block, self.block) + dominators.dominates(self.block, other.block) } } } diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 45de0c280352f..658e01d931031 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -520,7 +520,7 @@ impl<'a> BcbCounters<'a> { let mut found_loop_exit = false; for &branch in branches.iter() { if backedge_from_bcbs.iter().any(|&backedge_from_bcb| { - self.bcb_is_dominated_by(backedge_from_bcb, branch.target_bcb) + self.bcb_dominates(branch.target_bcb, backedge_from_bcb) }) { if let Some(reloop_branch) = some_reloop_branch { if reloop_branch.counter(&self.basic_coverage_blocks).is_none() { @@ -603,8 +603,8 @@ impl<'a> BcbCounters<'a> { } #[inline] - fn bcb_is_dominated_by(&self, node: BasicCoverageBlock, dom: BasicCoverageBlock) -> bool { - self.basic_coverage_blocks.is_dominated_by(node, dom) + fn bcb_dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool { + self.basic_coverage_blocks.dominates(dom, node) } #[inline] diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 78d28f1ebab7c..a2671eef2e940 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -209,8 +209,8 @@ impl CoverageGraph { } #[inline(always)] - pub fn is_dominated_by(&self, node: BasicCoverageBlock, dom: BasicCoverageBlock) -> bool { - self.dominators.as_ref().unwrap().is_dominated_by(node, dom) + pub fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool { + self.dominators.as_ref().unwrap().dominates(dom, node) } #[inline(always)] @@ -312,7 +312,7 @@ rustc_index::newtype_index! { /// to the BCB's primary counter or expression). /// /// The BCB CFG is critical to simplifying the coverage analysis by ensuring graph path-based -/// queries (`is_dominated_by()`, `predecessors`, `successors`, etc.) have branch (control flow) +/// queries (`dominates()`, `predecessors`, `successors`, etc.) have branch (control flow) /// significance. #[derive(Debug, Clone)] pub(super) struct BasicCoverageBlockData { @@ -594,7 +594,7 @@ impl TraverseCoverageGraphWithLoops { // branching block would have given an `Expression` (or vice versa). let (some_successor_to_add, some_loop_header) = if let Some((_, loop_header)) = context.loop_backedges { - if basic_coverage_blocks.is_dominated_by(successor, loop_header) { + if basic_coverage_blocks.dominates(loop_header, successor) { (Some(successor), Some(loop_header)) } else { (None, None) @@ -666,15 +666,15 @@ pub(super) fn find_loop_backedges( // // The overall complexity appears to be comparable to many other MIR transform algorithms, and I // don't expect that this function is creating a performance hot spot, but if this becomes an - // issue, there may be ways to optimize the `is_dominated_by` algorithm (as indicated by an + // issue, there may be ways to optimize the `dominates` algorithm (as indicated by an // existing `FIXME` comment in that code), or possibly ways to optimize it's usage here, perhaps // by keeping track of results for visited `BasicCoverageBlock`s if they can be used to short - // circuit downstream `is_dominated_by` checks. + // circuit downstream `dominates` checks. // // For now, that kind of optimization seems unnecessarily complicated. for (bcb, _) in basic_coverage_blocks.iter_enumerated() { for &successor in &basic_coverage_blocks.successors[bcb] { - if basic_coverage_blocks.is_dominated_by(bcb, successor) { + if basic_coverage_blocks.dominates(successor, bcb) { let loop_header = successor; let backedge_from_bcb = bcb; debug!( diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index c54348404536a..31d5541a31b6b 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -63,7 +63,7 @@ impl CoverageStatement { /// Note: A `CoverageStatement` merged into another CoverageSpan may come from a `BasicBlock` that /// is not part of the `CoverageSpan` bcb if the statement was included because it's `Span` matches /// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock` -/// `is_dominated_by()` the `BasicBlock`s in this `CoverageSpan`. +/// `dominates()` the `BasicBlock`s in this `CoverageSpan`. #[derive(Debug, Clone)] pub(super) struct CoverageSpan { pub span: Span, @@ -705,12 +705,12 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> { fn hold_pending_dups_unless_dominated(&mut self) { // Equal coverage spans are ordered by dominators before dominated (if any), so it should be // impossible for `curr` to dominate any previous `CoverageSpan`. - debug_assert!(!self.span_bcb_is_dominated_by(self.prev(), self.curr())); + debug_assert!(!self.span_bcb_dominates(self.curr(), self.prev())); let initial_pending_count = self.pending_dups.len(); if initial_pending_count > 0 { let mut pending_dups = self.pending_dups.split_off(0); - pending_dups.retain(|dup| !self.span_bcb_is_dominated_by(self.curr(), dup)); + pending_dups.retain(|dup| !self.span_bcb_dominates(dup, self.curr())); self.pending_dups.append(&mut pending_dups); if self.pending_dups.len() < initial_pending_count { debug!( @@ -721,7 +721,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> { } } - if self.span_bcb_is_dominated_by(self.curr(), self.prev()) { + if self.span_bcb_dominates(self.prev(), self.curr()) { debug!( " different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}", self.prev() @@ -787,8 +787,8 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> { } } - fn span_bcb_is_dominated_by(&self, covspan: &CoverageSpan, dom_covspan: &CoverageSpan) -> bool { - self.basic_coverage_blocks.is_dominated_by(covspan.bcb, dom_covspan.bcb) + fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool { + self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb) } } From 00ff718da84b1dbe5f7851fa39987c5b801ca5ca Mon Sep 17 00:00:00 2001 From: Ezra Shaw Date: Sat, 21 Jan 2023 21:32:05 +1300 Subject: [PATCH 7/7] add UI test + docs for `E0789` --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0789.md | 30 +++++++++++++++++++ src/tools/tidy/src/error_codes.rs | 2 +- tests/ui/error-codes/E0789.rs | 12 ++++++++ tests/ui/error-codes/E0789.stderr | 15 ++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0789.md create mode 100644 tests/ui/error-codes/E0789.rs create mode 100644 tests/ui/error-codes/E0789.stderr diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 9d5f4ad752051..4ae372bb90432 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -506,6 +506,7 @@ E0785: include_str!("./error_codes/E0785.md"), E0786: include_str!("./error_codes/E0786.md"), E0787: include_str!("./error_codes/E0787.md"), E0788: include_str!("./error_codes/E0788.md"), +E0789: include_str!("./error_codes/E0789.md"), E0790: include_str!("./error_codes/E0790.md"), E0791: include_str!("./error_codes/E0791.md"), E0792: include_str!("./error_codes/E0792.md"), @@ -645,5 +646,4 @@ E0792: include_str!("./error_codes/E0792.md"), // E0721, // `await` keyword // E0723, // unstable feature in `const` context // E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`. - E0789, // rustc_allowed_through_unstable_modules without stability attribute } diff --git a/compiler/rustc_error_codes/src/error_codes/E0789.md b/compiler/rustc_error_codes/src/error_codes/E0789.md new file mode 100644 index 0000000000000..89b7cd422fe96 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0789.md @@ -0,0 +1,30 @@ +#### This error code is internal to the compiler and will not be emitted with normal Rust code. + +The internal `rustc_allowed_through_unstable_modules` attribute must be used +on an item with a `stable` attribute. + +Erroneous code example: + +```compile_fail,E0789 +// NOTE: both of these attributes are perma-unstable and should *never* be +// used outside of the compiler and standard library. +#![feature(rustc_attrs)] +#![feature(staged_api)] + +#![unstable(feature = "foo_module", reason = "...", issue = "123")] + +#[rustc_allowed_through_unstable_modules] +// #[stable(feature = "foo", since = "1.0")] +struct Foo; +// ^^^ error: `rustc_allowed_through_unstable_modules` attribute must be +// paired with a `stable` attribute +``` + +Typically when an item is marked with a `stable` attribute, the modules that +enclose the item must also be marked with `stable` attributes, otherwise the +item becomes *de facto* unstable. `#[rustc_allowed_through_unstable_modules]` +is a workaround which allows an item to "escape" its unstable parent modules. +This error occurs when an item is marked with +`#[rustc_allowed_through_unstable_modules]` but no supplementary `stable` +attribute exists. See [#99288](https://github.com/rust-lang/rust/pull/99288) +for an example of `#[rustc_allowed_through_unstable_modules]` in use. diff --git a/src/tools/tidy/src/error_codes.rs b/src/tools/tidy/src/error_codes.rs index 5b84b51a035d4..6bb4d32f87d0a 100644 --- a/src/tools/tidy/src/error_codes.rs +++ b/src/tools/tidy/src/error_codes.rs @@ -31,7 +31,7 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E06 // Error codes that don't yet have a UI test. This list will eventually be removed. const IGNORE_UI_TEST_CHECK: &[&str] = - &["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729", "E0789"]; + &["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729"]; macro_rules! verbose_print { ($verbose:expr, $($fmt:tt)*) => { diff --git a/tests/ui/error-codes/E0789.rs b/tests/ui/error-codes/E0789.rs new file mode 100644 index 0000000000000..c0cbbcc9d2dc2 --- /dev/null +++ b/tests/ui/error-codes/E0789.rs @@ -0,0 +1,12 @@ +// compile-flags: --crate-type lib + +#![feature(rustc_attrs)] +#![feature(staged_api)] +#![unstable(feature = "foo_module", reason = "...", issue = "123")] + +#[rustc_allowed_through_unstable_modules] +// #[stable(feature = "foo", since = "1.0")] +struct Foo; +//~^ ERROR `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute +//~^^ ERROR `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute +// FIXME: we shouldn't have two errors here, only occurs when using `-Zdeduplicate-diagnostics=no` diff --git a/tests/ui/error-codes/E0789.stderr b/tests/ui/error-codes/E0789.stderr new file mode 100644 index 0000000000000..faab92bae035d --- /dev/null +++ b/tests/ui/error-codes/E0789.stderr @@ -0,0 +1,15 @@ +error[E0789]: `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute + --> $DIR/E0789.rs:9:1 + | +LL | struct Foo; + | ^^^^^^^^^^^ + +error[E0789]: `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute + --> $DIR/E0789.rs:9:1 + | +LL | struct Foo; + | ^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0789`.