Skip to content
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

Remove support for extern "rust-intrinsic" blocks #132735

Open
4 of 5 tasks
RalfJung opened this issue Nov 7, 2024 · 42 comments
Open
4 of 5 tasks

Remove support for extern "rust-intrinsic" blocks #132735

RalfJung opened this issue Nov 7, 2024 · 42 comments
Assignees
Labels
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Nov 7, 2024

We currently have two ways to declare symbols that are invoked as intrinsics. The old way:

extern "rust-intrinsic" {
    fn unreachable() -> !;
}

The new way:

#[rustc_intrinsic]
unsafe fn unreachable() -> !;

The goal of this issue is to remove support for the old style, and consistently use the new style.

@RalfJung RalfJung added 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. labels Nov 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 7, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 7, 2024
@compiler-errors
Copy link
Member

I do wonder if there's some way we could have body-less free function items when users write #[rustc_intrinsic_must_be_overridden]. Having all these dummy bodies like loop {} and unreachable {} seem kinda meh.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 7, 2024 via email

@compiler-errors
Copy link
Member

We actually reject them after expansion but before ast lowering.

We could perhaps intercept these bodyless functions during ast lowering and fill them with a dummy body like loop {} or something that diverges rather than having it be manually written on each function.

@compiler-errors
Copy link
Member

Obviously only intercepting them if they're marked with rustc_intrinsic_must_be_overridden; if it's a regular function we'd issue the regular error for a bodyless free function, and if it's rustc_intrinsic we could tell the user that it needs to be marked with rustc_intrinsic_must_be_overridden.

@RalfJung
Copy link
Member Author

RalfJung commented Nov 7, 2024

That's way beyond my knowledge of those parts of the compiler. ;) So sure, sounds great. :D

Cc @petrochenkov

Obviously only intercepting them if they're marked with rustc_intrinsic_must_be_overridden

I was actually going to suggest that a #[rustc_intrinsic] not having a body should replace the rustc_intrinsic_must_be_overridden attribute.

@compiler-errors
Copy link
Member

Oh, that works too.

@workingjubilee
Copy link
Member

hmm do we have the notion of a builtin attribute macro...?

@compiler-errors
Copy link
Member

@workingjubilee: Yes

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 8, 2024
@BLANKatGITHUB
Copy link
Contributor

@rustbot claim

@BLANKatGITHUB
Copy link
Contributor

BLANKatGITHUB commented Nov 10, 2024

Ok so basically I tried porting the first block of extern "rust-intrinsic" in library/core/src/intrinsics/mod.rs
and it gave the errors

