-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add an attribute to check the number of lanes in a SIMD vector after monomorphization #146667
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: master
Are you sure you want to change the base?
Add an attribute to check the number of lanes in a SIMD vector after monomorphization #146667
Conversation
This comment has been minimized.
This comment has been minimized.
Hmm, that's not good. I'm probably using the visitor wrong. I'll investigate tomorrow |
I think I understand the goal here, but I'm not sure what exactly one has to do to actually find all the types that could be relevant. Iterating the signature and the locals feels ad-hoc, and also redundant since all arguments and the return value also appear as MIR locals. And then you try to recursively iterate the type and its fields... no idea if that makes sense, sorry. I also don't have the time right now to dig into this. r? types Also Cc @BoxyUwU @lcnr @compiler-errors since this is essentially adding a compiler hack to work around const generics being painful, IIUC. (Would be good to reference an issue with context and prior discussion describing why the |
for background on dropping the lane count traits: rust-lang/portable-simd#364 (comment) |
https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/mono.20check.20that.20walks.20all.20types/near/539909904 this is the related zulip thread? Going to ignore the fact that I personally feel somewhat iffy about this change and feel in favor of a I think visiting all locals (and their fields) is very... questionable 😅 You'vbe mentioned putting this check into We already have similar errors for arrays, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should indeed get a new-style attribute parser
Adding the I could do this in layout, and perhaps it's more precise there. I think the compromise is that layout errors don't track a source span, but maybe that can be added. |
I like the analogy with "this type is too big for your target". |
If this is a backend limitation, why is the maximum lane count configured by the library in the type? The max size is a hard-coded constant in the compiler, after all. |
This is probably the most relevant zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/Post-mono.20errors.20for.20better.20UX A little bit of info in this issue as well, though mostly outdated as we now support non-power-of-two lengths: rust-lang/portable-simd#364 If I were able to somehow embed a const assert rather than a post-mono error I would be much happier with that, but AFAIK that's still not possible |
Unfortunately I tried that in the past (#80652) and failed crater because some crates are using |
It's a nightly-only feature so I am not too bothered by that. EDIT: Looking at that PR, it seems the failure was mostly about non-power-of-2 vectors, not too big vectors?
That seems to be an argument in favor of having this in the compiler. (If we want to accept such non-portability; the max size currently only depends on the target pointer width.) |
For std::simd, we have settled on 64 elements as a reasonable maximum size. With larger vectors, you can see weird unrolling and writing vectors to memory particularly on architectures with smaller vectors. I wouldn't want to enforce 64 elements for the |
only for when we need separate trait impls for each size, when we don't need the trait impls I think 16384 is better since that is actually the hardware size on some RISC-V CPUs. |
Some changes occurred in compiler/rustc_passes/src/check_attr.rs Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_hir/src/attrs |
b4a5f3b
to
a5b0838
Compare
Add an attribute to check the number of lanes in a SIMD vector after monomorphization Allows std::simd to drop the `LaneCount<N>: SupportedLaneCount` trait and maintain good error messages. r? `@RalfJung` cc `@workingjubilee` `@programmerjake`
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
I'm not really sure what's configured differently with that job that effects how the errors are emitted |
As the name indicates, it's probably doing debug builds instead of release builds. That can affect which types are encountered during monomorphization. |
I tried What's odd is that it's the same errors, they're just being reported differently (without a span). This is what layout errors currently do on stable. Maybe there's an error reporting branch I didn't account for. |
We have existing tests that check the size-too-big error, so they do anything (like special compiler flags or so) that you could be copying? |
…monomorphization Unify zero-length and oversized SIMD errors
a5b0838
to
f5c6c95
Compare
This comment was marked as resolved.
This comment was marked as resolved.
11ff067
to
60548ff
Compare
I extended #145967 by including spans in the layout errors for all ADTs. This fixes the issue locally for me. |
@bors try jobs=x86_64-gnu-debug |
Add an attribute to check the number of lanes in a SIMD vector after monomorphization try-job: x86_64-gnu-debug
This comment has been minimized.
This comment has been minimized.
@bors r=lcnr,RalfJung |
Allows std::simd to drop the
LaneCount<N>: SupportedLaneCount
trait and maintain good error messages.Also, extends #145967 by including spans in layout errors for all ADTs.
r? @RalfJung
cc @workingjubilee @programmerjake