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

codegen_llvm/llvm_type: avoid matching on the Rust type #115240

Merged
merged 4 commits into from
Aug 28, 2023

Conversation

RalfJung
Copy link
Member

This match is highly suspicious. Looking at scalar_llvm_type_at I think it makes no difference. But if it were to make a difference that would be a huge problem, since it doesn't look through repr(transparent)!

Cc @eddyb @bjorn3

@rustbot
Copy link
Collaborator

rustbot commented Aug 26, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@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. labels Aug 26, 2023
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This looks okay to me but I want a second pair of eyes on it.

@davidtwco
Copy link
Member

r? @bjorn3

@rustbot rustbot assigned bjorn3 and unassigned davidtwco Aug 28, 2023
@RalfJung
Copy link
Member Author

RalfJung commented Aug 28, 2023

I just found this which seems equally suspicious:

// HACK(eddyb) special-case fat pointers until LLVM removes
// pointee types, to avoid bitcasting every `OperandRef::deref`.
match *self.ty.kind() {

Moreover, pointee types are removed, so the entire hack is probably unnecessary?

@rustbot
Copy link
Collaborator

rustbot commented Aug 28, 2023

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@RalfJung
Copy link
Member Author

I've removed that other match as well now, and since the GCC backend copy-pasted that code I also updated it there.

Cranelift is extremely reliant on Rust types in its backend type computation functions, which is concerning... maybe it's just somehow not relevant for ABI there?

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member

bjorn3 commented Aug 28, 2023

cg_clif should not be dependent on rust types for calling convention handling. It should only use rust types for handling locals.

it was already unused before, but due to the recursion the compiler did not realize
@RalfJung
Copy link
Member Author

Okay, I was probably looking at the wrong code then.

@bjorn3
Copy link
Member

bjorn3 commented Aug 28, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Aug 28, 2023

📌 Commit 9b9cb51 has been approved by bjorn3

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 Aug 28, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 28, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#115164 (MIR validation: reject in-place argument/return for packed fields)
 - rust-lang#115240 (codegen_llvm/llvm_type: avoid matching on the Rust type)
 - rust-lang#115294 (More precisely detect cycle errors from type_of on opaque)
 - rust-lang#115310 (Document panic behavior across editions, and improve xrefs)
 - rust-lang#115311 (Revert "Suggest using `Arc` on `!Send`/`!Sync` types")
 - rust-lang#115317 (Devacationize oli-obk)
 - rust-lang#115319 (don't use SnapshotVec in Graph implementation, as it looks unused; use Vec instead)
 - rust-lang#115322 (Tweak output of `to_pretty_impl_header` involving only anon lifetimes)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a5b7504 into rust-lang:master Aug 28, 2023
11 checks passed
@bors
Copy link
Contributor

bors commented Aug 28, 2023

⌛ Testing commit 9b9cb51 with merge 4e78abb...

@rustbot rustbot added this to the 1.74.0 milestone Aug 28, 2023
@RalfJung RalfJung deleted the llvm-no-type branch August 29, 2023 06:15
Comment on lines +218 to +220
// This must produce the same result for `repr(transparent)` wrappers as for the inner type!
// In other words, this should generally not look at the type at all, but only at the
// layout.
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for seeing this so late, but, if not made clear so far by anyone else:
the special cases you removed are simultaneously sound and obsolete.

They're sound because they only affect pointer types' pointee types (which doesn't impact ABI on it own), and they're obsolete thanks to LLVM opaque pointers (making the removal welcome!).

You can kinda tell they were working fine because e.g. Option<&String> would look like i64*, whereas the inner &String would actually be {i8*, i64, i64}* - worst case, it would pessimize some badly written LLVM optimizations, but all of those concerns should be gone now.

In fact, some of this code can very likely be simplified!

scalar_pair_element_llvm_type only exists in the form it does because it needed to special-case wide pointers, but now each component of the scalar pair can be independently converted to LLVM.

It might even make sense to remove caches like scalar_lltypes and instead have something much simpler keyed by Primitive - the existing scalar_llvm_type_at might be good enough, even, and I would argue the cache only existed because of the pointer cases, and can now be fully removed.

Copy link
Member Author

@RalfJung RalfJung Oct 6, 2023

Choose a reason for hiding this comment

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

the special cases you removed are simultaneously sound and obsolete.

Yes that was my conclusion, too. That still makes this PR a good cleanup, no? :)

But looking at these special cases led me to ones that aren't sound (see the recent ABI issues I opened), so the cleanup of obsolete-but-sound type matching was still worth it.

I'm sure there's further simplification possible.

antoyo pushed a commit to antoyo/rust that referenced this pull request Oct 9, 2023
codegen_llvm/llvm_type: avoid matching on the Rust type

This `match` is highly suspicious. Looking at `scalar_llvm_type_at` I think it makes no difference. But if it were to make a difference that would be a huge problem, since it doesn't look through `repr(transparent)`!

Cc `@eddyb` `@bjorn3`
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants