summary refs log tree commit diff
path: root/compiler/rustc_abi/src
AgeCommit message (Collapse)AuthorLines
2023-09-08turns out Layout has some more things to worry about -- move ABI comparison ↵Ralf Jung-1/+23
into helper function like is_bool, and some special magic extra fields
2023-09-08accept some differences for rustc_abi(assert_eq), so that we can test more ↵Ralf Jung-0/+17
things to be compatible
2023-08-29there seems to be no reason to treat ZST specially in these casesRalf Jung-12/+2
2023-08-29rustc_abi: audit uses of is_zst; fix a case of giving an enum insufficient ↵Ralf Jung-7/+18
alignment
2023-08-29add is_1zst helper methodRalf Jung-0/+10
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-03Add `internal_features` lintNilstrieb-0/+1
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-17/+10
2023-07-25Rollup merge of #114060 - davidtwco:issue-113279, r=wesleywiserMatthias Krüger-2/+3
abi: unsized field in union - assert to delay bug Fixes #113279. > Unions cannot have unsized fields, and as such, layout computation for unions asserts that each union field is sized (as this would normally have halted compilation earlier). > > However, if a generator ends up with an unsized local - a circumstance in which an error will always have been emitted earlier, for example, if attempting to dereference a `&str` - then the generator transform will produce a union with an unsized field. > > Since https://github.com/rust-lang/rust/pull/110107, later passes will be run, such as constant propagation, and can attempt layout computation on the generator, which will result in layout computation of `str` in the context of it being a field of a union - and so the aforementioned assertion would cause an ICE. > > It didn't seem appropriate to try and detect this case in the MIR body and skip this specific pass; tainting the MIR body or delaying a bug from the generator transform (or elsewhere) wouldn't prevent this either (as neither would prevent the later pass from running); and tainting when the deref of `&str` is reported, if that's possible, would unnecessarily prevent potential other errors from being reported later in compilation, and is very tailored to this specific case of getting a unsized type in a generator. > > Given that this circumstance can only happen when an error should have already been reported, the correct fix appears to be just changing the assert to a delayed bug. This will still assert if there is some circumstance where this occurs and no error has been reported, but it won't crash the compiler in this instance. While debugging this, I noticed a translation ICE in a delayed bug, so I fixed that too: > During borrowck, the `MultiSpan` from a buffered diagnostic is cloned and used to emit a delayed bug indicating a diagnostic was buffered - when the buffered diagnostic is translated, then the cloned `MultiSpan` may contain labels which can only render with the diagnostic's arguments, but the delayed bug being emitted won't have those arguments. Adds a function which clones `MultiSpan` without also cloning the contained labels, and use this function when creating the buffered diagnostic delayed bug.
2023-07-25abi: unsized field in union - assert to delay bugDavid Wood-2/+3
Unions cannot have unsized fields, and as such, layout computation for unions asserts that each union field is sized (as this would normally have halted compilation earlier). However, if a generator ends up with an unsized local - a circumstance in which an error will always have been emitted earlier, for example, if attempting to dereference a `&str` - then the generator transform will produce a union with an unsized field. Since #110107, later passes will be run, such as constant propagation, and can attempt layout computation on the generator, which will result in layout computation of `str` in the context of it being a field of a union - and so the aforementioned assertion would cause an ICE. It didn't seem appropriate to try and detect this case in the MIR body and skip this specific pass; tainting the MIR body or delaying a bug from the generator transform (or elsewhere) wouldn't prevent this either (as neither would prevent the later pass from running); and tainting when the deref of `&str` is reported, if that's possible, would unnecessarily prevent potential other errors from being reported later in compilation, and is very tailored to this specific case of getting a unsized type in a generator. Given that this circumstance can only happen when an error should have already been reported, the correct fix appears to be just changing the assert to a delayed bug. This will still assert if there is some circumstance where this occurs and no error has been reported, but it won't crash the compiler in this instance. Signed-off-by: David Wood <david@davidtw.co>
2023-07-25interpret: refactor projection code to work on a common trait, and use that ↵Ralf Jung-1/+1
for visitors
2023-07-21Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"David Tolnay-98/+10
This reverts commit 557359f92512ca88b62a602ebda291f17a953002, reversing changes made to 1e6c09a803fd543a98bfbe1624d697a55300a786.
2023-07-21Track (partial) niche information in `NaiveLayout`Moulins-2/+8
Still more complexity, but this allows computing exact `NaiveLayout`s for null-optimized enums, and thus allows calls like `transmute::<Option<&T>, &U>()` to work in generic contexts.
2023-07-21CTFE: move `target_{i, u}size_{min, max)` to `rustc_abi::TargetDataLayout`Moulins-11/+13
2023-07-21recover null-ptr optimization by adding a special case to the niching logicMoulins-8/+12
2023-07-21support non-null pointer niches in CTFEMoulins-0/+37
2023-07-21restrict the valid range of references if `-Z reference-niches` is setMoulins-0/+31
Note that this doesn't actually work at all, as many places in rustc assume that references only have the null niche.
2023-07-21add crate-local `-Z reference_niches` unstable flag (does nothing for now)Moulins-0/+8
2023-07-14i686-windows: make requested alignment > 4 special case apply transitivelyErik Desjardins-29/+25
2023-07-10aarch64-linux: properly handle 128bit aligned aggregatesErik Desjardins-8/+71
2023-07-10repr(align) <= 4 should still be byvalErik Desjardins-17/+17
2023-07-10move has_repr to layout, handle repr(transparent) properlyErik Desjardins-1/+26
2023-07-06clean up struct layout codeLukas Markeffsky-4/+4
2023-06-13Auto merge of #112062 - lukas-code:unsized-layout, r=wesleywiserbors-44/+54
Make struct layout not depend on unsizeable tail fixes (after backport) https://github.com/rust-lang/rust/issues/112048 Since unsizing `Ptr<Foo<T>>` -> `Ptr<Foo<U>` just copies the pointer and adds the metadata, the layout of `Foo` must not depend on niches in and alignment of the tail `T`. Nominating for beta 1.71, because it will have this issue: `@rustbot` label beta-nominated
2023-06-08Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few ↵Andrew Xie-1/+3
misc issues, added collect to UnordItems
2023-06-01Use translatable diagnostics in `rustc_const_eval`Deadbeef-7/+42
2023-05-29disable some layout optimizations for unsizable structsThe 8472-42/+48
2023-05-29Make struct layout not depend on unsizeable tailLukas Markeffsky-2/+6
2023-05-16Avoid `&format("...")` calls in error message code.Nicholas Nethercote-2/+2
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
2023-05-05Reorder to keep duplicate checks in sync.Luqman Aden-7/+12
2023-05-05Review feedbackLuqman Aden-14/+23
2023-05-05Don't discard preferred alignment in scalar pair.Luqman Aden-4/+2
2023-05-05Factor out checks in layout check and add helper inherent_size.Luqman Aden-1/+22
2023-05-05Incorporate review feedback from 103926.Luqman Aden-38/+33
2023-05-05Add helper methods inherent_align and to_union on Abi.Luqman Aden-1/+26
2023-05-05Do not use scalar layout if there are ZSTs with alignment > 1Oli Scherer-20/+42
2023-04-28layout-alignment-promotion logic should depend on the niche-biasThe 8472-7/+22
For start-biased layout we want to avoid overpromoting so that the niche doesn't get pushed back. For end-biased layout we want to avoid promoting fields that may contain one of the niches of interest.
2023-04-28[review] add comments, turn flag into enumThe 8472-23/+44
2023-04-27add tracing for layout optimizationsThe 8472-0/+44
2023-04-27don't promote large fields to higher alignments if that would affect niche ↵The 8472-13/+24
placement
2023-04-27try two different niche-placement strategies when layouting univariant structsThe 8472-6/+70
2023-04-27refactor: extract functionThe 8472-214/+220
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-1/+1
2023-04-18Store hashes in special types so they aren't accidentally encoded as numbersBen Kimock-4/+6
2023-04-17Rollup merge of #110394 - scottmcm:less-idx-new, r=WaffleLapkinMatthias Krüger-5/+4
Various minor Idx-related tweaks Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify. cc https://github.com/rust-lang/compiler-team/issues/606 r? `@WaffleLapkin`
2023-04-16Remove the loop in `Align::from_bytes`Scott McMurray-7/+4
Perf is almost certainly irrelevant, but might as well simplify it, since `trailing_zeros` does exactly what's needed.
2023-04-16Various minor Idx-related tweaksScott McMurray-5/+4
Nothing particularly exciting here, but a couple of things I noticed as I was looking for more index conversions to simplify.
2023-04-09Fix some clippy::complexityNilstrieb-1/+1
2023-04-08Enforce that PointerLike requires a pointer-like ABIMichael Goulet-0/+10
2023-04-04Use `FieldIdx` in `FieldsShape`Scott McMurray-52/+46
Finally got to the main motivating example from the MCP :)