Skip to content

Commit 7c76587

Browse files
committed
Auto merge of #116044 - cuviper:beta-next, r=cuviper
[beta] backports - Fix a pthread_t handle leak #114696 - MCP661: Move wasm32-wasi-preview1-threads target to Tier 2 #115345 - Don't modify libstd to dump rustc ICEs #115627 - Paper over an accidental regression #115844 - Update to LLVM 17.0.0 #115959 r? cuviper
2 parents 9b95397 + fff45e9 commit 7c76587

File tree

16 files changed

+153
-92
lines changed

16 files changed

+153
-92
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
[submodule "src/llvm-project"]
3434
path = src/llvm-project
3535
url = https://github.com/rust-lang/llvm-project.git
36-
branch = rustc/17.0-2023-07-29
36+
branch = rustc/17.0-2023-09-19
3737
shallow = true
3838
[submodule "src/doc/embedded-book"]
3939
path = src/doc/embedded-book

compiler/rustc_driver_impl/src/lib.rs

+54-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
88
#![feature(lazy_cell)]
99
#![feature(decl_macro)]
10-
#![feature(ice_to_disk)]
10+
#![feature(panic_update_hook)]
1111
#![feature(let_chains)]
1212
#![recursion_limit = "256"]
1313
#![allow(rustc::potential_query_instability)]
@@ -50,9 +50,9 @@ use std::collections::BTreeMap;
5050
use std::env;
5151
use std::ffi::OsString;
5252
use std::fmt::Write as _;
53-
use std::fs;
53+
use std::fs::{self, File};
5454
use std::io::{self, IsTerminal, Read, Write};
55-
use std::panic::{self, catch_unwind};
55+
use std::panic::{self, catch_unwind, PanicInfo};
5656
use std::path::PathBuf;
5757
use std::process::{self, Command, Stdio};
5858
use std::str;
@@ -1363,31 +1363,59 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
13631363
std::env::set_var("RUST_BACKTRACE", "full");
13641364
}
13651365

1366-
panic::set_hook(Box::new(move |info| {
1367-
// If the error was caused by a broken pipe then this is not a bug.
1368-
// Write the error and return immediately. See #98700.
1369-
#[cfg(windows)]
1370-
if let Some(msg) = info.payload().downcast_ref::<String>() {
1371-
if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)") {
1372-
// the error code is already going to be reported when the panic unwinds up the stack
1373-
let handler = EarlyErrorHandler::new(ErrorOutputType::default());
1374-
let _ = handler.early_error_no_abort(msg.clone());
1375-
return;
1376-
}
1377-
};
1378-
1379-
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
1380-
// Don't do this for delayed bugs, which already emit their own more useful backtrace.
1381-
if !info.payload().is::<rustc_errors::DelayedBugPanic>() {
1382-
std::panic_hook_with_disk_dump(info, ice_path().as_deref());
1366+
panic::update_hook(Box::new(
1367+
move |default_hook: &(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static),
1368+
info: &PanicInfo<'_>| {
1369+
// If the error was caused by a broken pipe then this is not a bug.
1370+
// Write the error and return immediately. See #98700.
1371+
#[cfg(windows)]
1372+
if let Some(msg) = info.payload().downcast_ref::<String>() {
1373+
if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)")
1374+
{
1375+
// the error code is already going to be reported when the panic unwinds up the stack
1376+
let handler = EarlyErrorHandler::new(ErrorOutputType::default());
1377+
let _ = handler.early_error_no_abort(msg.clone());
1378+
return;
1379+
}
1380+
};
13831381

1384-
// Separate the output with an empty line
1385-
eprintln!();
1386-
}
1382+
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
1383+
// Don't do this for delayed bugs, which already emit their own more useful backtrace.
1384+
if !info.payload().is::<rustc_errors::DelayedBugPanic>() {
1385+
default_hook(info);
1386+
// Separate the output with an empty line
1387+
eprintln!();
1388+
1389+
if let Some(ice_path) = ice_path()
1390+
&& let Ok(mut out) =
1391+
File::options().create(true).append(true).open(&ice_path)
1392+
{
1393+
// The current implementation always returns `Some`.
1394+
let location = info.location().unwrap();
1395+
let msg = match info.payload().downcast_ref::<&'static str>() {
1396+
Some(s) => *s,
1397+
None => match info.payload().downcast_ref::<String>() {
1398+
Some(s) => &s[..],
1399+
None => "Box<dyn Any>",
1400+
},
1401+
};
1402+
let thread = std::thread::current();
1403+
let name = thread.name().unwrap_or("<unnamed>");
1404+
let _ = write!(
1405+
&mut out,
1406+
"thread '{name}' panicked at {location}:\n\
1407+
{msg}\n\
1408+
stack backtrace:\n\
1409+
{:#}",
1410+
std::backtrace::Backtrace::force_capture()
1411+
);
1412+
}
1413+
}
13871414

1388-
// Print the ICE message
1389-
report_ice(info, bug_report_url, extra_info);
1390-
}));
1415+
// Print the ICE message
1416+
report_ice(info, bug_report_url, extra_info);
1417+
},
1418+
));
13911419
}
13921420

13931421
/// Prints the ICE message, including query stack, but without backtrace.

compiler/rustc_hir_analysis/src/check/check.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,15 @@ fn check_opaque_meets_bounds<'tcx>(
461461
}
462462
match origin {
463463
// Checked when type checking the function containing them.
464-
hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..) => {}
464+
hir::OpaqueTyOrigin::FnReturn(..) | hir::OpaqueTyOrigin::AsyncFn(..) => {
465+
// HACK: this should also fall through to the hidden type check below, but the original
466+
// implementation had a bug where equivalent lifetimes are not identical. This caused us
467+
// to reject existing stable code that is otherwise completely fine. The real fix is to
468+
// compare the hidden types via our type equivalence/relation infra instead of doing an
469+
// identity check.
470+
let _ = infcx.take_opaque_types();
471+
return Ok(());
472+
}
465473
// Nested opaque types occur only in associated types:
466474
// ` type Opaque<T> = impl Trait<&'static T, AssocTy = impl Nested>; `
467475
// They can only be referenced as `<Opaque<T> as Trait<&'static T>>::AssocTy`.

library/std/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,6 @@ pub mod alloc;
613613
// Private support modules
614614
mod panicking;
615615

616-
#[unstable(feature = "ice_to_disk", issue = "none")]
617-
pub use panicking::panic_hook_with_disk_dump;
618-
619616
#[path = "../../backtrace/src/lib.rs"]
620617
#[allow(dead_code, unused_attributes, fuzzy_provenance_casts)]
621618
mod backtrace_rs;

library/std/src/panicking.rs

+7-29
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,6 @@ where
236236

237237
/// The default panic handler.
238238
fn default_hook(info: &PanicInfo<'_>) {
239-
panic_hook_with_disk_dump(info, None)
240-
}
241-
242-
#[unstable(feature = "ice_to_disk", issue = "none")]
243-
/// The implementation of the default panic handler.
244-
///
245-
/// It can also write the backtrace to a given `path`. This functionality is used only by `rustc`.
246-
pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path::Path>) {
247239
// If this is a double panic, make sure that we print a backtrace
248240
// for this panic. Otherwise only print it if logging is enabled.
249241
let backtrace = if panic_count::get_count() >= 2 {
@@ -265,7 +257,7 @@ pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path
265257
let thread = thread_info::current_thread();
266258
let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
267259

268-
let write = |err: &mut dyn crate::io::Write, backtrace: Option<BacktraceStyle>| {
260+
let write = |err: &mut dyn crate::io::Write| {
269261
let _ = writeln!(err, "thread '{name}' panicked at {location}:\n{msg}");
270262

271263
static FIRST_PANIC: AtomicBool = AtomicBool::new(true);
@@ -279,37 +271,23 @@ pub fn panic_hook_with_disk_dump(info: &PanicInfo<'_>, path: Option<&crate::path
279271
}
280272
Some(BacktraceStyle::Off) => {
281273
if FIRST_PANIC.swap(false, Ordering::SeqCst) {
282-
if let Some(path) = path {
283-
let _ = writeln!(
284-
err,
285-
"note: a backtrace for this error was stored at `{}`",
286-
path.display(),
287-
);
288-
} else {
289-
let _ = writeln!(
290-
err,
291-
"note: run with `RUST_BACKTRACE=1` environment variable to display a \
274+
let _ = writeln!(
275+
err,
276+
"note: run with `RUST_BACKTRACE=1` environment variable to display a \
292277
backtrace"
293-
);
294-
}
278+
);
295279
}
296280
}
297281
// If backtraces aren't supported, do nothing.
298282
None => {}
299283
}
300284
};
301285

302-
if let Some(path) = path
303-
&& let Ok(mut out) = crate::fs::File::options().create(true).append(true).open(&path)
304-
{
305-
write(&mut out, BacktraceStyle::full());
306-
}
307-
308286
if let Some(local) = set_output_capture(None) {
309-
write(&mut *local.lock().unwrap_or_else(|e| e.into_inner()), backtrace);
287+
write(&mut *local.lock().unwrap_or_else(|e| e.into_inner()));
310288
set_output_capture(Some(local));
311289
} else if let Some(mut out) = panic_output() {
312-
write(&mut out, backtrace);
290+
write(&mut out);
313291
}
314292
}
315293

library/std/src/sys/wasi/thread.rs

+8
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ cfg_if::cfg_if! {
4747
stack_size: libc::size_t,
4848
) -> ffi::c_int;
4949
pub fn pthread_attr_destroy(attr: *mut pthread_attr_t) -> ffi::c_int;
50+
pub fn pthread_detach(thread: pthread_t) -> ffi::c_int;
5051
}
5152
}
5253

5354
pub struct Thread {
5455
id: libc::pthread_t,
5556
}
57+
58+
impl Drop for Thread {
59+
fn drop(&mut self) {
60+
let ret = unsafe { libc::pthread_detach(self.id) };
61+
debug_assert_eq!(ret, 0);
62+
}
63+
}
5664
} else {
5765
pub struct Thread(!);
5866
}

src/ci/docker/host-x86_64/dist-various-2/build-wasi-threads-toolchain.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin"
1010
git clone https://github.com/WebAssembly/wasi-libc
1111

1212
cd wasi-libc
13-
git reset --hard 7018e24d8fe248596819d2e884761676f3542a04
13+
git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087
1414
make -j$(nproc) \
1515
CC="$bin/clang" \
1616
NM="$bin/llvm-nm" \

src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin"
1010
git clone https://github.com/WebAssembly/wasi-libc
1111

1212
cd wasi-libc
13-
git reset --hard 7018e24d8fe248596819d2e884761676f3542a04
13+
git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087
1414
make -j$(nproc) \
1515
CC="$bin/clang" \
1616
NM="$bin/llvm-nm" \

src/doc/rustc/src/platform-support.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ target | std | notes
180180
`wasm32-unknown-emscripten` | ✓ | WebAssembly via Emscripten
181181
`wasm32-unknown-unknown` | ✓ | WebAssembly
182182
`wasm32-wasi` | ✓ | WebAssembly with WASI
183+
[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | WebAssembly with WASI Preview 1 and threads
183184
`x86_64-apple-ios` | ✓ | 64-bit x86 iOS
184185
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
185186
`x86_64-fuchsia` | ✓ | Alias for `x86_64-unknown-fuchsia`
@@ -321,7 +322,6 @@ target | std | host | notes
321322
`thumbv7a-pc-windows-msvc` | ? | |
322323
`thumbv7a-uwp-windows-msvc` | ✓ | |
323324
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL
324-
[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | WebAssembly with WASI Preview 1 and threads
325325
[`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly
326326
`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64
327327
[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS

src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `wasm32-wasi-preview1-threads`
22

3-
**Tier: 3**
3+
**Tier: 2**
44

55
The `wasm32-wasi-preview1-threads` target is a new and still (as of July 2023) an
66
experimental target. This target is an extension to `wasm32-wasi-preview1` target,
@@ -70,12 +70,6 @@ compile `wasm32-wasi-preview1-threads` binaries straight out of the box. You can
7070
reliably interoperate with C code in this mode (yet).
7171

7272

73-
This target is not a stable target. This means that there are not many engines
74-
which implement the `wasi-threads` feature and if they do they're likely behind a
75-
flag, for example:
76-
77-
* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads`
78-
7973
Also note that at this time the `wasm32-wasi-preview1-threads` target assumes the
8074
presence of other merged wasm proposals such as (with their LLVM feature flags):
8175

@@ -94,6 +88,17 @@ The target intends to match the corresponding Clang target for its `"C"` ABI.
9488
> found it's recommended to open an issue either with rust-lang/rust or ideally
9589
> with LLVM itself.
9690
91+
## Platform requirements
92+
93+
The runtime should support the same set of APIs as any other supported wasi target for interacting with the host environment through the WASI standard. The runtime also should have implemetation of [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads).
94+
95+
This target is not a stable target. This means that there are a few engines
96+
which implement the `wasi-threads` feature and if they do they're likely behind a
97+
flag, for example:
98+
99+
* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads`
100+
* [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) - needs to be built with WAMR_BUILD_LIB_WASI_THREADS=1
101+
97102
## Building the target
98103

99104
Users need to install or built wasi-sdk since release 20.0
@@ -110,12 +115,16 @@ After that users can build this by adding it to the `target` list in
110115

111116
## Building Rust programs
112117

113-
Since it is Tier 3, rust doesn't ship pre-compiled artifacts for this target.
118+
From Rust Nightly 1.71.1 (2023-08-03) on the artifacts are shipped pre-compiled:
119+
120+
```text
121+
rustup target add wasm32-wasi-preview1-threads --toolchain nightly
122+
```
123+
124+
Rust programs can be built for that target:
114125

115-
Specify `wasi-root` as explained in the previous section and then use the `build-std`
116-
nightly cargo feature to build the standard library:
117-
```shell
118-
cargo +nightly build --target=wasm32-wasi-preview1-threads -Zbuild-std
126+
```text
127+
rustc --target wasm32-wasi-preview1-threads your-code.rs
119128
```
120129

121130
## Cross-compilation

src/llvm-project

Submodule llvm-project updated 495 files

tests/run-make/dump-ice-to-disk/check.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ rm $TMPDIR/rustc-ice-*.txt
2222
# Explicitly disabling ICE dump
2323
export RUSTC_ICE=0
2424
$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-disabled.log 2>&1
25-
should_be_empty_tmp=$(ls -l $TMPDIR/rustc-ice-*.txt | wc -l)
26-
should_be_empty_dot=$(ls -l ./rustc-ice-*.txt | wc -l)
25+
should_be_empty_tmp=$(ls -l $TMPDIR/rustc-ice-*.txt 2>/dev/null | wc -l)
26+
should_be_empty_dot=$(ls -l ./rustc-ice-*.txt 2>/dev/null | wc -l)
2727

2828
echo "#### ICE Dump content:"
2929
echo $content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! This test shows a situation where through subtle compiler changes we can
2+
//! suddenly infer a different lifetime in the hidden type, and thus not meet
3+
//! the opaque type bounds anymore. In this case `'a` and `'b` are equal, so
4+
//! picking either is fine, but then we'll fail an identity check of the hidden
5+
//! type and the expected hidden type.
6+
7+
// check-pass
8+
9+
fn test<'a: 'b, 'b: 'a>() -> impl IntoIterator<Item = (&'a u8, impl Into<(&'b u8, &'a u8)>)> {
10+
None::<(_, (_, _))>
11+
}
12+
13+
fn main() {}

tests/ui/match/issue-115681.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// run-pass
2+
// compile-flags: -C opt-level=1
3+
4+
// Make sure LLVM does not miscompile this match.
5+
fn main() {
6+
enum Bits {
7+
None = 0x00,
8+
Low = 0x40,
9+
High = 0x80,
10+
Both = 0xC0,
11+
}
12+
13+
let value = Box::new(0x40u8);
14+
let mut out = Box::new(0u8);
15+
16+
let bits = match *value {
17+
0x00 => Bits::None,
18+
0x40 => Bits::Low,
19+
0x80 => Bits::High,
20+
0xC0 => Bits::Both,
21+
_ => return,
22+
};
23+
24+
match bits {
25+
Bits::None | Bits::Low => {
26+
*out = 1;
27+
}
28+
_ => (),
29+
}
30+
31+
assert_eq!(*out, 1);
32+
}

tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn without_lt() -> impl for<'a> Trait<'a, Assoc = WithoutLt> {}
88
//~^ ERROR captures lifetime that does not appear in bounds
99

1010
type WithLt<'a> = impl Sized + 'a;
11-
//~^ ERROR concrete type differs from previous defining opaque type use
11+
1212
fn with_lt() -> impl for<'a> Trait<'a, Assoc = WithLt<'a>> {}
1313
//~^ ERROR expected generic lifetime parameter, found `'a`
1414

0 commit comments

Comments
 (0)