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

Dellvmize some intrinsics (use u32 instead of Self in some integer intrinsics) #124003

Merged
merged 7 commits into from
Apr 23, 2024

Conversation

WaffleLapkin
Copy link
Member

This implements rust-lang/compiler-team#693 minus what was implemented in #123226.

Note: I decided to not change shl/... builder methods, as it just doesn't seem worth it.

r? @scottmcm

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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 Apr 16, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2024

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@@ -487,7 +492,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
sym::bitreverse => (bits << extra).reverse_bits(),
_ => bug!("not a numeric intrinsic: {}", name),
};
Ok(Scalar::from_uint(bits_out, layout.size))
Ok(Scalar::from_uint(bits_out, ret_layout.size))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it can ICE when bswap/bitrevere is called with a too small ret_layout.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that happen though? The intrinsics are defined like pub fn bitreverse<T: Copy>(x: T) -> T;, so the ret_layout must be the same?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an extremely non-local invariant. This function here should make sense on its own without worrying about what happens in the standard library.

Copy link
Member

@RalfJung RalfJung Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an assertion that for bswap/bitreverse, the two layouts are the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is true in general with intrinsics, we implicitly depend on their signature in a lot of ways. Either way, I added an assertion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the interpreter and Miri we always have local assertions for these things.

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Looks like some CI issues?)

compiler/rustc_codegen_llvm/src/intrinsic.rs Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 16, 2024
@WaffleLapkin
Copy link
Member Author

#[cfg(not(bootstrap))] makes tidy think unsafe is not documented. fun.

@WaffleLapkin

This comment was marked as resolved.

@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2024

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2024

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 20, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin
Copy link
Member Author

@rustbot ready

I was not able to fix the gcc backend (could not run tests locally and using CI seemed like too much trouble), so I just commented the tests out ^^'

Other backends should be working, unless I missed something.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 20, 2024
@antoyo
Copy link
Contributor

antoyo commented Apr 20, 2024

Is the error you got from the GCC codegen the one we see in the message above?
This one:

##[error]   --> example/example.rs:157:5
    |
    |
156 | unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
    |                                       --- expected `u16` because of return type
157 |     intrinsics::ctlz_nonzero(a)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32`
    |
help: you can convert a `u32` to a `u16` and panic if the converted value doesn't fit
    |
157 |     intrinsics::ctlz_nonzero(a).try_into().unwrap()

?
Because that's a frontend error, so that seems weird to me especially since you changed the signature here.

@WaffleLapkin
Copy link
Member Author

@antoyo this is the error I got, but if I'd fix it, I would just get a different error, because gcc (now) casts to the wrong type

@antoyo
Copy link
Contributor

antoyo commented Apr 20, 2024

Did you try to change arg_type to self.u32_type in this code?

@WaffleLapkin
Copy link
Member Author

I did not, precisely because I wasn't able to test things

@antoyo
Copy link
Contributor

antoyo commented Apr 21, 2024

Ok, you might want to join this discussion so we can figure out how to make this better.

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here all look good to me.

@RalfJung , did you want to look further at the CTFE parts?

I'm a bit uncertain about the cg_gcc state here. The amount being disabled is small so seems fine enough to do and resolve later, but I also don't feel confident in saying what the expectations are for it.

@RalfJung
Copy link
Member

The interpreter changes LGTM.

@antoyo
Copy link
Contributor

antoyo commented Apr 23, 2024

I'm a bit uncertain about the cg_gcc state here. The amount being disabled is small so seems fine enough to do and resolve later, but I also don't feel confident in saying what the expectations are for it.

While we do prefer to avoid disabling code like was done here (and we're always happy to help implement the stuff in the PR), we're OK with people not implementing the stuff and doing it on our side.

I guess we could think at some point of allowing us to fix the cg_gcc stuff in PR made by other people, but we should also think about that carefully to not block people.

All of that to say, I'm OK with the cg_gcc changes here.

@workingjubilee
Copy link
Member

hokay!

@bors r=scottmcm,RalfJung,antoyo

@bors
Copy link
Contributor

bors commented Apr 23, 2024

📌 Commit 468179c has been approved by scottmcm,RalfJung,antoyo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 23, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 23, 2024
…tmcm,RalfJung,antoyo

Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics)

This implements rust-lang/compiler-team#693 minus what was implemented in rust-lang#123226.

Note: I decided to _not_ change `shl`/... builder methods, as it just doesn't seem worth it.

r? `@scottmcm`
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2024
…iaskrgr

Rollup of 3 pull requests

Successful merges:

 - rust-lang#124003 (Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics))
 - rust-lang#124169 (Don't fatal when calling `expect_one_of` when recovering arg in `parse_seq`)
 - rust-lang#124286 (Subtree sync for rustc_codegen_cranelift)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 918304b into rust-lang:master Apr 23, 2024
12 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 23, 2024
Rollup merge of rust-lang#124003 - WaffleLapkin:dellvmization, r=scottmcm,RalfJung,antoyo

Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics)

This implements rust-lang/compiler-team#693 minus what was implemented in rust-lang#123226.

Note: I decided to _not_ change `shl`/... builder methods, as it just doesn't seem worth it.

r? ``@scottmcm``
@WaffleLapkin WaffleLapkin deleted the dellvmization branch April 23, 2024 21:37
@WaffleLapkin
Copy link
Member Author

Thanks to everyone involved <3

bjorn3 pushed a commit to bjorn3/rust that referenced this pull request May 13, 2024
…tmcm,RalfJung,antoyo

Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics)

This implements rust-lang/compiler-team#693 minus what was implemented in rust-lang#123226.

Note: I decided to _not_ change `shl`/... builder methods, as it just doesn't seem worth it.

r? ``@scottmcm``
tautschnig pushed a commit to model-checking/kani that referenced this pull request May 15, 2024
GuillaumeGomez pushed a commit to GuillaumeGomez/rust that referenced this pull request Jul 10, 2024
…tmcm,RalfJung,antoyo

Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics)

This implements rust-lang/compiler-team#693 minus what was implemented in rust-lang#123226.

Note: I decided to _not_ change `shl`/... builder methods, as it just doesn't seem worth it.

r? ``@scottmcm``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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

Successfully merging this pull request may close these issues.

8 participants