`error[E0308]: intrinsic has wrong type
core/src/intrinsics/mod.rs:1277:26

pub fn prefetch_read_data<T>(data: *const T, locality: i32) {
                                                ^^^ expected unsafe fn, found safe fn
 
 note: expected signature `unsafe fn(_, _)`
            found signature `fn(_, _)` 

and

``
error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic prefetch_write_data
core/src/intrinsics/mod.rs:1292:1

pub fn prefetch_write_data(data: *const T, locality: i32) {

``

@RalfJung
Copy link
Member Author

Yes, the intrinsics need to be marked as unsafe fn. Sorry I forgot that when writing up the issue.

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Nov 14, 2024
Change intrinsic declarations to new style

Pr is for issue rust-lang#132735
This changes the first `extern "rust-intrinsic"` block to the new style.
r? `@RalfJung`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 14, 2024
Rollup merge of rust-lang#132907 - BLANKatGITHUB:intrinsic, r=saethlin

Change intrinsic declarations to new style

Pr is for issue rust-lang#132735
This changes the first `extern "rust-intrinsic"` block to the new style.
r? `@RalfJung`
jieyouxu added a commit to jieyouxu/rust that referenced this issue Nov 23, 2024
changes old intrinsic declaration to new declaration

This pr is for issue rust-lang#132735

It changes old `extern "intrinsic"` code block with new declaration.

There are other blocks that use old declaration but as the changes needed in single block is quite large I do them in parts
jieyouxu added a commit to jieyouxu/rust that referenced this issue Nov 30, 2024
changes old intrinsic declaration to new declaration

This pr is for issue rust-lang#132735

It changes old `extern "intrinsic"` code block with new declaration.

There are other blocks that use old declaration but as the changes needed in single block is quite large I do them in parts
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 30, 2024
Rollup merge of rust-lang#133106 - BLANKatGITHUB:intrinsic, r=RalfJung

changes old intrinsic declaration to new declaration

This pr is for issue rust-lang#132735

It changes old `extern "intrinsic"` code block with new declaration.

There are other blocks that use old declaration but as the changes needed in single block is quite large I do them in parts
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 8, 2024
Adds new intrinsic declaration

This pr is for rust-lang#132735 removes removes `extern "intrinsic"`

I think its the last block of this file and was kind of asking for advice how to handle other files as mentioned in the issue .
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 9, 2024
Rollup merge of rust-lang#134013 - BLANKatGITHUB:intrinsic, r=saethlin

Adds new intrinsic declaration

This pr is for rust-lang#132735 removes removes `extern "intrinsic"`

I think its the last block of this file and was kind of asking for advice how to handle other files as mentioned in the issue .
@RalfJung
Copy link
Member Author

RalfJung commented Jan 2, 2025

I do wonder if there's some way we could have body-less free function items when users write #[rustc_intrinsic_must_be_overridden]. Having all these dummy bodies like loop {} and unreachable {} seem kinda meh.

#135031 implements that.

github-actions bot pushed a commit to tautschnig/verify-rust-std that referenced this issue Mar 11, 2025
ports last few library files to new intrinsic style

This pr ports the last 2 library files to new intrinsic style this pr is part of issue rust-lang#132735
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 20, 2025
ports the compiler test cases to new rust_intrinsic format

pr is part of rust-lang#132735
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2025
ports the compiler test cases to new rust_intrinsic format

pr is part of rust-lang#132735
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 21, 2025
ports the compiler test cases to new rust_intrinsic format

pr is part of rust-lang#132735
Kobzol added a commit to Kobzol/rust that referenced this issue Mar 21, 2025
ports the compiler test cases to new rust_intrinsic format

pr is part of rust-lang#132735
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 21, 2025
Rollup merge of rust-lang#138364 - BLANKatGITHUB:compiler, r=RalfJung

ports the compiler test cases to new rust_intrinsic format

pr is part of rust-lang#132735
@RalfJung
Copy link
Member Author

RalfJung commented Apr 7, 2025

@Skgland you opened #139455. Given that the issue here still has someone assigned, please always ask the assignee (@BLANKatGITHUB) in the issue first before assuming they have stopped working on this!

Zalathar added a commit to Zalathar/rust that referenced this issue Apr 7, 2025
… r=oli-obk

 Remove support for `extern "rust-intrinsic"` blocks

Part of rust-lang#132735

Looked manageable and there didn't appear to have been progress in the last two weeks,
so decided to give it a try.
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 7, 2025
… r=oli-obk

 Remove support for `extern "rust-intrinsic"` blocks

Part of rust-lang#132735

Looked manageable and there didn't appear to have been progress in the last two weeks,
so decided to give it a try.
@BLANKatGITHUB
Copy link
Contributor

Well , I was busy with college, that's quite a big pr though, does this pr finally close the issue? Or there are some more files left

@RalfJung
Copy link
Member Author

RalfJung commented Apr 7, 2025

No worries. I hope you're fine with someone else taking over. :)

That PR entirely removes "rust-intrinsics" from the compiler so it has to fix all the remaining files. The only thing that's left is the last (5th) checkbox in the issue description.

@BLANKatGITHUB
Copy link
Contributor

No problem

rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 7, 2025
Rollup merge of rust-lang#139455 - Skgland:remove_rust-intrinsic_ABI, r=oli-obk

 Remove support for `extern "rust-intrinsic"` blocks

Part of rust-lang#132735

Looked manageable and there didn't appear to have been progress in the last two weeks,
so decided to give it a try.
@Skgland
Copy link
Contributor

Skgland commented Apr 7, 2025

Besides looking for further cleanup potential, the following things are still to be done

And I noticed is that rust-analyser still checks for #[rustc_intrinsic_must_be_overridden] though this has been removed from the compiler as its been superseded by intrinsics functions without bodies.
So the check e.g. at

|| attrs.by_key(&sym::rustc_intrinsic_must_be_overridden).exists(),
and symbol defined at
rustc_intrinsic_must_be_overridden,
can also probably be removed.

@RalfJung
Copy link
Member Author

RalfJung commented Apr 7, 2025

RA has its own repo so this might be worth an issue there. They usually wait a bit before removing language features since they want to support using a current RA on older versions of Rust, which still use the old features (and even on stable Rust, those features are present in the standard library). So RA is out-of-scope for this issue.

Regarding the nomicon, could you make a PR?

I can reword that comment in intrinsics/mod.rs. EDIT: done as part of #139490.

@Skgland
Copy link
Contributor

Skgland commented Apr 7, 2025

They usually wait a bit before removing language features since they want to support using a current RA on older versions of Rust, which still use the old features (and even on stable Rust, those features are present in the standard library).

Uh-oh, then 51b51b5 probably went too far as well and should maybe be reverted until rust-analyzer is ready to remove support for the "rust-intrinsic" ABI.

@Skgland
Copy link
Contributor

Skgland commented Apr 7, 2025

Regarding the nomicon, could you make a PR?

Opened rust-lang/nomicon#485

Zalathar added a commit to Zalathar/rust that referenced this issue Apr 8, 2025
…kril

Revert r-a changes of rust-lang#139455

I discovered rust-lang#132735 (comment) that I might have done too much in rust-lang#132735 by also removing support in r-a.
So this reverts the commit with the changes to r-a.

r? RalfJung
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 8, 2025
…kril

Revert r-a changes of rust-lang#139455

I discovered rust-lang#132735 (comment) that I might have done too much in rust-lang#132735 by also removing support in r-a.
So this reverts the commit with the changes to r-a.

r? RalfJung
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 9, 2025
Rollup merge of rust-lang#139496 - Skgland:139455-went-too-far, r=Veykril

Revert r-a changes of rust-lang#139455

I discovered rust-lang#132735 (comment) that I might have done too much in rust-lang#132735 by also removing support in r-a.
So this reverts the commit with the changes to r-a.

r? RalfJung
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 10, 2025
…=RalfJung

Remove some dead or leftover code related to rustc-intrinsic abi removal

r? `@RalfJung`

PR that removed the ABI: rust-lang#139455

tracking issue: rust-lang#132735
Zalathar added a commit to Zalathar/rust that referenced this issue Apr 10, 2025
…=RalfJung

Remove some dead or leftover code related to rustc-intrinsic abi removal

r? ``@RalfJung``

PR that removed the ABI: rust-lang#139455

tracking issue: rust-lang#132735
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 10, 2025
…=RalfJung

Remove some dead or leftover code related to rustc-intrinsic abi removal

r? ```@RalfJung```

PR that removed the ABI: rust-lang#139455

tracking issue: rust-lang#132735
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 10, 2025
Rollup merge of rust-lang#139530 - oli-obk:rustc-intrinsic-cleanup, r=RalfJung

Remove some dead or leftover code related to rustc-intrinsic abi removal

r? ```@RalfJung```

PR that removed the ABI: rust-lang#139455

tracking issue: rust-lang#132735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants