From eac0b3a1d1b8d1db8fa95c50e118de5b9471e5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Sun, 21 Apr 2024 20:15:43 +0200 Subject: [PATCH 1/6] Add `-lmingwex` second time in `mingw_libs` Upcoming mingw-w64 releases will contain small math functions refactor which moved implementation around. As a result functions like `lgamma` now depend on libraries in this order: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`. Fixes #124221 --- compiler/rustc_target/src/spec/base/windows_gnu.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_target/src/spec/base/windows_gnu.rs b/compiler/rustc_target/src/spec/base/windows_gnu.rs index 25f02dc145193..1357de2dad126 100644 --- a/compiler/rustc_target/src/spec/base/windows_gnu.rs +++ b/compiler/rustc_target/src/spec/base/windows_gnu.rs @@ -40,6 +40,9 @@ pub fn opts() -> TargetOptions { // // See https://github.com/rust-lang/rust/pull/47483 for some more details. "-lmsvcrt", + // Math functions missing in MSVCRT (they are present in UCRT) require + // this dependency cycle: `libmingwex.a` -> `libmsvcrt.a` -> `libmingwex.a`. + "-lmingwex", "-luser32", "-lkernel32", ]; From 281aa50e3f52e13377444c518b190ac5dbace0cb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 8 May 2024 19:11:17 +0200 Subject: [PATCH 2/6] bootstrap: add comments for the automatic dry run --- src/bootstrap/src/core/builder.rs | 3 +++ src/bootstrap/src/lib.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 6c4b26ec2195f..b206aadef624a 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -88,6 +88,9 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash { /// Primary function to execute this rule. Can call `builder.ensure()` /// with other steps to run those. + /// + /// This gets called twice during a normal `./x.py` execution: first + /// with `dry_run() == true`, and then for real. fn run(self, builder: &Builder<'_>) -> Self::Output; /// When bootstrap is passed a set of paths, this controls whether this rule diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 47b03d411cb0d..c4420010f2438 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -683,6 +683,8 @@ impl Build { if !self.config.dry_run() { { + // We first to a dry-run. This is a sanity-check to ensure that + // steps don't do anything expensive in the dry-run. self.config.dry_run = DryRun::SelfCheck; let builder = builder::Builder::new(self); builder.execute_cli(); From fd2af9bf00e600fe09b8d846fd9072b3194bedea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 8 May 2024 21:25:19 +0200 Subject: [PATCH 3/6] reachable computation: extend explanation of what this does, and why --- compiler/rustc_passes/src/reachable.rs | 32 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index d5e1a70fd45c4..55b7c6dce4d9b 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -1,14 +1,26 @@ -//! Finds local items that are externally reachable, which means that other crates need access to -//! their compiled machine code or their MIR. +//! Finds local items that are "reachable", which means that other crates need access to their +//! compiled code or their *runtime* MIR. (Compile-time MIR is always encoded anyway, so we don't +//! worry about that here.) //! -//! An item is "externally reachable" if it is relevant for other crates. This obviously includes -//! all public items. However, some of these items cannot be compiled to machine code (because they -//! are generic), and for some the machine code is not sufficient (because we want to cross-crate -//! inline them). These items "need cross-crate MIR". When a reachable function `f` needs -//! cross-crate MIR, then all the functions it calls also become reachable, as they will be -//! necessary to use the MIR of `f` from another crate. Furthermore, an item can become "externally -//! reachable" by having a `const`/`const fn` return a pointer to that item, so we also need to -//! recurse into reachable `const`/`const fn`. +//! An item is "reachable" if codegen that happens in downstream crates can end up referencing this +//! item. This obviously includes all public items. However, some of these items cannot be codegen'd +//! (because they are generic), and for some the compiled code is not sufficient (because we want to +//! cross-crate inline them). These items "need cross-crate MIR". When a reachable function `f` +//! needs cross-crate MIR, then its MIR may be codegen'd in a downstream crate, and hence items it +//! mentions need to be considered reachable. +//! +//! Furthermore, if a `const`/`const fn` is reachable, then it can return pointers to other items, +//! making those reachable as well. For instance, consider a `const fn` returning a pointer to an +//! otherwise entirely private function: if a downstream crate calls that `const fn` to compute the +//! initial value of a `static`, then it needs to generate a direct reference to this function -- +//! i.e., the function is directly reachable from that downstream crate! Hence we have to recurse +//! into `const` and `const fn`. +//! +//! Conversely, reachability *stops* when it hits a monomorphic non-`const` function that we do not +//! want to cross-crate inline. That function will just be codegen'd in this crate, which means the +//! monomorphization collector will consider it a root and then do another graph traversal to +//! codegen everything called by this function -- but that's a very different graph from what we are +//! considering here as at that point, everything is monomorphic. use hir::def_id::LocalDefIdSet; use rustc_data_structures::stack::ensure_sufficient_stack; From dbdef68ddf0b8200954c81264400ef271a5f0194 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 9 May 2024 10:47:07 -0400 Subject: [PATCH 4/6] Make sure we consume a generic arg when checking mistyped turbofish --- compiler/rustc_parse/src/parser/diagnostics.rs | 6 +++++- .../recover/turbofish-arg-with-stray-colon.rs | 6 ++++++ .../recover/turbofish-arg-with-stray-colon.stderr | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs create mode 100644 tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f256dbf436021..ccf3b82ff7ad7 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1224,7 +1224,11 @@ impl<'a> Parser<'a> { let x = self.parse_seq_to_before_end( &token::Gt, SeqSep::trailing_allowed(token::Comma), - |p| p.parse_generic_arg(None), + |p| match p.parse_generic_arg(None)? { + Some(arg) => Ok(arg), + // If we didn't eat a generic arg, then we should error. + None => p.unexpected_any(), + }, ); match x { Ok((_, _, Recovered::No)) => { diff --git a/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs new file mode 100644 index 0000000000000..32125211a910f --- /dev/null +++ b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs @@ -0,0 +1,6 @@ +fn foo() { + let x = Tr; + //~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,` +} + +fn main() {} diff --git a/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr new file mode 100644 index 0000000000000..551b2e3ff09b0 --- /dev/null +++ b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr @@ -0,0 +1,14 @@ +error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,` + --> $DIR/turbofish-arg-with-stray-colon.rs:2:17 + | +LL | let x = Tr; + | ^ expected one of 8 possible tokens + | + = note: type ascription syntax has been removed, see issue #101728 +help: maybe write a path separator here + | +LL | let x = Tr; + | ~~ + +error: aborting due to 1 previous error + From 87c09fefbbf54aa30d1252d60ef1135862eef76d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 10 May 2024 07:45:53 +0200 Subject: [PATCH 5/6] fix typo Co-authored-by: jyn --- src/bootstrap/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index c4420010f2438..698a576effa63 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -683,7 +683,7 @@ impl Build { if !self.config.dry_run() { { - // We first to a dry-run. This is a sanity-check to ensure that + // We first do a dry-run. This is a sanity-check to ensure that // steps don't do anything expensive in the dry-run. self.config.dry_run = DryRun::SelfCheck; let builder = builder::Builder::new(self); From f70f9000362e4d207a6c7d0d63f3b11272878ccc Mon Sep 17 00:00:00 2001 From: bohan Date: Wed, 24 Apr 2024 11:28:45 +0800 Subject: [PATCH 6/6] ignore generics args in attribute paths --- compiler/rustc_parse/src/parser/path.rs | 19 ++++++++++++------- tests/crashes/123911.rs | 16 ---------------- tests/crashes/123912.rs | 15 --------------- .../genercs-in-path-with-prettry-hir.rs} | 3 +-- .../genercs-in-path-with-prettry-hir.stderr | 8 ++++++++ .../genercs-in-path-with-prettry-hir.stdout | 15 +++++++++++++++ .../macro-expand-within-generics-in-path.rs | 19 +++++++++++++++++++ ...acro-expand-within-generics-in-path.stderr | 14 ++++++++++++++ tests/ui/span/macro-ty-params.rs | 1 - tests/ui/span/macro-ty-params.stderr | 8 +------- 10 files changed, 70 insertions(+), 48 deletions(-) delete mode 100644 tests/crashes/123911.rs delete mode 100644 tests/crashes/123912.rs rename tests/{crashes/97006.rs => ui/macros/genercs-in-path-with-prettry-hir.rs} (83%) create mode 100644 tests/ui/macros/genercs-in-path-with-prettry-hir.stderr create mode 100644 tests/ui/macros/genercs-in-path-with-prettry-hir.stdout create mode 100644 tests/ui/macros/macro-expand-within-generics-in-path.rs create mode 100644 tests/ui/macros/macro-expand-within-generics-in-path.stderr diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index b97ec8c613d91..3636a3579781b 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -160,7 +160,7 @@ impl<'a> Parser<'a> { style: PathStyle, ty_generics: Option<&Generics>, ) -> PResult<'a, Path> { - let reject_generics_if_mod_style = |parser: &Parser<'_>, path: &Path| { + let reject_generics_if_mod_style = |parser: &Parser<'_>, path: Path| { // Ensure generic arguments don't end up in attribute paths, such as: // // macro_rules! m { @@ -178,21 +178,26 @@ impl<'a> Parser<'a> { .map(|arg| arg.span()) .collect::>(); parser.dcx().emit_err(errors::GenericsInPath { span }); + // Ignore these arguments to prevent unexpected behaviors. + let segments = path + .segments + .iter() + .map(|segment| PathSegment { ident: segment.ident, id: segment.id, args: None }) + .collect(); + Path { segments, ..path } + } else { + path } }; - maybe_whole!(self, NtPath, |path| { - reject_generics_if_mod_style(self, &path); - path.into_inner() - }); + maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner())); if let token::Interpolated(nt) = &self.token.kind { if let token::NtTy(ty) = &nt.0 { if let ast::TyKind::Path(None, path) = &ty.kind { let path = path.clone(); self.bump(); - reject_generics_if_mod_style(self, &path); - return Ok(path); + return Ok(reject_generics_if_mod_style(self, path)); } } } diff --git a/tests/crashes/123911.rs b/tests/crashes/123911.rs deleted file mode 100644 index 1a4d6a7951281..0000000000000 --- a/tests/crashes/123911.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ known-bug: #123911 - -macro_rules! m { - ($attr_path: path) => { - #[$attr_path] - fn f() {} - } -} - -m!(inline<{ - let a = CharCharFloat { a: 1 }; - let b = rustrt::rust_dbg_abi_4(a); - println!("a: {}", b.a); -}>); - -fn main() {} diff --git a/tests/crashes/123912.rs b/tests/crashes/123912.rs deleted file mode 100644 index 35216caabcdbf..0000000000000 --- a/tests/crashes/123912.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ known-bug: #123912 - -macro_rules! m { - ($attr_path: path) => { - #[$attr_path] - fn f() {} - } -} - -m!(inline<{ - let a = CharCharFloat { a: 1 }; - println!("a: {}", a); -}>); - -fn main() {} diff --git a/tests/crashes/97006.rs b/tests/ui/macros/genercs-in-path-with-prettry-hir.rs similarity index 83% rename from tests/crashes/97006.rs rename to tests/ui/macros/genercs-in-path-with-prettry-hir.rs index c8dfa52ebee07..84370fcebbcbc 100644 --- a/tests/crashes/97006.rs +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.rs @@ -1,7 +1,6 @@ -//@ known-bug: #97006 //@ compile-flags: -Zunpretty=hir -#![allow(unused)] +// issue#97006 macro_rules! m { ($attr_path: path) => { diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr b/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr new file mode 100644 index 0000000000000..8fcc7c6fbff06 --- /dev/null +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stderr @@ -0,0 +1,8 @@ +error: unexpected generic arguments in path + --> $DIR/genercs-in-path-with-prettry-hir.rs:12:10 + | +LL | m!(inline); + | ^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout new file mode 100644 index 0000000000000..e9ee59abfae8d --- /dev/null +++ b/tests/ui/macros/genercs-in-path-with-prettry-hir.stdout @@ -0,0 +1,15 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +//@ compile-flags: -Zunpretty=hir + +// issue#97006 + +macro_rules! m { ($attr_path: path) => { #[$attr_path] fn f() {} } } +#[ + +inline] +fn f() { } + +fn main() { } diff --git a/tests/ui/macros/macro-expand-within-generics-in-path.rs b/tests/ui/macros/macro-expand-within-generics-in-path.rs new file mode 100644 index 0000000000000..017d5152221bf --- /dev/null +++ b/tests/ui/macros/macro-expand-within-generics-in-path.rs @@ -0,0 +1,19 @@ +// issue#123911 +// issue#123912 + +macro_rules! m { + ($p: path) => { + #[$p] + struct S; + }; +} + +macro_rules! p { + () => {}; +} + +m!(generic); +//~^ ERROR: unexpected generic arguments in path +//~| ERROR: cannot find attribute `generic` in this scope + +fn main() {} diff --git a/tests/ui/macros/macro-expand-within-generics-in-path.stderr b/tests/ui/macros/macro-expand-within-generics-in-path.stderr new file mode 100644 index 0000000000000..72026c41050a2 --- /dev/null +++ b/tests/ui/macros/macro-expand-within-generics-in-path.stderr @@ -0,0 +1,14 @@ +error: unexpected generic arguments in path + --> $DIR/macro-expand-within-generics-in-path.rs:15:11 + | +LL | m!(generic); + | ^^^^^^ + +error: cannot find attribute `generic` in this scope + --> $DIR/macro-expand-within-generics-in-path.rs:15:4 + | +LL | m!(generic); + | ^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/span/macro-ty-params.rs b/tests/ui/span/macro-ty-params.rs index cf28b0255d17d..c7ce9b9faed09 100644 --- a/tests/ui/span/macro-ty-params.rs +++ b/tests/ui/span/macro-ty-params.rs @@ -11,5 +11,4 @@ fn main() { foo::<>!(); //~ ERROR generic arguments in macro path m!(Default<>); //~^ ERROR unexpected generic arguments in path - //~^^ ERROR generic arguments in macro path } diff --git a/tests/ui/span/macro-ty-params.stderr b/tests/ui/span/macro-ty-params.stderr index 7023ef8cd1c33..138cd2598a1c5 100644 --- a/tests/ui/span/macro-ty-params.stderr +++ b/tests/ui/span/macro-ty-params.stderr @@ -16,11 +16,5 @@ error: unexpected generic arguments in path LL | m!(Default<>); | ^^ -error: generic arguments in macro path - --> $DIR/macro-ty-params.rs:12:15 - | -LL | m!(Default<>); - | ^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors