Commit graph

130 commits

Author SHA1 Message Date
bors c290e9de32 Auto merge of #126326 - eggyal:ununsafe-StableOrd, r=michaelwoerister
Un-unsafe the `StableOrd` trait

Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc.

[Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler).

cc [MCP 533](https://github.com/rust-lang/compiler-team/issues/533), #105175, `@michaelwoerister`

r? `@Nilstrieb`
2024-06-25 15:51:35 +00:00
Alan Egerton 0e73e7095a
Ensure careful consideration is given by impls
Added an associated `const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED`
to the `StableOrd` trait to ensure that implementors carefully consider
whether the trait's contract is upheld, as incorrect implementations can
cause miscompilations.
2024-06-22 07:17:02 +01:00
Alan Egerton 114dd2061e
Un-unsafe the StableOrd trait
Whilst incorrect implementations of this trait can cause miscompilation,
they cannot cause memory unsafety in rustc.
2024-06-12 13:01:22 +01:00
Nicholas Nethercote 75b164d836 Use tidy to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.

For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
  `allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
  sometimes the order is alphabetical, and sometimes there is no
  particular order.
- Sometimes the attributes of a particular kind aren't even grouped
  all together, e.g. there might be a `feature`, then an `allow`, then
  another `feature`.

This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.

Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
  because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
  ignored in `rustfmt.toml`).
2024-06-12 15:49:10 +10:00
Ralf Jung 37aeb75eb6 don't inhibit random field reordering on repr(packed(1)) 2024-05-21 19:22:04 +02:00
Laurențiu Nicola 8ec5a3d7b4 Temporarily revert to NonZeroUsize in rustc-abi to fix building on stable 2024-05-18 11:27:29 +03:00
Scott McMurray 99213ae164 Make index_by_increasing_offset return one item for primitives 2024-05-11 21:22:51 -07:00
Scott McMurray dcab06d7d2 Unify Rvalue::Aggregate paths in cg_ssa 2024-05-11 21:22:51 -07:00
Matthias Krüger 1ae0d90b72
Rollup merge of #124797 - beetrees:primitive-float, r=davidtwco
Refactor float `Primitive`s to a separate `Float` type

Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`.

As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`.

Tracking issue: #116909

`@rustbot` label +F-f16_and_f128
2024-05-10 16:10:46 +02:00
Markus Reiter bd8e565e16
Use generic NonZero. 2024-05-08 21:37:55 +02:00
beetrees 3769fddba2
Refactor float Primitives to a separate Float type 2024-05-06 14:56:10 +01:00
Matthias Krüger 613bccc4ca
Rollup merge of #124555 - Zalathar:init-coverage, r=nnethercote
coverage: Clean up creation of MC/DC condition bitmaps

This PR improves the code for creating and initializing [MC/DC](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) condition bitmap variables, as introduced by #123409 and modified by #124255.

- The condition bitmap variables are now created eagerly at the start of per-function codegen, via a new `init_coverage` method in `CoverageInfoBuilderMethods`. This avoids having to retroactively create the bitmaps while doing codegen for an individual coverage statement.
- As a result, we can now create and initialize those bitmaps using existing safe APIs, instead of having to perform our own unsafe call to `llvm::LLVMBuildAlloca`.
- This PR also tweaks the way we count the number of condition bitmaps needed, by tracking the total number of bitmaps needed (max depth + 1), instead of only tracking the maximum depth. This reduces the potential for subtle off-by-one confusion.
2024-05-03 20:33:46 +02:00
Ralf Jung 65d74785d7 Align: add bytes_usize and bits_usize 2024-05-01 15:57:33 +02:00
Zalathar 0b3a47900e coverage: Set up MC/DC bitmaps without additional unsafe code
Because this now always takes place at the start of the function, we can just
use the normal `alloca` method and then initialize each bitmap immediately.

This patch also moves bitmap setup out of the `mcdc_parameters` method, because
there is no longer any particular reason for it to be there.
2024-05-01 09:55:22 +10:00
Gurinder Singh 4aafec1bc1 Rename inihibit_union_abi_opt() to inihibits_union_abi_opt()
The present tense makes it read more naturally at use site i.e.
"this repr _inhibits_ optimizations"
2024-04-28 13:09:36 +05:30
beetrees 6e5f1dacf3
Use the Align type when parsing alignment attributes 2024-04-01 03:05:55 +01:00
bors 3cbb93223f Auto merge of #121668 - erikdesjardins:commonprim, r=scottmcm,oli-obk
Represent `Result<usize, Box<T>>` as ScalarPair(i64, ptr)

This allows types like `Result<usize, std::io::Error>` (and integers of differing sign, e.g. `Result<u64, i64>`) to be passed in a pair of registers instead of through memory, like `Result<u64, u64>` or `Result<Box<T>, Box<U>>` are today.

Fixes #97540.

r? `@ghost`
2024-03-13 15:25:35 +00:00
Matthias Krüger efe9deace8
Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, r=davidtwco
Rework `untranslatable_diagnostic` lint

Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`.

r? ``@davidtwco``
2024-03-06 22:02:46 +01:00
Ralf Jung f391c0793b only set noalias on Box with the global allocator 2024-03-05 15:03:33 +01:00
Nicholas Nethercote d602394827 Change message type in bug functions.
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`.

Because these functions don't produce user-facing output and we don't
want their strings to be translated.
2024-03-05 17:11:42 +11:00
Erik Desjardins f574c65147 simplify common prim computation 2024-02-28 17:55:04 -05:00
Trevor Gross e3f63d9375 Add f16 and f128 to rustc_type_ir::FloatTy and rustc_abi::Primitive
Make changes necessary to support these types in the compiler.
2024-02-28 12:58:32 -05:00
Erik Desjardins 4dabbcb23b allow using scalarpair with a common prim of ptr/ptr-sized-int 2024-02-27 00:09:12 -05:00
Ralf Jung 297abc35b3 fix some references to no-longer-existing ReprOptions.layout_seed 2024-02-26 10:40:48 +01:00
Nadrieril e12101c4db Fix rustc_abi build on stable 2024-01-16 21:15:31 +01:00
bjorn3 6ed37bdc42 Avoid specialization for the Span Encodable and Decodable impls 2023-12-31 20:42:17 +00:00
Nilstrieb ffafcd8819 Update to bitflags 2 in the compiler
This involves lots of breaking changes. There are two big changes that
force changes. The first is that the bitflag types now don't
automatically implement normal derive traits, so we need to derive them
manually.

Additionally, bitflags now have a hidden inner type by default, which
breaks our custom derives. The bitflags docs recommend using the impl
form in these cases, which I did.
2023-12-30 18:17:28 +01:00
Jubilee Young 8facfb23c6 Extract fn layout_of_struct 2023-12-16 02:36:35 -08:00
Jubilee Young b525f76bb5 Extract fn layout_of_enum 2023-12-16 02:31:57 -08:00
Jubilee Young f116bc6e27 Manually inline scalar_unit 2023-12-16 01:43:40 -08:00
Jubilee Young 6959818ec2 Hoist fn absent 2023-12-16 01:41:56 -08:00
Jubilee Young 0e9d400587 Annotate panic! reasons during enum layout
Add some reasons to the panics, and use more exhaustive matches.
2023-12-15 02:21:31 -08:00
Nicholas Nethercote cb91235131 Rename LayoutCalculator::delay_bug as LayoutCalculator::delayed_bug.
To match with the previous commits.
2023-12-02 09:01:34 +11:00
Nilstrieb 21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Mark Rousskov db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
hkalbasi c8a25eddfe Make the randomize feature of rustc_abi additive 2023-11-05 21:51:47 +03:30
Nicholas Nethercote 8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Ralf Jung 2ef5897a89 fix failure to detect a too-big-type after adding padding 2023-10-27 18:07:53 +02:00
Oli Scherer e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Michael Howell 2ff2624722 docs: add Rust logo to more compiler crates
c6e6ecb1af added it to some of the
compiler's crates, but avoided adding it to all of them to reduce
bit-rot. This commit adds to more.
2023-10-16 15:38:08 -07:00
Ralf Jung f3f9b795bd place evaluation: require the original pointer to be aligned if an access happens 2023-10-15 18:13:31 +02:00
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