-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Rust doesn't use niche in reference (or pointer) to slice #132235
Comments
Duplicate of #119507 |
In any case, I don't really think having a zillion tiny issues regarding the layout code, which is a big ball of mud, is very helpful. It would be better to collect the various possible optimizations and reason about them in a central manner, rather than trying to make tiny adjustments to spot-fix the code. |
Honestly, I'm not sure why your PR #116542 is seemingly both trying to add metadata and alter the layout of slices. |
The fundamental issue is that all of the issues we're discussing are trying to do the same thing: "There are two niches, one in each of two separate parts of this. Optimize the layout based on that." In that regard, a struct and a slice should not be treated significantly differently. |
This issue isn't about jointly using two pre-existing niches. It's about adding a new set of niches to the length field in slice-refs, by exploiting the isize::MAX bytes upper limit, something we're currently not doing.
They're based on the same thing, derived from the validity ranges of the fields. |
They may be based on the same thing, but that doesn't mean the changes are functionally dependent in the implementation. |
...Unless they are, in which case that segment of the layout code is possibly in even more dire need of being scrapped and rewritten than I thought. |
I mean if we define the slice length field validity range - which currently isn't explicitly set and so defaults to the same validity as usize - then both metadata and niches fall out of that automatically. Treating them differently for the purpose of llvmir metadata and niche calculation would take extra effort. |
I suppose I'll reopen this then, but now I'm wondering if we can convince the layout code that |
I think layout code should already be seeing an univariant ADT with two fields and scalarpair abi. My PR does result in layout changes. |
The issue with this is that when T is a zst, it is now okay for a Also |
From reddit thread: why can't rust optimize the size of
Option<Option<&str>>
?Indeed, in spite of the fact that
&str
doesn't all use more than half of possible bit sequences (top bit of 2nd word is always zero, plus first word can not be zero) onlyOption<&str>
is optimizedWould it make sense to teach compiler about that niche or is it prevented by some deeper issue?
The text was updated successfully, but these errors were encountered: