Commit Graph

89 Commits

Author SHA1 Message Date
Lukas Wirth 0aedec4849 Remove unnecessary features from rustc_abi 2023-10-04 11:43:57 +02:00
Lukas Wirth 2d73d30a3c Fix incorrect inlining of RangeInclusive::size_hint 2023-10-02 21:31:16 +02:00
Lukas Wirth b25c84510d Add some docs regarding rustc_abi rust-analyzer compat changes 2023-10-02 21:31:16 +02:00
Lukas Wirth 67e5eb6cec Cfg out ReprOption::field_shuffle_seed 2023-10-02 21:31:16 +02:00
Lukas Wirth e8a2673159 Add VariantIdx back 2023-10-02 21:31:16 +02:00
Lukas Wirth f14b7c9443 Move FieldIdx and Layout to rustc_target 2023-10-02 21:31:16 +02:00
Lukas Wirth b47ad3b744 Bring back generic FieldIdx 2023-10-02 21:31:11 +02:00
Lukas Wirth 3b99d73f5a Unglob rustc_abi imports 2023-10-02 21:29:19 +02:00
Nicholas Nethercote 17e3793eb1 Name some local variables more consistently.
By making every `alt_foo` exactly match a `foo`.
2023-10-02 09:12:47 +11:00
Nicholas Nethercote 2369adc5d8 Remove unnecessary `pub`s. 2023-10-01 21:57:09 +11:00
Nicholas Nethercote ddb742225a Rename two parsing closures.
To match `parse_address_space` and `parse_bits` above.
2023-10-01 21:57:09 +11:00
Nicholas Nethercote 86ecfdd605 Minor comment and whitespace tweaks. 2023-10-01 21:57:06 +11:00
Ralf Jung b0cf4c28ea turns out Layout has some more things to worry about -- move ABI comparison into helper function
like is_bool, and some special magic extra fields
2023-09-08 09:14:07 +02:00
Ralf Jung c3e14edd8b accept some differences for rustc_abi(assert_eq), so that we can test more things to be compatible 2023-09-08 08:59:55 +02:00
Ralf Jung bf91321e0f there seems to be no reason to treat ZST specially in these cases 2023-08-29 08:58:58 +02:00
Ralf Jung 0da9409e08 rustc_abi: audit uses of is_zst; fix a case of giving an enum insufficient alignment 2023-08-29 08:58:58 +02:00
Ralf Jung 0360b6740b add is_1zst helper method 2023-08-29 08:58:21 +02:00
Mark Rousskov 0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Nilstrieb 5830ca216d Add `internal_features` lint
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-08-03 14:50:50 +02:00
Matthias Krüger 23815467a2 inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
Matthias Krüger ba6982b8a0
Rollup merge of #114060 - davidtwco:issue-113279, r=wesleywiser
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-25 19:21:39 +02:00
David Wood 037b27430b
abi: unsized field in union - assert to delay bug
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-25 15:50:39 +01:00
Ralf Jung a2bcafa500 interpret: refactor projection code to work on a common trait, and use that for visitors 2023-07-25 14:30:58 +02:00
David Tolnay 5bbf0a8306
Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk"
This reverts commit 557359f925, reversing
changes made to 1e6c09a803.
2023-07-21 22:35:57 -07:00
Moulins 7f109086ee Track (partial) niche information in `NaiveLayout`
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-21 14:23:23 +02:00
Moulins 39cfe70e4f CTFE: move `target_{i, u}size_{min, max)` to `rustc_abi::TargetDataLayout` 2023-07-21 03:31:47 +02:00
Moulins 4fb039ed6c recover null-ptr optimization by adding a special case to the niching logic 2023-07-21 03:31:46 +02:00
Moulins 76c49aead6 support non-null pointer niches in CTFE 2023-07-21 03:31:45 +02:00
Moulins 3c05276866 restrict the valid range of references if `-Z reference-niches` is set
Note that this doesn't actually work at all, as many places in rustc
assume that references only have the null niche.
2023-07-21 03:31:45 +02:00
Moulins 8b847ef734 add crate-local `-Z reference_niches` unstable flag (does nothing for now) 2023-07-21 03:31:45 +02:00
Erik Desjardins 2daacf5af9 i686-windows: make requested alignment > 4 special case apply transitively 2023-07-14 17:48:13 -04:00
Erik Desjardins d1e764cb3b aarch64-linux: properly handle 128bit aligned aggregates 2023-07-10 19:19:40 -04:00
Erik Desjardins 7e933b4e26 repr(align) <= 4 should still be byval 2023-07-10 19:19:40 -04:00
Erik Desjardins 00b3eca0df move has_repr to layout, handle repr(transparent) properly 2023-07-10 19:19:39 -04:00
Lukas Markeffsky 478071ba9d clean up struct layout code 2023-07-06 13:04:13 +00:00
bors 6330daade9 Auto merge of #112062 - lukas-code:unsized-layout, r=wesleywiser
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-13 22:34:59 +00:00
Andrew Xie 54d7b327e5 Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems 2023-06-08 00:38:50 -04:00
Deadbeef 4f83717cf7 Use translatable diagnostics in `rustc_const_eval` 2023-06-01 14:45:18 +00:00
The 8472 3003d05a8b disable some layout optimizations for unsizable structs 2023-05-29 20:16:18 +02:00
Lukas Markeffsky 381b778d27 Make struct layout not depend on unsizeable tail 2023-05-29 14:54:48 +02:00
Nicholas Nethercote 01e33a3600 Avoid `&format("...")` calls in error message code.
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-16 17:59:56 +10:00
Luqman Aden 8e7714d3bb Reorder to keep duplicate checks in sync. 2023-05-05 16:30:32 -07:00
Luqman Aden 012f9a333b Review feedback 2023-05-05 16:14:36 -07:00
Luqman Aden c63a204e23 Don't discard preferred alignment in scalar pair. 2023-05-05 16:11:08 -07:00
Luqman Aden 3b1e535f36 Factor out checks in layout check and add helper inherent_size. 2023-05-05 16:11:03 -07:00
Luqman Aden 4f4f22b11c Incorporate review feedback from 103926. 2023-05-05 16:04:59 -07:00
Luqman Aden a3800535b1 Add helper methods inherent_align and to_union on Abi. 2023-05-05 16:00:19 -07:00
Oli Scherer 23d09aebc8 Do not use scalar layout if there are ZSTs with alignment > 1 2023-05-05 16:00:12 -07:00
The 8472 61fb5a91b7 layout-alignment-promotion logic should depend on the niche-bias
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 23:08:54 +02:00
The 8472 afe106cdc8 [review] add comments, turn flag into enum 2023-04-28 23:08:54 +02:00