Skip to content

Extend minicore with intrinsics and use it to replace #[rustc_intrinsic] in tests #139918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
RalfJung opened this issue Apr 16, 2025 · 2 comments · May be fixed by #140037
Open

Extend minicore with intrinsics and use it to replace #[rustc_intrinsic] in tests #139918

RalfJung opened this issue Apr 16, 2025 · 2 comments · May be fixed by #140037
Labels
A-lang-item Area: Language items A-testsuite Area: The testsuite used to check the correctness of rustc C-cleanup Category: PRs that clean code up or issues documenting cleanup. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

We now have a "minicore" at tests/auxiliary/minicore.rs with some lang items to be shared among no_core tests. However, there's a lot more that could reasonably be added there, and this does not require a lot of experience with how rustc works so it could be a good first issue as well.

To find a candidate test, grep the test suite for #[rustc_intrinsic]. If this test also uses #![no_core], changes are high that this is a good candidate. If the test does not yet use minicore, first port it to minicore by adding //@ add-core-stubs and:

extern crate minicore;
use minicore::*;

See e.g. tests/assembly/simd-intrinsic-mask-reduce.rs for an example.
All of the existing lang items (things with #[lang] attributes) in the test should be removed now; if they don't yet exist in minicore, they should be added there. Then also remove the #[rustc_intrinsic] declarations from the test and add them to minicore if they do not yet exist there.

Cc @jieyouxu

@RalfJung RalfJung added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Apr 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2025
@jieyouxu jieyouxu added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-testsuite Area: The testsuite used to check the correctness of rustc A-lang-item Area: Language items and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 16, 2025
@hbina
Copy link
Contributor

hbina commented Apr 19, 2025

After applying the change to this test https://github.com/rust-lang/rust/blob/master/tests/assembly/rust-abi-arg-attr.rs
It fails,

error[E0425]: cannot find function `three_way_compare` in this scope
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:24:15
   |
24 |         match three_way_compare($a, $b) {
   |               ^^^^^^^^^^^^^^^^^ not found in this scope
...
68 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Ordering`
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:25:13
   |
25 |             Ordering::Less | Ordering::Equal => $b,
   |             ^^^^^^^^ use of undeclared type `Ordering`
...
48 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Ordering`
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:25:30
   |
25 |             Ordering::Less | Ordering::Equal => $b,
   |                              ^^^^^^^^ use of undeclared type `Ordering`
...
48 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Ordering`
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:26:13
   |
26 |             Ordering::Greater => $a,
   |             ^^^^^^^^ use of undeclared type `Ordering`
...
48 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Ordering`
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:25:13
   |
25 |             Ordering::Less | Ordering::Equal => $b,
   |             ^^^^^^^^ use of undeclared type `Ordering`
...
68 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Ordering`
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:25:30
   |
25 |             Ordering::Less | Ordering::Equal => $b,
   |                              ^^^^^^^^ use of undeclared type `Ordering`
...
68 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `Ordering`
  --> /home/hbina085/git/rustlang/tests/assembly/rust-abi-arg-attr.rs:26:13
   |
26 |             Ordering::Greater => $a,
   |             ^^^^^^^^ use of undeclared type `Ordering`
...
68 |     max!(a, b)
   |     ---------- in this macro invocation
   |
   = note: this error originates in the macro `max` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 8 previous errors; 1 warning emitted

It doesn't look like minicore have Ordering or three_way_compare, should i implement those?

diff --git a/tests/assembly/rust-abi-arg-attr.rs b/tests/assembly/rust-abi-arg-attr.rs
index 5b5eeb29f0f..5b241cb84dd 100644
--- a/tests/assembly/rust-abi-arg-attr.rs
+++ b/tests/assembly/rust-abi-arg-attr.rs
@@ -1,3 +1,4 @@
+//@ add-core-stubs
 //@ assembly-output: emit-asm
 //@ revisions: riscv64 riscv64-zbb loongarch64
 //@ compile-flags: -C opt-level=3
@@ -14,46 +15,8 @@
 #![no_std]
 #![no_core]
 
-// FIXME: Migrate these code after PR #130693 is landed.
-// vvvvv core
-
-#[lang = "sized"]
-trait Sized {}
-
-#[lang = "copy"]
-trait Copy {}
-
-impl Copy for i8 {}
-impl Copy for u32 {}
-impl Copy for i32 {}
-
-#[lang = "neg"]
-trait Neg {
-    type Output;
-
-    fn neg(self) -> Self::Output;
-}
-
-impl Neg for i8 {
-    type Output = i8;
-
-    fn neg(self) -> Self::Output {
-        -self
-    }
-}
-
-#[lang = "Ordering"]
-#[repr(i8)]
-enum Ordering {
-    Less = -1,
-    Equal = 0,
-    Greater = 1,
-}
-
-#[rustc_intrinsic]
-fn three_way_compare<T: Copy>(lhs: T, rhs: T) -> Ordering;
-
-// ^^^^^ core
+extern crate minicore;
+use minicore::*;
 
 // Reimplementation of function `{integer}::max`.
 macro_rules! max {

@hbina
Copy link
Contributor

hbina commented Apr 19, 2025

This is the list of files if anyone is interested

hbina085@DESKTOP-PGERPVO ~/g/rustlang (master) [127]> rg --context 10000000 '\#\[rustc_intrinsic\]' /home/hbina085/git/rustlang/tests/**.rs | rg '\#!\[no_core\]'                                    (base) 
/home/hbina085/git/rustlang/tests/ui/traits/const-traits/auxiliary/minicore.rs-#![no_core]
/home/hbina085/git/rustlang/tests/ui/target-feature/feature-hierarchy.rs-#![no_core]
/home/hbina085/git/rustlang/tests/ui/target-feature/no-llvm-leaks.rs-#![no_core]
/home/hbina085/git/rustlang/tests/ui/repr/16-bit-repr-c-enum.rs-#![no_core]
/home/hbina085/git/rustlang/tests/rustdoc/safe-intrinsic.rs-#![no_core]
/home/hbina085/git/rustlang/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs-//! This test case is a `#![no_core]`-version of the MVCE presented in #129301.
/home/hbina085/git/rustlang/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs-#![no_core]
/home/hbina085/git/rustlang/tests/run-make/atomic-lock-free/atomic_lock_free.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-intrinsic-mask-load.rs-#![no_core]
/home/hbina085/git/rustlang/tests/codegen/emscripten-catch-unwind-js-eh.rs-#![no_core]
/home/hbina085/git/rustlang/tests/codegen/avr/avr-func-addrspace.rs-#![no_core]
/home/hbina085/git/rustlang/tests/auxiliary/minicore.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-intrinsic-mask-reduce.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-intrinsic-scatter.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-bitmask.rs-#![no_core]
/home/hbina085/git/rustlang/tests/codegen/intrinsics/nontemporal.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-intrinsic-select.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-intrinsic-gather.rs-#![no_core]
/home/hbina085/git/rustlang/tests/assembly/simd-intrinsic-mask-store.rs-#![no_core]
/home/hbina085/git/rustlang/tests/codegen/emscripten-catch-unwind-wasm-eh.rs-#![no_core]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lang-item Area: Language items A-testsuite Area: The testsuite used to check the correctness of rustc C-cleanup Category: PRs that clean code up or issues documenting cleanup. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants