-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
compiler: remove AIX's uses_power_alignment lint
#142310
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
base: main
Are you sure you want to change the base?
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
|
These commits modify compiler targets. |
This comment has been minimized.
This comment has been minimized.
78009f5 to
6abc782
Compare
This comment has been minimized.
This comment has been minimized.
I assume you are referring to llvm/llvm-project#133599 here? Always good to leave some cross-references. :) Please also add comments in the code referencing that (both in the aix target triple, and the special exception for the data layout consistency check). Right now, just looking at the code after applying this diff, one would have a very hard time figuring out what happens. |
|
aye aye capitan |
|
As discussed on IRLO, as-is this patch would make some types more correct and others less correct. Hard to say whether that's overall a net positive... |
|
It does fix every type that doesn't have |
|
Are there really more types with f64 in some later field vs the first field?
Also, for the later field case we at least had a lint...
|
|
Not all types which start with |
I think so, when we're considering that it includes all nested aggregates? Yes, the problem after this patch is now "possible-to-fix-in-bindgen"-tier. |
Ah, that's a good point. |
|
Hi! Thanks for this patch. I wanted to test this on an AIX machine, but if I try to build it, I get an assertion on the LLVM side: Since the datalayout string in LLVM does not match the datalayout string in rustc. If I make the strings match to unblock the build, I see the internal compiler bug message that was added in the patch: In any case, I tried to work around these issues to test the patch a bit. There are a few concerns from our end:
Ideally, we would only want these changes for FYI @daltenty |
That's a Rust layout struct. Why should it have AIX-specific layout? We use the same (undocumented, can-change-any-day) algorithm for repr(Rust) on all targets and we really want to keep it that way for the sake of everyone's sanity. |
Ah, sorry. I'll just remove the |
|
@amy-kwan New patch to try out, should be less comical to test. |
While I may make further changes to the layout algorithm that may overalign in some cases for the performance reasons you note, the fundamental detail is that it doesn't matter: once any f64 may be underaligned (read: 4, the ABI alignment on AIX), our codegen will notice they all are at that alignment and our reads and writes of that type will be generated with such an alignment annotation for LLVM. LLVM will only be able to upgrade the alignment as an optimization. That is not an optimization I believe we should ourselves perform on our LLVMIR. This is because it would be extremely fragile, as This is also partly because any reasoning that we overaligned things depends on specifics of the layout algorithm that we are allowed to undermine. It would be globally embedding a local assumption from another part of the code. So for this: pub struct Floats {
a: f64,
b: u32,
c: f64,
}If the true alignment of #[repr(linear)]
pub struct Floats {
a: f64,
c: f64,
b: u32,
}nor can you rely on us choosing this layout: #[repr(linear)]
pub struct Floats {
b: u32,
a: f64,
c: f64,
}We are allowed to pick either actual effective layout. You do not have a "should" you can rely on. And in general neither should we: if we make our code break with our own rules, then we make it harder to update. |
|
Also you could probably have built the previous commit by disabling assertions for LLVM but I can understand not wanting to, for, you know, testing-the-patch purposes. :^) |
This comment has been minimized.
This comment has been minimized.
|
@nikic as usual is off being a gentleman and a scholar and has opened llvm/llvm-project#144673 |
|
☔ The latest upstream changes (presumably #144044) made this pull request unmergeable. Please resolve the merge conflicts. |
can the review of this patch proceed in parallel or do you prefer the LLVM to be first merged? |
|
@amy-kwan @mandlebug @daltenty Hello. The current build of the compiler ICEs when building the standard library due to a missing case regarding unions, see #147348. This patch would remove the ICE if accepted. I suppose I also have to rebase it, but I will also have to rebase it over any fixes of the "power alignment" lint. |
Hi @workingjubilee, I'd like to first apologize in the delay in getting back to this patch. We are aware of the compiler ICEs, and thanks for bringing attention to them. We have recently been trying to sort out the data layout related issues on our side and have been reviewing and testing the relevant patches again, so we will be trying our best to continue to make progress on this. I'm able to get this patch through a stage 1 build (thank you!), although a question I thought of when testing this patch is, when llvm/llvm-project#144673 lands, will any more changes be necessary? For example, do we still need the changes within Somewhat separate to this, but I wasn't able to get through a complete stage 2 build due to the assert in https://github.com/BurntSushi/byteorder/blob/1.5.0/src/lib.rs#L1271, which I think makes sense. However, this crate hasn't been updated in awhile, which could be concerning if we wanted to make updates to it to accommodate the AIX data layout changes. |
That assertion seems to simply not be true on AIX -- there are BurntSushi is still around and maintaining other code, so it may be worth reporting an issue nevertheless. Maybe that function should be simply cfg'd out on AIX. |
We do our best to keep our data layout string in sync with LLVM's, so yes some update will likely be required. It may be more minimal, however. |
|
I have opened BurntSushi/byteorder#221 |
|
@amy-kwan The reason I would not worry too much about dependencies not building. They can be solved, one way or another. I do appreciate you pointing that out, though. |
|
I'd like to apologize for the long delay as I have not been able to continue looking into the power alignment issues near the end of last year. I'm starting to pick this up again and so far, I've rebased this patch locally and am trying to locate the |
We have all been there. We actually already landed #149880 it seems, which contains the datalayout change. I will cut this PR down to removing the lint, and will submit a change to byteorder. I am happy to submit a followup to rust-lang/rust that does more in terms of addressing the remaining mismatch with
|
|
I think it has to be 1 and/or 2. We shouldn't change what repr(C) does without t-lang involvement and that discussion is/was happening at rust-lang/rfcs#3845 and possibly in other RFCs. |
|
Technically, we have already done so, in the sense that we already fixed the data layout for this target, thus now |
9bc6c32 to
0c0206d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
430a9ba to
85e8056
Compare
The "power alignment" lint was based on a false premise: rustc assumed LLVM's built-in AIX datalayout was correct for given types. Unfortunately, C compilers, like clang, implemented a different layout. As LLVM's wrong layout was taken as gospel, a fix seemed impossible. This resulted in the creation of the "power alignment" lint as a compromise, as it did not require invasively changing layout algorithms. Eventually in llvm-project's @b7c0452a9a3d895b14ec7c5735e4e4ddc311edb3 LLVM's AIX layout was fixed. Now rustc will have mostly-correct layouts on AIX since rust's dea8b8b We may need a new lint that captures the remaining C layout problems for AIX and other targets as well, but that is a larger conversation. For now, remove the incorrect lint.
85e8056 to
6f5f162
Compare
|
We did not change the spec for repr(C), which is in terms of the size and alignment of its fields. We changed the input to the algorithm, but that's a different kind of change.
That change still should come with release notes though.
|
uses_power_alignment lint
In #149880 we changed the data layout for AIX to use the corrected, reduced alignment for
f64(AKA "double"). Because theuses_power_alignmentlint was based on the premise that our previous alignment was correct, which is wrong, we should now simply remove it. This greatly simplifies the surrounding code handling types that are "improper" for FFI.Some
repr(C)structs are still not given the proper layout for FFI compatibility. This will involve a future migration plan involving either a new lint or language changes. The current lint remains incorrect and is not very useful to rewrite into possible revised lints that address this need.