Skip to content

Commit b90dc1e

Browse files
committed
Auto merge of #153392 - matthiaskrgr:rollup-UDvxmNA, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #153341 (std: refactor Xous startup code) - #152816 (Check for region dependent goals on type_op itself as well) - #153224 (Fix LegacyKeyValueFormat report from docker build: disabled) - #153274 (Fix async drop multi crate crash) - #153324 (fix autodiff parsing for non-trait impl)
2 parents d933cf4 + e42a3ba commit b90dc1e

File tree

31 files changed

+469
-211
lines changed

31 files changed

+469
-211
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ mod llvm_enzyme {
214214
// first get information about the annotable item: visibility, signature, name and generic
215215
// parameters.
216216
// these will be used to generate the differentiated version of the function
217-
let Some((vis, sig, primal, generics, impl_of_trait)) = (match &item {
217+
let Some((vis, sig, primal, generics, is_impl)) = (match &item {
218218
Annotatable::Item(iitem) => {
219219
extract_item_info(iitem).map(|(v, s, p, g)| (v, s, p, g, false))
220220
}
@@ -224,13 +224,13 @@ mod llvm_enzyme {
224224
}
225225
_ => None,
226226
},
227-
Annotatable::AssocItem(assoc_item, Impl { of_trait }) => match &assoc_item.kind {
227+
Annotatable::AssocItem(assoc_item, Impl { of_trait: _ }) => match &assoc_item.kind {
228228
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => Some((
229229
assoc_item.vis.clone(),
230230
sig.clone(),
231231
ident.clone(),
232232
generics.clone(),
233-
*of_trait,
233+
true,
234234
)),
235235
_ => None,
236236
},
@@ -328,7 +328,7 @@ mod llvm_enzyme {
328328
span,
329329
&d_sig,
330330
&generics,
331-
impl_of_trait,
331+
is_impl,
332332
)],
333333
);
334334

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Destructor>
133133
}
134134

135135
fn adt_async_destructor(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::AsyncDestructor> {
136-
tcx.calculate_async_dtor(def_id, always_applicable::check_drop_impl)
136+
let result = tcx.calculate_async_dtor(def_id, always_applicable::check_drop_impl);
137+
// Async drop in libstd/libcore would become insta-stable — catch that mistake.
138+
if result.is_some() && tcx.features().staged_api() {
139+
span_bug!(tcx.def_span(def_id), "don't use async drop in libstd, it becomes insta-stable");
140+
}
141+
result
137142
}
138143

139144
/// Given a `DefId` for an opaque type in return position, find its parent item's return

compiler/rustc_mir_transform/src/elaborate_drop.rs

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,8 @@ where
422422

423423
fn build_drop(&mut self, bb: BasicBlock) {
424424
let drop_ty = self.place_ty(self.place);
425-
if self.tcx().features().async_drop()
426-
&& self.elaborator.body().coroutine.is_some()
427-
&& self.elaborator.allow_async_drops()
428-
&& !self.elaborator.patch_ref().block(self.elaborator.body(), bb).is_cleanup
429-
&& drop_ty.needs_async_drop(self.tcx(), self.elaborator.typing_env())
425+
if !self.elaborator.patch_ref().block(self.elaborator.body(), bb).is_cleanup
426+
&& self.check_if_can_async_drop(drop_ty, false)
430427
{
431428
self.build_async_drop(
432429
self.place,
@@ -452,6 +449,46 @@ where
452449
}
453450
}
454451

452+
/// Function to check if we can generate an async drop here
453+
fn check_if_can_async_drop(&mut self, drop_ty: Ty<'tcx>, call_destructor_only: bool) -> bool {
454+
let is_async_drop_feature_enabled = if self.tcx().features().async_drop() {
455+
true
456+
} else {
457+
// Check if the type needing async drop comes from a dependency crate.
458+
if let ty::Adt(adt_def, _) = drop_ty.kind() {
459+
!adt_def.did().is_local() && adt_def.async_destructor(self.tcx()).is_some()
460+
} else {
461+
false
462+
}
463+
};
464+
465+
// Short-circuit before calling needs_async_drop/is_async_drop, as those
466+
// require the `async_drop` lang item to exist (which may not be present
467+
// in minimal/custom core environments like cranelift's mini_core).
468+
if !is_async_drop_feature_enabled
469+
|| !self.elaborator.body().coroutine.is_some()
470+
|| !self.elaborator.allow_async_drops()
471+
{
472+
return false;
473+
}
474+
475+
let needs_async_drop = if call_destructor_only {
476+
drop_ty.is_async_drop(self.tcx(), self.elaborator.typing_env())
477+
} else {
478+
drop_ty.needs_async_drop(self.tcx(), self.elaborator.typing_env())
479+
};
480+
481+
// Async drop in libstd/libcore would become insta-stable — catch that mistake.
482+
if needs_async_drop && self.tcx().features().staged_api() {
483+
span_bug!(
484+
self.source_info.span,
485+
"don't use async drop in libstd, it becomes insta-stable"
486+
);
487+
}
488+
489+
needs_async_drop
490+
}
491+
455492
/// This elaborates a single drop instruction, located at `bb`, and
456493
/// patches over it.
457494
///
@@ -1003,12 +1040,7 @@ where
10031040
) -> BasicBlock {
10041041
debug!("destructor_call_block({:?}, {:?})", self, succ);
10051042
let ty = self.place_ty(self.place);
1006-
if self.tcx().features().async_drop()
1007-
&& self.elaborator.body().coroutine.is_some()
1008-
&& self.elaborator.allow_async_drops()
1009-
&& !unwind.is_cleanup()
1010-
&& ty.is_async_drop(self.tcx(), self.elaborator.typing_env())
1011-
{
1043+
if !unwind.is_cleanup() && self.check_if_can_async_drop(ty, true) {
10121044
self.build_async_drop(self.place, ty, None, succ, unwind, dropline, true)
10131045
} else {
10141046
self.destructor_call_block_sync((succ, unwind))
@@ -1078,12 +1110,7 @@ where
10781110
let loop_block = self.elaborator.patch().new_block(loop_block);
10791111

10801112
let place = tcx.mk_place_deref(ptr);
1081-
if self.tcx().features().async_drop()
1082-
&& self.elaborator.body().coroutine.is_some()
1083-
&& self.elaborator.allow_async_drops()
1084-
&& !unwind.is_cleanup()
1085-
&& ety.needs_async_drop(self.tcx(), self.elaborator.typing_env())
1086-
{
1113+
if !unwind.is_cleanup() && self.check_if_can_async_drop(ety, false) {
10871114
self.build_async_drop(
10881115
place,
10891116
ety,
@@ -1368,12 +1395,7 @@ where
13681395

13691396
fn drop_block(&mut self, target: BasicBlock, unwind: Unwind) -> BasicBlock {
13701397
let drop_ty = self.place_ty(self.place);
1371-
if self.tcx().features().async_drop()
1372-
&& self.elaborator.body().coroutine.is_some()
1373-
&& self.elaborator.allow_async_drops()
1374-
&& !unwind.is_cleanup()
1375-
&& drop_ty.needs_async_drop(self.tcx(), self.elaborator.typing_env())
1376-
{
1398+
if !unwind.is_cleanup() && self.check_if_can_async_drop(drop_ty, false) {
13771399
self.build_async_drop(
13781400
self.place,
13791401
drop_ty,

compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,40 @@ where
9292
let value = infcx.commit_if_ok(|_| {
9393
let ocx = ObligationCtxt::new(infcx);
9494
let value = op(&ocx).map_err(|_| {
95-
infcx.dcx().span_delayed_bug(span, format!("error performing operation: {name}"))
95+
infcx.tcx.check_potentially_region_dependent_goals(root_def_id).err().unwrap_or_else(
96+
// FIXME: In this region-dependent context, `type_op` should only fail due to
97+
// region-dependent goals. Any other kind of failure indicates a bug and we
98+
// should ICE.
99+
//
100+
// In principle, all non-region errors are expected to be emitted before
101+
// borrowck. Such errors should taint the body and prevent borrowck from
102+
// running at all. However, this invariant does not currently hold.
103+
//
104+
// Consider:
105+
//
106+
// ```ignore (illustrative)
107+
// struct Foo<T>(T)
108+
// where
109+
// T: Iterator,
110+
// <T as Iterator>::Item: Default;
111+
//
112+
// fn foo<T>() -> Foo<T> {
113+
// loop {}
114+
// }
115+
// ```
116+
//
117+
// Here, `fn foo` ought to error and taint the body before MIR build, since
118+
// `Foo<T>` is not well-formed. However, we currently avoid checking this
119+
// during HIR typeck to prevent duplicate diagnostics.
120+
//
121+
// If we ICE here on any non-region-dependent failure, we would trigger ICEs
122+
// too often for such cases. For now, we emit a delayed bug instead.
123+
|| {
124+
infcx
125+
.dcx()
126+
.span_delayed_bug(span, format!("error performing operation: {name}"))
127+
},
128+
)
96129
})?;
97130
let errors = ocx.evaluate_obligations_error_on_ambiguity();
98131
if errors.is_empty() {

library/std/src/sys/args/xous.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
pub use super::common::Args;
2-
use crate::sys::pal::os::get_application_parameters;
3-
use crate::sys::pal::os::params::ArgumentList;
2+
use crate::sys::pal::params::{self, ArgumentList};
43

54
pub fn args() -> Args {
6-
let Some(params) = get_application_parameters() else {
5+
let Some(params) = params::get() else {
76
return Args::new(vec![]);
87
};
98

library/std/src/sys/env/xous.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::ffi::{OsStr, OsString};
44
use crate::io;
55
use crate::sync::atomic::{Atomic, AtomicUsize, Ordering};
66
use crate::sync::{Mutex, Once};
7-
use crate::sys::pal::os::{get_application_parameters, params};
7+
use crate::sys::pal::params;
88

99
static ENV: Atomic<usize> = AtomicUsize::new(0);
1010
static ENV_INIT: Once = Once::new();
@@ -13,7 +13,7 @@ type EnvStore = Mutex<HashMap<OsString, OsString>>;
1313
fn get_env_store() -> &'static EnvStore {
1414
ENV_INIT.call_once(|| {
1515
let env_store = EnvStore::default();
16-
if let Some(params) = get_application_parameters() {
16+
if let Some(params) = params::get() {
1717
for param in params {
1818
if let Ok(envs) = params::EnvironmentBlock::try_from(&param) {
1919
let mut env_store = env_store.lock().unwrap();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
11
#![forbid(unsafe_op_in_unsafe_fn)]
22

33
pub mod os;
4+
pub mod params;
45

56
#[path = "../unsupported/common.rs"]
67
mod common;
78
pub use common::*;
9+
10+
#[cfg(not(test))]
11+
#[cfg(feature = "panic-unwind")]
12+
mod eh_unwinding {
13+
pub(crate) struct EhFrameFinder;
14+
pub(crate) static mut EH_FRAME_ADDRESS: usize = 0;
15+
pub(crate) static EH_FRAME_SETTINGS: EhFrameFinder = EhFrameFinder;
16+
17+
unsafe impl unwind::EhFrameFinder for EhFrameFinder {
18+
fn find(&self, _pc: usize) -> Option<unwind::FrameInfo> {
19+
if unsafe { EH_FRAME_ADDRESS == 0 } {
20+
None
21+
} else {
22+
Some(unwind::FrameInfo {
23+
text_base: None,
24+
kind: unwind::FrameInfoKind::EhFrame(unsafe { EH_FRAME_ADDRESS }),
25+
})
26+
}
27+
}
28+
}
29+
}
30+
31+
#[cfg(not(test))]
32+
mod c_compat {
33+
use crate::os::xous::ffi::exit;
34+
35+
unsafe extern "C" {
36+
fn main() -> u32;
37+
}
38+
39+
#[unsafe(no_mangle)]
40+
pub extern "C" fn abort() {
41+
exit(1);
42+
}
43+
44+
#[unsafe(no_mangle)]
45+
pub extern "C" fn _start(eh_frame: usize, params: *mut u8) {
46+
#[cfg(feature = "panic-unwind")]
47+
{
48+
unsafe { super::eh_unwinding::EH_FRAME_ADDRESS = eh_frame };
49+
unwind::set_custom_eh_frame_finder(&super::eh_unwinding::EH_FRAME_SETTINGS).ok();
50+
}
51+
52+
unsafe { super::params::set(params) };
53+
exit(unsafe { main() });
54+
}
55+
}

library/std/src/sys/pal/xous/os.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,8 @@ use super::unsupported;
22
use crate::ffi::{OsStr, OsString};
33
use crate::marker::PhantomData;
44
use crate::path::{self, PathBuf};
5-
use crate::sync::atomic::{Atomic, AtomicPtr, Ordering};
65
use crate::{fmt, io};
76

8-
pub(crate) mod params;
9-
10-
static PARAMS_ADDRESS: Atomic<*mut u8> = AtomicPtr::new(core::ptr::null_mut());
11-
12-
#[cfg(not(test))]
13-
#[cfg(feature = "panic-unwind")]
14-
mod eh_unwinding {
15-
pub(crate) struct EhFrameFinder;
16-
pub(crate) static mut EH_FRAME_ADDRESS: usize = 0;
17-
pub(crate) static EH_FRAME_SETTINGS: EhFrameFinder = EhFrameFinder;
18-
19-
unsafe impl unwind::EhFrameFinder for EhFrameFinder {
20-
fn find(&self, _pc: usize) -> Option<unwind::FrameInfo> {
21-
if unsafe { EH_FRAME_ADDRESS == 0 } {
22-
None
23-
} else {
24-
Some(unwind::FrameInfo {
25-
text_base: None,
26-
kind: unwind::FrameInfoKind::EhFrame(unsafe { EH_FRAME_ADDRESS }),
27-
})
28-
}
29-
}
30-
}
31-
}
32-
33-
#[cfg(not(test))]
34-
mod c_compat {
35-
use crate::os::xous::ffi::exit;
36-
unsafe extern "C" {
37-
fn main() -> u32;
38-
}
39-
40-
#[unsafe(no_mangle)]
41-
pub extern "C" fn abort() {
42-
exit(1);
43-
}
44-
45-
#[unsafe(no_mangle)]
46-
pub extern "C" fn _start(eh_frame: usize, params_address: usize) {
47-
#[cfg(feature = "panic-unwind")]
48-
{
49-
unsafe { super::eh_unwinding::EH_FRAME_ADDRESS = eh_frame };
50-
unwind::set_custom_eh_frame_finder(&super::eh_unwinding::EH_FRAME_SETTINGS).ok();
51-
}
52-
53-
if params_address != 0 {
54-
let params_address = crate::ptr::with_exposed_provenance_mut::<u8>(params_address);
55-
if unsafe {
56-
super::params::ApplicationParameters::new_from_ptr(params_address).is_some()
57-
} {
58-
super::PARAMS_ADDRESS.store(params_address, core::sync::atomic::Ordering::Relaxed);
59-
}
60-
}
61-
exit(unsafe { main() });
62-
}
63-
}
64-
657
pub fn getcwd() -> io::Result<PathBuf> {
668
unsupported()
679
}
@@ -106,11 +48,6 @@ pub fn current_exe() -> io::Result<PathBuf> {
10648
unsupported()
10749
}
10850

109-
pub(crate) fn get_application_parameters() -> Option<params::ApplicationParameters> {
110-
let params_address = PARAMS_ADDRESS.load(Ordering::Relaxed);
111-
unsafe { params::ApplicationParameters::new_from_ptr(params_address) }
112-
}
113-
11451
pub fn temp_dir() -> PathBuf {
11552
panic!("no filesystem on this platform")
11653
}

0 commit comments

Comments
 (0)