From d8fb568cf4889ec830e8b092cddc24b7d1c29a34 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 11 Jul 2023 11:27:51 +0200 Subject: [PATCH 01/13] fix spurious test failure with panic=abort --- tests/ui/panic-handler/weak-lang-item-2.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/ui/panic-handler/weak-lang-item-2.rs b/tests/ui/panic-handler/weak-lang-item-2.rs index a429d8fabc72b..6d6e8e04b05c2 100644 --- a/tests/ui/panic-handler/weak-lang-item-2.rs +++ b/tests/ui/panic-handler/weak-lang-item-2.rs @@ -6,10 +6,18 @@ extern crate weak_lang_items as other; -use std::thread; - fn main() { - let _ = thread::spawn(move|| { + let _ = std::thread::spawn(move || { + // The goal of the test is just to make sure other::foo() is called. Since the function + // panics, it's executed in its own thread. That way, the panic is isolated within the + // thread and wont't affect the overall exit code. + // + // That causes a spurious failures in panic=abort targets though: if the program exits + // before the thread is fully initialized the test will pass, but if the thread gets + // executed first the whole program will abort. Adding a 60 seconds sleep will (hopefully!) + // ensure the program always exits before the thread is executed. + std::thread::sleep(std::time::Duration::from_secs(60)); + other::foo() }); } From 57407a35552639c570893782d8c19cfad27dcc51 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 26 Jul 2023 22:29:52 +0000 Subject: [PATCH 02/13] Bubble up nested goals from equation in predicates_for_object_candidate --- .../src/solve/assembly/mod.rs | 16 ++++------ .../src/solve/assembly/structural_traits.rs | 31 +++++++++++-------- ...bject-soundness-requires-generalization.rs | 20 ++++++++++++ 3 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 tests/ui/traits/new-solver/object-soundness-requires-generalization.rs diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index ab90db6ff5869..b1c9d7f3d19dd 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -153,16 +153,12 @@ pub(super) trait GoalKind<'tcx>: let ty::Dynamic(bounds, _, _) = *goal.predicate.self_ty().kind() else { bug!("expected object type in `consider_object_bound_candidate`"); }; - ecx.add_goals( - structural_traits::predicates_for_object_candidate( - &ecx, - goal.param_env, - goal.predicate.trait_ref(tcx), - bounds, - ) - .into_iter() - .map(|pred| goal.with(tcx, pred)), - ); + ecx.add_goals(structural_traits::predicates_for_object_candidate( + &ecx, + goal.param_env, + goal.predicate.trait_ref(tcx), + bounds, + )); ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) }) } diff --git a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs index a2db35e069eb7..45dbd4b926940 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs @@ -3,6 +3,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::{def_id::DefId, Movability, Mutability}; use rustc_infer::traits::query::NoSolution; +use rustc_middle::traits::solve::Goal; use rustc_middle::ty::{ self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -345,7 +346,7 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>( param_env: ty::ParamEnv<'tcx>, trait_ref: ty::TraitRef<'tcx>, object_bound: &'tcx ty::List>, -) -> Vec> { +) -> Vec>> { let tcx = ecx.tcx(); let mut requirements = vec![]; requirements.extend( @@ -376,17 +377,22 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>( } } - requirements.fold_with(&mut ReplaceProjectionWith { - ecx, - param_env, - mapping: replace_projection_with, - }) + let mut folder = + ReplaceProjectionWith { ecx, param_env, mapping: replace_projection_with, nested: vec![] }; + let folded_requirements = requirements.fold_with(&mut folder); + + folder + .nested + .into_iter() + .chain(folded_requirements.into_iter().map(|clause| Goal::new(tcx, param_env, clause))) + .collect() } struct ReplaceProjectionWith<'a, 'tcx> { ecx: &'a EvalCtxt<'a, 'tcx>, param_env: ty::ParamEnv<'tcx>, mapping: FxHashMap>, + nested: Vec>>, } impl<'tcx> TypeFolder> for ReplaceProjectionWith<'_, 'tcx> { @@ -402,13 +408,12 @@ impl<'tcx> TypeFolder> for ReplaceProjectionWith<'_, 'tcx> { // but the where clauses we instantiated are not. We can solve this by instantiating // the binder at the usage site. let proj = self.ecx.instantiate_binder_with_infer(*replacement); - // FIXME: Technically this folder could be fallible? - let nested = self - .ecx - .eq_and_get_goals(self.param_env, alias_ty, proj.projection_ty) - .expect("expected to be able to unify goal projection with dyn's projection"); - // FIXME: Technically we could register these too.. - assert!(nested.is_empty(), "did not expect unification to have any nested goals"); + // FIXME: Technically this equate could be fallible... + self.nested.extend( + self.ecx + .eq_and_get_goals(self.param_env, alias_ty, proj.projection_ty) + .expect("expected to be able to unify goal projection with dyn's projection"), + ); proj.term.ty().unwrap() } else { ty.super_fold_with(self) diff --git a/tests/ui/traits/new-solver/object-soundness-requires-generalization.rs b/tests/ui/traits/new-solver/object-soundness-requires-generalization.rs new file mode 100644 index 0000000000000..d02dada72c916 --- /dev/null +++ b/tests/ui/traits/new-solver/object-soundness-requires-generalization.rs @@ -0,0 +1,20 @@ +// compile-flags: -Ztrait-solver=next +// ignore-test + +trait Trait { + type Gat<'lt>; +} +impl Trait for u8 { + type Gat<'lt> = u8; +} + +fn test::Gat<'_>) -> S + ?Sized, S>() {} + +fn main() { + // Proving `dyn FnOnce: FnOnce` requires making sure that all of the supertraits + // of the trait and associated type bounds hold. We check this in + // `predicates_for_object_candidate`, and eagerly replace projections using equality + // which may generalize a type and emit a nested AliasRelate goal. Make sure that + // we don't ICE in that case, and bubble that goal up to the caller. + test::::Gat<'_>) + 'static, _>(); +} From c9e83c02a2bc0b1e240733d78abca4e58953b6af Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 5 Aug 2023 12:47:46 +0900 Subject: [PATCH 03/13] Set max_atomic_width for AVR to 16 --- compiler/rustc_target/src/spec/avr_gnu_base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/avr_gnu_base.rs b/compiler/rustc_target/src/spec/avr_gnu_base.rs index fbec44b716a3e..cd324c94bbe8b 100644 --- a/compiler/rustc_target/src/spec/avr_gnu_base.rs +++ b/compiler/rustc_target/src/spec/avr_gnu_base.rs @@ -23,7 +23,7 @@ pub fn target(target_cpu: &'static str, mmcu: &'static str) -> Target { LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-lgcc"], ), - max_atomic_width: Some(0), + max_atomic_width: Some(16), atomic_cas: false, relocation_model: RelocModel::Static, ..TargetOptions::default() From 4d4df889347cca380d1279a1d42d8925ab626786 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 5 Aug 2023 13:01:15 +0900 Subject: [PATCH 04/13] Set max_atomic_width for sparc-unknown-linux-gnu to 32 --- compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs index 12968abda082e..b10e6264b73c3 100644 --- a/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/sparc_unknown_linux_gnu.rs @@ -5,7 +5,7 @@ pub fn target() -> Target { let mut base = super::linux_gnu_base::opts(); base.endian = Endian::Big; base.cpu = "v9".into(); - base.max_atomic_width = Some(64); + base.max_atomic_width = Some(32); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-mv8plus"]); Target { From 9941db45125f03f6f2c2e491b747e66f0f133415 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Sat, 5 Aug 2023 10:53:34 +0000 Subject: [PATCH 05/13] llvm-wrapper: adapt for LLVM API changes No functional changes intended. Adapts llvm-wrapper for https://github.com/llvm/llvm-project/commit/65e57bbed06d55cab7bb64d54891d33ccb2d4159. Found by our experimental rust + llvm @ HEAD CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/21304#0189c526-86cd-4db9-bdbc-dd0132dfc22b/197-500 --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index ebf8a50ae8b85..a986fa28f7881 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -1120,9 +1120,15 @@ struct LLVMRustThinLTOData { // Not 100% sure what these are, but they impact what's internalized and // what's inlined across modules, I believe. +#if LLVM_VERSION_GE(17, 0) + DenseMap ImportLists; + DenseMap ExportLists; + DenseMap ModuleToDefinedGVSummaries; +#else StringMap ImportLists; StringMap ExportLists; StringMap ModuleToDefinedGVSummaries; +#endif StringMap> ResolvedODR; LLVMRustThinLTOData() : Index(/* HaveGVs = */ false) {} From dee4cba955621d7608154abafc1ebbe7ec424df9 Mon Sep 17 00:00:00 2001 From: Taras Tsugrii Date: Sun, 6 Aug 2023 21:44:55 -0700 Subject: [PATCH 06/13] [miri][typo] Fix a typo in a vector_block comment. --- src/tools/miri/src/concurrency/vector_clock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/src/concurrency/vector_clock.rs b/src/tools/miri/src/concurrency/vector_clock.rs index a6e67ef8699df..fa93c9e00b14a 100644 --- a/src/tools/miri/src/concurrency/vector_clock.rs +++ b/src/tools/miri/src/concurrency/vector_clock.rs @@ -9,7 +9,7 @@ use std::{ /// A vector clock index, this is associated with a thread id /// but in some cases one vector index may be shared with -/// multiple thread ids if it safe to do so. +/// multiple thread ids if it's safe to do so. #[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] pub struct VectorIdx(u32); From 8d3360830ccc0d0edb2ed93bb6e59a7a028a9a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 7 Aug 2023 09:56:34 +0200 Subject: [PATCH 07/13] Do not hide CI error logs in a group when a failure happens --- src/ci/run.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ci/run.sh b/src/ci/run.sh index da1960fc05712..483cb42ae6a0c 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -154,13 +154,25 @@ fi # check for clock drifts. An HTTP URL is used instead of HTTPS since on Azure # Pipelines it happened that the certificates were marked as expired. datecheck() { - echo "::group::Clock drift check" + # If an error has happened, we do not want to start a new group, because that will collapse + # a previous group that might have contained the error log. + exit_code=$? + + if [ $exit_code -eq 0 ] + then + echo "::group::Clock drift check" + fi + echo -n " local time: " date echo -n " network time: " curl -fs --head http://ci-caches.rust-lang.org | grep ^Date: \ | sed 's/Date: //g' || true - echo "::endgroup::" + + if [ $exit_code -eq 0 ] + then + echo "::endgroup::" + fi } datecheck trap datecheck EXIT From 3f3262e592c51b0f39925a7a716d29b7a8e37ff4 Mon Sep 17 00:00:00 2001 From: Benedikt Radtke Date: Sun, 6 Aug 2023 23:20:53 +0200 Subject: [PATCH 08/13] stabilize abi_thiscall --- compiler/rustc_feature/src/accepted.rs | 2 + compiler/rustc_feature/src/active.rs | 2 - compiler/rustc_target/src/spec/abi.rs | 11 +- library/panic_unwind/src/lib.rs | 2 +- .../src/language-features/abi-thiscall.md | 12 -- .../crates/ide-db/src/generated/lints.rs | 16 --- .../unwind-abis/thiscall-unwind-abi.rs | 2 +- tests/ui/abi/unsupported.aarch64.stderr | 18 +-- tests/ui/abi/unsupported.arm.stderr | 16 +-- tests/ui/abi/unsupported.i686.stderr | 12 +- tests/ui/abi/unsupported.rs | 1 - tests/ui/abi/unsupported.x64.stderr | 16 +-- tests/ui/extern/extern-thiscall.rs | 2 - .../ui/feature-gates/feature-gate-thiscall.rs | 38 ------ .../feature-gate-thiscall.stderr | 115 ------------------ 15 files changed, 37 insertions(+), 228 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/abi-thiscall.md delete mode 100644 tests/ui/feature-gates/feature-gate-thiscall.rs delete mode 100644 tests/ui/feature-gates/feature-gate-thiscall.stderr diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 0170d52e82a2e..b1f74643b69c7 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -53,6 +53,8 @@ declare_features! ( /// Allows the sysV64 ABI to be specified on all platforms /// instead of just the platforms on which it is the C ABI. (accepted, abi_sysv64, "1.24.0", Some(36167), None), + /// Allows using the `thiscall` ABI. + (accepted, abi_thiscall, "1.19.0", None, None), /// Allows using ADX intrinsics from `core::arch::{x86, x86_64}`. (accepted, adx_target_feature, "1.61.0", Some(44839), None), /// Allows explicit discriminants on non-unit enum variants. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 2a0dab64af551..ede3570510acb 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -156,8 +156,6 @@ declare_features! ( // ------------------------------------------------------------------------- // no-tracking-issue-start - /// Allows using the `thiscall` ABI. - (active, abi_thiscall, "1.19.0", None, None), /// Allows using the `unadjusted` ABI; perma-unstable. (active, abi_unadjusted, "1.16.0", None, None), /// Allows using the `vectorcall` ABI. diff --git a/compiler/rustc_target/src/spec/abi.rs b/compiler/rustc_target/src/spec/abi.rs index eb3f66ac308dd..dc233121f666a 100644 --- a/compiler/rustc_target/src/spec/abi.rs +++ b/compiler/rustc_target/src/spec/abi.rs @@ -150,7 +150,8 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> { // Stable "Rust" | "C" | "C-unwind" | "cdecl" | "cdecl-unwind" | "stdcall" | "stdcall-unwind" | "fastcall" | "fastcall-unwind" | "aapcs" | "aapcs-unwind" | "win64" | "win64-unwind" - | "sysv64" | "sysv64-unwind" | "system" | "system-unwind" | "efiapi" => Ok(()), + | "sysv64" | "sysv64-unwind" | "system" | "system-unwind" | "efiapi" | "thiscall" + | "thiscall-unwind" => Ok(()), "rust-intrinsic" => Err(AbiDisabled::Unstable { feature: sym::intrinsics, explain: "intrinsics are subject to change", @@ -167,14 +168,6 @@ pub fn is_stable(name: &str) -> Result<(), AbiDisabled> { feature: sym::abi_vectorcall, explain: "vectorcall-unwind ABI is experimental and subject to change", }), - "thiscall" => Err(AbiDisabled::Unstable { - feature: sym::abi_thiscall, - explain: "thiscall is experimental and subject to change", - }), - "thiscall-unwind" => Err(AbiDisabled::Unstable { - feature: sym::abi_thiscall, - explain: "thiscall-unwind ABI is experimental and subject to change", - }), "rust-call" => Err(AbiDisabled::Unstable { feature: sym::unboxed_closures, explain: "rust-call ABI is subject to change", diff --git a/library/panic_unwind/src/lib.rs b/library/panic_unwind/src/lib.rs index 2e5459321a2c1..009014de5c2c4 100644 --- a/library/panic_unwind/src/lib.rs +++ b/library/panic_unwind/src/lib.rs @@ -19,7 +19,7 @@ #![feature(panic_unwind)] #![feature(staged_api)] #![feature(std_internals)] -#![feature(abi_thiscall)] +#![cfg_attr(bootstrap, feature(abi_thiscall))] #![feature(rustc_attrs)] #![panic_runtime] #![feature(panic_runtime)] diff --git a/src/doc/unstable-book/src/language-features/abi-thiscall.md b/src/doc/unstable-book/src/language-features/abi-thiscall.md deleted file mode 100644 index 73bc6eacf42ce..0000000000000 --- a/src/doc/unstable-book/src/language-features/abi-thiscall.md +++ /dev/null @@ -1,12 +0,0 @@ -# `abi_thiscall` - -The tracking issue for this feature is: [#42202] - -[#42202]: https://github.com/rust-lang/rust/issues/42202 - ------------------------- - -The MSVC ABI on x86 Windows uses the `thiscall` calling convention for C++ -instance methods by default; it is identical to the usual (C) calling -convention on x86 Windows except that the first parameter of the method, -the `this` pointer, is passed in the ECX register. diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs index e488300b41caa..49b37024a5e62 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs @@ -928,22 +928,6 @@ $ cat $(find -name '*.s') ret; } ``` -"##, - }, - Lint { - label: "abi_thiscall", - description: r##"# `abi_thiscall` - -The tracking issue for this feature is: [#42202] - -[#42202]: https://github.com/rust-lang/rust/issues/42202 - ------------------------- - -The MSVC ABI on x86 Windows uses the `thiscall` calling convention for C++ -instance methods by default; it is identical to the usual (C) calling -convention on x86 Windows except that the first parameter of the method, -the `this` pointer, is passed in the ECX register. "##, }, Lint { diff --git a/tests/codegen/unwind-abis/thiscall-unwind-abi.rs b/tests/codegen/unwind-abis/thiscall-unwind-abi.rs index 7e81367fc5b78..0a02755a2cd85 100644 --- a/tests/codegen/unwind-abis/thiscall-unwind-abi.rs +++ b/tests/codegen/unwind-abis/thiscall-unwind-abi.rs @@ -1,7 +1,7 @@ // needs-llvm-components: x86 // compile-flags: --target=i686-pc-windows-msvc --crate-type=rlib -Cno-prepopulate-passes #![no_core] -#![feature(no_core, lang_items, c_unwind, abi_thiscall)] +#![feature(no_core, lang_items, c_unwind)] #[lang="sized"] trait Sized { } diff --git a/tests/ui/abi/unsupported.aarch64.stderr b/tests/ui/abi/unsupported.aarch64.stderr index e86a73ea60f65..980457eeab5b7 100644 --- a/tests/ui/abi/unsupported.aarch64.stderr +++ b/tests/ui/abi/unsupported.aarch64.stderr @@ -1,53 +1,53 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:25:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:27:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:30:1 + --> $DIR/unsupported.rs:29:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"aapcs"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:32:1 + --> $DIR/unsupported.rs:31:1 | LL | extern "aapcs" fn aapcs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:36:1 + --> $DIR/unsupported.rs:35:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:38:1 + --> $DIR/unsupported.rs:37:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"x86-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:40:1 + --> $DIR/unsupported.rs:39:1 | LL | extern "x86-interrupt" fn x86() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"thiscall"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:43:1 + --> $DIR/unsupported.rs:42:1 | LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:47:1 + --> $DIR/unsupported.rs:46:1 | LL | extern "stdcall" fn stdcall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/abi/unsupported.arm.stderr b/tests/ui/abi/unsupported.arm.stderr index f7569c8cdd797..450abd948863e 100644 --- a/tests/ui/abi/unsupported.arm.stderr +++ b/tests/ui/abi/unsupported.arm.stderr @@ -1,47 +1,47 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:25:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:27:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:30:1 + --> $DIR/unsupported.rs:29:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:36:1 + --> $DIR/unsupported.rs:35:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:38:1 + --> $DIR/unsupported.rs:37:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"x86-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:40:1 + --> $DIR/unsupported.rs:39:1 | LL | extern "x86-interrupt" fn x86() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"thiscall"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:43:1 + --> $DIR/unsupported.rs:42:1 | LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:47:1 + --> $DIR/unsupported.rs:46:1 | LL | extern "stdcall" fn stdcall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/abi/unsupported.i686.stderr b/tests/ui/abi/unsupported.i686.stderr index 7ca93516db989..0340382a45263 100644 --- a/tests/ui/abi/unsupported.i686.stderr +++ b/tests/ui/abi/unsupported.i686.stderr @@ -1,35 +1,35 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:25:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:27:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:30:1 + --> $DIR/unsupported.rs:29:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"aapcs"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:32:1 + --> $DIR/unsupported.rs:31:1 | LL | extern "aapcs" fn aapcs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:36:1 + --> $DIR/unsupported.rs:35:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:38:1 + --> $DIR/unsupported.rs:37:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/abi/unsupported.rs b/tests/ui/abi/unsupported.rs index 6427a5695c029..bcd95f1ed4cdc 100644 --- a/tests/ui/abi/unsupported.rs +++ b/tests/ui/abi/unsupported.rs @@ -15,7 +15,6 @@ abi_ptx, abi_msp430_interrupt, abi_avr_interrupt, - abi_thiscall, abi_amdgpu_kernel, wasm_abi, abi_x86_interrupt diff --git a/tests/ui/abi/unsupported.x64.stderr b/tests/ui/abi/unsupported.x64.stderr index 26023a4584e40..29eed8505b9b5 100644 --- a/tests/ui/abi/unsupported.x64.stderr +++ b/tests/ui/abi/unsupported.x64.stderr @@ -1,47 +1,47 @@ error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:26:1 + --> $DIR/unsupported.rs:25:1 | LL | extern "ptx-kernel" fn ptx() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"amdgpu-kernel"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:28:1 + --> $DIR/unsupported.rs:27:1 | LL | extern "amdgpu-kernel" fn amdgpu() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"wasm"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:30:1 + --> $DIR/unsupported.rs:29:1 | LL | extern "wasm" fn wasm() {} | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"aapcs"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:32:1 + --> $DIR/unsupported.rs:31:1 | LL | extern "aapcs" fn aapcs() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"msp430-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:36:1 + --> $DIR/unsupported.rs:35:1 | LL | extern "msp430-interrupt" fn msp430() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"avr-interrupt"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:38:1 + --> $DIR/unsupported.rs:37:1 | LL | extern "avr-interrupt" fn avr() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0570]: `"thiscall"` is not a supported ABI for the current target - --> $DIR/unsupported.rs:43:1 + --> $DIR/unsupported.rs:42:1 | LL | extern "thiscall" fn thiscall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: use of calling convention not supported on this target - --> $DIR/unsupported.rs:47:1 + --> $DIR/unsupported.rs:46:1 | LL | extern "stdcall" fn stdcall() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/extern/extern-thiscall.rs b/tests/ui/extern/extern-thiscall.rs index 717df57ec4848..c491c156af597 100644 --- a/tests/ui/extern/extern-thiscall.rs +++ b/tests/ui/extern/extern-thiscall.rs @@ -1,8 +1,6 @@ // run-pass // only-x86 -#![feature(abi_thiscall)] - trait A { extern "thiscall" fn test1(i: i32); } diff --git a/tests/ui/feature-gates/feature-gate-thiscall.rs b/tests/ui/feature-gates/feature-gate-thiscall.rs deleted file mode 100644 index 97a732bcff7f3..0000000000000 --- a/tests/ui/feature-gates/feature-gate-thiscall.rs +++ /dev/null @@ -1,38 +0,0 @@ -// gate-test-abi_thiscall -// needs-llvm-components: x86 -// compile-flags: --target=i686-pc-windows-msvc --crate-type=rlib -#![no_core] -#![feature(no_core, lang_items)] -#[lang="sized"] -trait Sized { } - -// Test that the "thiscall" ABI is feature-gated, and cannot be used when -// the `abi_thiscall` feature gate is not used. - -extern "thiscall-unwind" fn fu() {} //~ ERROR thiscall-unwind ABI is experimental -extern "thiscall" fn f() {} //~ ERROR thiscall is experimental - -trait T { - extern "thiscall" fn m(); //~ ERROR thiscall is experimental - extern "thiscall-unwind" fn mu(); //~ ERROR thiscall-unwind ABI is experimental - - extern "thiscall" fn dm() {} //~ ERROR thiscall is experimental - extern "thiscall-unwind" fn dmu() {} //~ ERROR thiscall-unwind ABI is experimental -} - -struct S; -impl T for S { - extern "thiscall" fn m() {} //~ ERROR thiscall is experimental - extern "thiscall-unwind" fn mu() {} //~ ERROR thiscall-unwind ABI is experimental -} - -impl S { - extern "thiscall" fn im() {} //~ ERROR thiscall is experimental - extern "thiscall-unwind" fn imu() {} //~ ERROR thiscall-unwind ABI is experimental -} - -type TA = extern "thiscall" fn(); //~ ERROR thiscall is experimental -type TAU = extern "thiscall-unwind" fn(); //~ ERROR thiscall-unwind ABI is experimental - -extern "thiscall" {} //~ ERROR thiscall is experimental -extern "thiscall-unwind" {} //~ ERROR thiscall-unwind ABI is experimental diff --git a/tests/ui/feature-gates/feature-gate-thiscall.stderr b/tests/ui/feature-gates/feature-gate-thiscall.stderr deleted file mode 100644 index 346e45952cde8..0000000000000 --- a/tests/ui/feature-gates/feature-gate-thiscall.stderr +++ /dev/null @@ -1,115 +0,0 @@ -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:12:8 - | -LL | extern "thiscall-unwind" fn fu() {} - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:13:8 - | -LL | extern "thiscall" fn f() {} - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:16:12 - | -LL | extern "thiscall" fn m(); - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:17:12 - | -LL | extern "thiscall-unwind" fn mu(); - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:19:12 - | -LL | extern "thiscall" fn dm() {} - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:20:12 - | -LL | extern "thiscall-unwind" fn dmu() {} - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:25:12 - | -LL | extern "thiscall" fn m() {} - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:26:12 - | -LL | extern "thiscall-unwind" fn mu() {} - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:30:12 - | -LL | extern "thiscall" fn im() {} - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:31:12 - | -LL | extern "thiscall-unwind" fn imu() {} - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:34:18 - | -LL | type TA = extern "thiscall" fn(); - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:35:19 - | -LL | type TAU = extern "thiscall-unwind" fn(); - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:37:8 - | -LL | extern "thiscall" {} - | ^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error[E0658]: thiscall-unwind ABI is experimental and subject to change - --> $DIR/feature-gate-thiscall.rs:38:8 - | -LL | extern "thiscall-unwind" {} - | ^^^^^^^^^^^^^^^^^ - | - = help: add `#![feature(abi_thiscall)]` to the crate attributes to enable - -error: aborting due to 14 previous errors - -For more information about this error, try `rustc --explain E0658`. From 4199a3c13a05d05fcc863d506ee2aed74228b8e7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 4 Aug 2023 17:01:05 -0300 Subject: [PATCH 09/13] Convert unsafety using the stable method and reuse mir::Safety --- compiler/rustc_smir/src/rustc_smir/mod.rs | 7 ++----- compiler/rustc_smir/src/stable_mir/ty.rs | 10 ++-------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index e377843cdb436..6eb7e93042560 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -826,7 +826,7 @@ impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> { type T = stable_mir::ty::FnSig; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { use rustc_target::spec::abi; - use stable_mir::ty::{Abi, FnSig, Unsafety}; + use stable_mir::ty::{Abi, FnSig}; FnSig { inputs_and_output: self @@ -835,10 +835,7 @@ impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> { .map(|ty| tables.intern_ty(ty)) .collect(), c_variadic: self.c_variadic, - unsafety: match self.unsafety { - hir::Unsafety::Normal => Unsafety::Normal, - hir::Unsafety::Unsafe => Unsafety::Unsafe, - }, + unsafety: self.unsafety.stable(tables), abi: match self.abi { abi::Abi::Rust => Abi::Rust, abi::Abi::C { unwind } => Abi::C { unwind }, diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index df28fc4eed9ff..be917b2e14013 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -1,4 +1,4 @@ -use super::{mir::Mutability, with, DefId}; +use super::{mir::Mutability, mir::Safety, with, DefId}; use crate::rustc_internal::Opaque; #[derive(Copy, Clone, Debug)] @@ -140,16 +140,10 @@ pub type PolyFnSig = Binder; pub struct FnSig { pub inputs_and_output: Vec, pub c_variadic: bool, - pub unsafety: Unsafety, + pub unsafety: Safety, pub abi: Abi, } -#[derive(Clone, PartialEq, Eq, Debug)] -pub enum Unsafety { - Unsafe, - Normal, -} - #[derive(Clone, PartialEq, Eq, Debug)] pub enum Abi { Rust, From 496faa857c4bc66a73d36e9bb06fbedd99f7fe1c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 4 Aug 2023 17:23:26 -0300 Subject: [PATCH 10/13] Convert trait declaration to SMIR --- compiler/rustc_smir/src/rustc_internal/mod.rs | 4 ++ compiler/rustc_smir/src/rustc_smir/mod.rs | 52 +++++++++++++++++-- compiler/rustc_smir/src/stable_mir/mod.rs | 3 +- compiler/rustc_smir/src/stable_mir/ty.rs | 21 ++++++++ 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index 6a26a4a22ed42..39541c845b394 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -68,6 +68,10 @@ impl<'tcx> Tables<'tcx> { self.def_ids[item.0] } + pub fn trait_def_id(&self, trait_def: &stable_mir::ty::TraitDef) -> DefId { + self.def_ids[trait_def.0] + } + pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem { stable_mir::CrateItem(self.create_def_id(did)) } diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 6eb7e93042560..239b61b433d64 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -41,6 +41,13 @@ impl<'tcx> Context for Tables<'tcx> { fn entry_fn(&mut self) -> Option { Some(self.crate_item(self.tcx.entry_fn(())?.0)) } + + fn trait_decl(&mut self, trait_def: &stable_mir::ty::TraitDef) -> stable_mir::ty::TraitDecl { + let def_id = self.trait_def_id(trait_def); + let trait_def = self.tcx.trait_def(def_id); + trait_def.stable(self) + } + fn mir_body(&mut self, item: &stable_mir::CrateItem) -> stable_mir::mir::Body { let def_id = self.item_def_id(item); let mir = self.tcx.optimized_mir(def_id); @@ -515,7 +522,7 @@ impl<'tcx> Stable<'tcx> for mir::RetagKind { } } -impl<'tcx> Stable<'tcx> for rustc_middle::ty::UserTypeAnnotationIndex { +impl<'tcx> Stable<'tcx> for ty::UserTypeAnnotationIndex { type T = usize; fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { self.as_usize() @@ -1045,7 +1052,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { } } -impl<'tcx> Stable<'tcx> for rustc_middle::ty::ParamTy { +impl<'tcx> Stable<'tcx> for ty::ParamTy { type T = stable_mir::ty::ParamTy; fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { use stable_mir::ty::ParamTy; @@ -1053,7 +1060,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::ParamTy { } } -impl<'tcx> Stable<'tcx> for rustc_middle::ty::BoundTy { +impl<'tcx> Stable<'tcx> for ty::BoundTy { type T = stable_mir::ty::BoundTy; fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { use stable_mir::ty::BoundTy; @@ -1091,3 +1098,42 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation { } } } + +impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind { + type T = stable_mir::ty::TraitSpecializationKind; + fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { + use stable_mir::ty::TraitSpecializationKind; + + match self { + ty::trait_def::TraitSpecializationKind::None => TraitSpecializationKind::None, + ty::trait_def::TraitSpecializationKind::Marker => TraitSpecializationKind::Marker, + ty::trait_def::TraitSpecializationKind::AlwaysApplicable => { + TraitSpecializationKind::AlwaysApplicable + } + } + } +} + +impl<'tcx> Stable<'tcx> for ty::TraitDef { + type T = stable_mir::ty::TraitDecl; + fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { + use stable_mir::ty::TraitDecl; + + TraitDecl { + def_id: rustc_internal::trait_def(self.def_id), + unsafety: self.unsafety.stable(tables), + paren_sugar: self.paren_sugar, + has_auto_impl: self.has_auto_impl, + is_marker: self.is_marker, + is_coinductive: self.is_coinductive, + skip_array_during_method_dispatch: self.skip_array_during_method_dispatch, + specialization_kind: self.specialization_kind.stable(tables), + must_implement_one_of: self + .must_implement_one_of + .as_ref() + .map(|idents| idents.iter().map(|ident| opaque(ident)).collect()), + implement_via_object: self.implement_via_object, + deny_explicit_impl: self.deny_explicit_impl, + } + } +} diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 5e599a77bcda5..0f32f07dcb5da 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -15,7 +15,7 @@ use std::cell::Cell; use crate::rustc_smir::Tables; -use self::ty::{Ty, TyKind}; +use self::ty::{TraitDecl, TraitDef, Ty, TyKind}; pub mod mir; pub mod ty; @@ -84,6 +84,7 @@ pub trait Context { /// Retrieve all items of the local crate that have a MIR associated with them. fn all_local_items(&mut self) -> CrateItems; fn mir_body(&mut self, item: &CrateItem) -> mir::Body; + fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl; /// Get information about the local crate. fn local_crate(&self) -> Crate; /// Retrieve a list of all external crates. diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index be917b2e14013..03089fef01a99 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -11,6 +11,7 @@ impl Ty { } pub(crate) type Const = Opaque; +type Ident = Opaque; pub(crate) type Region = Opaque; type Span = Opaque; @@ -258,3 +259,23 @@ pub struct Allocation { pub align: Align, pub mutability: Mutability, } + +pub enum TraitSpecializationKind { + None, + Marker, + AlwaysApplicable, +} + +pub struct TraitDecl { + pub def_id: TraitDef, + pub unsafety: Safety, + pub paren_sugar: bool, + pub has_auto_impl: bool, + pub is_marker: bool, + pub is_coinductive: bool, + pub skip_array_during_method_dispatch: bool, + pub specialization_kind: TraitSpecializationKind, + pub must_implement_one_of: Option>, + pub implement_via_object: bool, + pub deny_explicit_impl: bool, +} From 0e69a8ad20522467ea1b0c32720bbc7faa1eef13 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 4 Aug 2023 17:44:41 -0300 Subject: [PATCH 11/13] Add all_trait_decls to SMIR --- compiler/rustc_smir/src/rustc_smir/mod.rs | 8 ++++++++ compiler/rustc_smir/src/stable_mir/mod.rs | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 239b61b433d64..d12de92db8a64 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -42,6 +42,14 @@ impl<'tcx> Context for Tables<'tcx> { Some(self.crate_item(self.tcx.entry_fn(())?.0)) } + fn all_trait_decls(&mut self) -> stable_mir::TraitDecls { + self.tcx + .traits(LOCAL_CRATE) + .iter() + .map(|trait_def_id| self.trait_def(*trait_def_id)) + .collect() + } + fn trait_decl(&mut self, trait_def: &stable_mir::ty::TraitDef) -> stable_mir::ty::TraitDecl { let def_id = self.trait_def_id(trait_def); let trait_def = self.tcx.trait_def(def_id); diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 0f32f07dcb5da..d93f25249b9ef 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -32,6 +32,9 @@ pub type DefId = usize; /// A list of crate items. pub type CrateItems = Vec; +/// A list of crate items. +pub type TraitDecls = Vec; + /// Holds information about a crate. #[derive(Clone, PartialEq, Eq, Debug)] pub struct Crate { @@ -84,6 +87,7 @@ pub trait Context { /// Retrieve all items of the local crate that have a MIR associated with them. fn all_local_items(&mut self) -> CrateItems; fn mir_body(&mut self, item: &CrateItem) -> mir::Body; + fn all_trait_decls(&mut self) -> TraitDecls; fn trait_decl(&mut self, trait_def: &TraitDef) -> TraitDecl; /// Get information about the local crate. fn local_crate(&self) -> Crate; From 6e4d7bd90e58ad0e26458b277d1c7e7f4401734d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 5 Aug 2023 22:08:30 -0300 Subject: [PATCH 12/13] Add TraitDef::trait_decl method --- compiler/rustc_smir/src/stable_mir/ty.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 03089fef01a99..c487db5b732a5 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -105,6 +105,12 @@ pub struct AliasDef(pub(crate) DefId); #[derive(Clone, PartialEq, Eq, Debug)] pub struct TraitDef(pub(crate) DefId); +impl TraitDef { + pub fn trait_decl(&self) -> TraitDecl { + with(|cx| cx.trait_decl(self)) + } +} + #[derive(Clone, Debug)] pub struct GenericArgs(pub Vec); From 409d9946cdda6383dbfbabca696ab60f4f7a6dab Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 7 Aug 2023 15:42:24 +0200 Subject: [PATCH 13/13] change test to use `if black_box(false)` --- tests/ui/panic-handler/weak-lang-item-2.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/tests/ui/panic-handler/weak-lang-item-2.rs b/tests/ui/panic-handler/weak-lang-item-2.rs index 6d6e8e04b05c2..2cc5f23b45eb1 100644 --- a/tests/ui/panic-handler/weak-lang-item-2.rs +++ b/tests/ui/panic-handler/weak-lang-item-2.rs @@ -1,23 +1,15 @@ // run-pass // aux-build:weak-lang-items.rs -// ignore-emscripten no threads support // pretty-expanded FIXME #23616 extern crate weak_lang_items as other; fn main() { - let _ = std::thread::spawn(move || { - // The goal of the test is just to make sure other::foo() is called. Since the function - // panics, it's executed in its own thread. That way, the panic is isolated within the - // thread and wont't affect the overall exit code. - // - // That causes a spurious failures in panic=abort targets though: if the program exits - // before the thread is fully initialized the test will pass, but if the thread gets - // executed first the whole program will abort. Adding a 60 seconds sleep will (hopefully!) - // ensure the program always exits before the thread is executed. - std::thread::sleep(std::time::Duration::from_secs(60)); - - other::foo() - }); + // The goal of the test is just to make sure other::foo() is referenced at link time. Since + // the function panics, to prevent it from running we gate it behind an always-false `if` that + // is not going to be optimized away. + if std::hint::black_box(false) { + other::foo(); + } }