about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2024-01-10Rename `{create,emit}_warning` as `{create,emit}_warn`.Nicholas Nethercote-10/+10
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`, all of which use an abbreviated form.
2024-01-10Rename `struct_span_err!` as `struct_span_code_err!`.Nicholas Nethercote-13/+14
Because it takes an error code after the span. This avoids the confusing overlap with the `DiagCtxt::struct_span_err` method, which doesn't take an error code.
2024-01-09Rollup merge of #118903 - azhogin:azhogin/skip_second_stmt_debuginfo.rs, ↵Matthias Krüger-11/+6
r=petrochenkov Improved support of collapse_debuginfo attribute for macros. Added walk_chain_collapsed function to consider collapse_debuginfo attribute in parent macros in call chain. Fixed collapse_debuginfo attribute processing for cranelift (there was if/else branches error swap). cc https://github.com/rust-lang/rust/issues/100758
2024-01-08Improved support of collapse_debuginfo attribute for macros.Andrew Zhogin-11/+6
2024-01-08Use chaining for `DiagnosticBuilder` construction and `emit`.Nicholas Nethercote-4/+4
To avoid the use of a mutable local variable, and because it reads more nicely.
2024-01-08Use chaining in `DiagnosticBuilder` construction.Nicholas Nethercote-124/+56
To avoid the use of a mutable local variable, and because it reads more nicely.
2024-01-08Make `DiagnosticBuilder::emit` consuming.Nicholas Nethercote-3/+3
This works for most of its call sites. This is nice, because `emit` very much makes sense as a consuming operation -- indeed, `DiagnosticBuilderState` exists to ensure no diagnostic is emitted twice, but it uses runtime checks. For the small number of call sites where a consuming emit doesn't work, the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will be removed in subsequent commits.) Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes consuming, while `delay_as_bug_without_consuming` is added (which will also be removed in subsequent commits.) All this requires significant changes to `DiagnosticBuilder`'s chaining methods. Currently `DiagnosticBuilder` method chaining uses a non-consuming `&mut self -> &mut Self` style, which allows chaining to be used when the chain ends in `emit()`, like so: ``` struct_err(msg).span(span).emit(); ``` But it doesn't work when producing a `DiagnosticBuilder` value, requiring this: ``` let mut err = self.struct_err(msg); err.span(span); err ``` This style of chaining won't work with consuming `emit` though. For that, we need to use to a `self -> Self` style. That also would allow `DiagnosticBuilder` production to be chained, e.g.: ``` self.struct_err(msg).span(span) ``` However, removing the `&mut self -> &mut Self` style would require that individual modifications of a `DiagnosticBuilder` go from this: ``` err.span(span); ``` to this: ``` err = err.span(span); ``` There are *many* such places. I have a high tolerance for tedious refactorings, but even I gave up after a long time trying to convert them all. Instead, this commit has it both ways: the existing `&mut self -> Self` chaining methods are kept, and new `self -> Self` chaining methods are added, all of which have a `_mv` suffix (short for "move"). Changes to the existing `forward!` macro lets this happen with very little additional boilerplate code. I chose to add the suffix to the new chaining methods rather than the existing ones, because the number of changes required is much smaller that way. This doubled chainging is a bit clumsy, but I think it is worthwhile because it allows a *lot* of good things to subsequently happen. In this commit, there are many `mut` qualifiers removed in places where diagnostics are emitted without being modified. In subsequent commits: - chaining can be used more, making the code more concise; - more use of chaining also permits the removal of redundant diagnostic APIs like `struct_err_with_code`, which can be replaced easily with `struct_err` + `code_mv`; - `emit_without_diagnostic` can be removed, which simplifies a lot of machinery, removing the need for `DiagnosticBuilderState`.
2024-01-05Auto merge of #119192 - michaelwoerister:mcp533-push, r=cjgillotbors-9/+9
Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives This PR replaces almost all of the remaining `FxHashMap`s in query results with either `FxIndexMap` or `UnordMap`. The only case that is missing is the `EffectiveVisibilities` struct which turned out to not be straightforward to transform. Once that is done too, we can remove the `HashStable` implementation from `HashMap`. The first commit adds the `StableCompare` trait which is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableCompare` implementation can be provided to offer a lightweight way for stable sorting. The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`. The rest of the commits are rather mechanical and don't overlap, so they are best reviewed individually. Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-01-05Auto merge of #119621 - compiler-errors:rollup-5mxtvuk, r=compiler-errorsbors-31/+31
Rollup of 10 pull requests Successful merges: - #119034 (Allow coverage tests to ignore test modes, and to enable color in coverage reports) - #119148 (Tweak suggestions for bare trait used as a type) - #119538 (Cleanup error handlers: round 5) - #119566 (Remove `-Zdump-mir-spanview`) - #119567 (Remove `-Zreport-delayed-bugs`.) - #119577 (Migrate memory overlap check from validator to lint) - #119583 (Make `intrinsics::assume` const stable) - #119586 ([rustdoc] Fix invalid handling for static method calls in jump to definition feature) - #119588 (Move `i586-unknown-netbsd` from tier 2 to tier 3 platform support table) - #119601 (`Emitter` cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-31/+31
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-05Auto merge of #118991 - nikic:scalar-pair, r=nagisabors-21/+13
Separate immediate and in-memory ScalarPair representation Currently, we assume that ScalarPair is always represented using a two-element struct, both as an immediate value and when stored in memory. This currently works fairly well, but runs into problems with https://github.com/rust-lang/rust/pull/116672, where a ScalarPair involving an i128 type can no longer be represented as a two-element struct in memory. For example, the tuple `(i32, i128)` needs to be represented in-memory as `{ i32, [3 x i32], i128 }` to satisfy alignment requirements. Using `{ i32, i128 }` instead will result in the second element being stored at the wrong offset (prior to LLVM 18). Resolve this issue by no longer requiring that the immediate and in-memory type for ScalarPair are the same. The in-memory type will now look the same as for normal struct types (and will include padding filler and similar), while the immediate type stays a simple two-element struct type. This also means that booleans in immediate ScalarPair are now represented as i1 rather than i8, just like we do everywhere else. The core change here is to llvm_type (which now treats ScalarPair as a normal struct) and immediate_llvm_type (which returns the two-element struct that llvm_type used to produce). The rest is fixing things up to no longer assume these are the same. In particular, this switches places that try to get pointers to the ScalarPair elements to use byte-geps instead of struct-geps.
2024-01-04Make iteration order of supported_target_features query stableMichael Woerister-2/+2
2024-01-04Make iteration order of wasm_import_module_map query stableMichael Woerister-3/+3
2024-01-04Make iteration order of upstream_monomorphizations query stableMichael Woerister-4/+4
2024-01-04Rollup merge of #118521 - dpaoliello:asan, r=wesleywiserMatthias Krüger-14/+30
Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag This enables address sanitizer for x86_64-pc-windows-msvc and i686-pc-windows-msvc targets when linked with the MSVC linker (link.exe) by leveraging the `/INFERASANLIBS` option to automatically find and link in Microsoft's address sanitizer runtime: <https://learn.microsoft.com/en-us/cpp/sanitizers/asan-runtime?view=msvc-170> Implements https://github.com/rust-lang/compiler-team/issues/702 Fixes #89339 (for MSVC targets using the MSVC linker only) Supercedes #89369 Successful x86_64-msvc build showing the sanitizer tests working: https://github.com/rust-lang/rust/actions/runs/7228346880/job/19697628258?pr=118521
2024-01-04Remove `is_lint` field from `Level::Error`.Nicholas Nethercote-1/+1
Because it's redundant w.r.t. `Diagnostic::is_lint`, which is present for every diagnostic level. `struct_lint_level_impl` was the only place that set the `Error` field to `true`, and it's also the only place that calls `Diagnostic::is_lint()` to set the `is_lint` field.
2024-01-04Avoid some `rustc_errors::` qualifiers.Nicholas Nethercote-3/+3
These are misleading, because the mixture of `Level` and `rustc_errors::Level` makes it look like there are two different types involved.
2024-01-03Enable address sanitizer for MSVC targets using INFERASANLIBS linker flagDaniel Paoliello-14/+30
2024-01-03Rollup merge of #119444 - compiler-errors:closure-or-coroutine, r=oli-obkLeón Orell Valerian Liehr-3/+3
Rename `TyCtxt::is_closure` to `TyCtxt::is_closure_or_coroutine` This function has always been used to test whether the def-id was a closure **or** coroutine: https://github.com/rust-lang/rust/pull/118311/files#diff-69ebec59f7d38331dd1be84ede7957977dcaa39e30ed2869b04aa8c99b2079ccR552 -- the name is just confusing because it disagrees with other fns named `is_closure`, like `Ty::is_closure`. So let's rename it.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-28/+28
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2024-01-02Address review commentsNikita Popov-7/+5
2023-12-30Update to bitflags 2 in the compilerNilstrieb-1/+2
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-30is_coroutine -> is_coroutine_or_closureMichael Goulet-3/+3
2023-12-30Auto merge of #118705 - WaffleLapkin:codegen-atomic-exhange-untuple, r=cjgillotbors-4/+2
Change `rustc_codegen_ssa`'s `atomic_cmpxchg` interface to return a pair of values Doesn't change much, but a little nicer that way.
2023-12-28Change `rustc_codegen_ssa`'s `atomic_cmpxchg` interface to return a pair of ↵Bernd Schmidt-4/+2
values
2023-12-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-1/+1
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
2023-12-25Only regular coroutines have movabilityMichael Goulet-1/+1
2023-12-24Remove more `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-10/+11
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-111/+111
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-22Rollup merge of #119198 - compiler-errors:desugaring, r=eholkMichael Goulet-10/+26
Split coroutine desugaring kind from source What a coroutine is desugared from (gen/async gen/async) should be separate from where it comes (fn/block/closure).
2023-12-23Remove all uses of `DiagnosticBuilder::forget_guarantee()`.Nicholas Nethercote-7/+7
There are only three. It's simpler to make the type `DiagnosticBuilder<'_, ()>` from the start, no matter the level, than to change the guarantee later.
2023-12-23Improve some names.Nicholas Nethercote-4/+4
Lots of vectors of messages called `message` or `msg`. This commit pluralizes them. Note that `emit_message_default` and `emit_messages_default` both already existed, and both process a vector, so I renamed the former `emit_messages_default_inner` because it's called by the latter.
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-10/+26
2023-12-22Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errorsbors-47/+48
Fix `EmissionGuarantee` There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them. r? `@compiler-errors`
2023-12-21Auto merge of #119056 - cjgillot:codegen-overalign, r=wesleywiserbors-1/+1
Tolerate overaligned MIR constants for codegen. Fixes https://github.com/rust-lang/rust/issues/117761 cc `@saethlin`
2023-12-20Rollup merge of #118973 - Enselic:fix-IncorrectCguReuseType, r=michaelwoeristerMatthias Krüger-2/+2
rustc_codegen_ssa: Don't drop `IncorrectCguReuseType` , make `rustc_expected_cgu_reuse` attr work In [100753], `IncorrectCguReuseType` accidentally stopped being emitted by removing `diag.span_err(...)`. Begin emitting it again rather than just blindly dropping it, and adjust tests accordingly. We assume that there are no bugs and that the currently actual CGU reuse is correct. If there are bugs, they will be discovered and fixed eventually, and the tests will then be updated. [100753]: https://github.com/rust-lang/rust/pull/100753/commits/706452eba74026c51e8d0fa30aee2497c69eafc0#diff-048389738ddcbe0f9765291a29db1fed9a5f03693d4781cfb5aaa97ffb3c7f84 Closes #118972
2023-12-19rustc_codegen_ssa: Don't let `IncorrectCguReuseType` errors get lostMartin Nordholts-2/+2
In [100753], `IncorrectCguReuseType` accidentally stopped being emitted. Begin emitting it again rather than just blindly dropping it, and adjust tests accordingly. [100753]: https://github.com/rust-lang/rust/pull/100753/commits/706452eba74026c51e8d0fa30aee2497c69eafc0#diff-048389738ddcbe0f9765291a29db1fed9a5f03693d4781cfb5aaa97ffb3c7f84
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-47/+48
And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions.
2023-12-18Auto merge of #119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgrbors-10/+14
Rollup of 5 pull requests Successful merges: - #118852 (coverage: Skip instrumenting a function if no spans were extracted from MIR) - #118905 ([AIX] Fix XCOFF metadata) - #118967 (Add better ICE messages for some undescriptive panics) - #119051 (Replace `FileAllocationInfo` with `FileEndOfFileInfo`) - #119059 (Deny `~const` trait bounds in inherent impl headers) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-18Rollup merge of #118905 - bzEq:revert-u64-on-xcoff, r=WaffleLapkinMatthias Krüger-10/+14
[AIX] Fix XCOFF metadata #118344 accidentally changed the way to get metadata from XCOFF file and broken our internal CI. This PR reverts part of #118344 .
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-10/+9
2023-12-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-49/+48
2023-12-18Rename `CodegenContext::create_diag_handler` as `CodegenContext::create_dcx`.Nicholas Nethercote-9/+5
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-32/+22
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-13/+13
2023-12-18Address commentKai Luo-1/+1
2023-12-17Tolerate overaligned MIR constants for codegen.Camille GILLOT-1/+1
2023-12-15Separate immediate and in-memory ScalarPair representationNikita Popov-14/+8
Currently, we assume that ScalarPair is always represented using a two-element struct, both as an immediate value and when stored in memory. This currently works fairly well, but runs into problems with https://github.com/rust-lang/rust/pull/116672, where a ScalarPair involving an i128 type can no longer be represented as a two-element struct in memory. For example, the tuple `(i32, i128)` needs to be represented in-memory as `{ i32, [3 x i32], i128 }` to satisfy alignment requirement. Using `{ i32, i128 }` instead will result in the second element being stored at the wrong offset (prior to LLVM 18). Resolve this issue by no longer requiring that the immediate and in-memory type for ScalarPair are the same. The in-memory type will now look the same as for normal struct types (and will include padding filler and similar), while the immediate type stays a simple two-element struct type. This also means that booleans in immediate ScalarPair are now represented as i1 rather than i8, just like we do everywhere else. The core change here is to llvm_type (which now treats ScalarPair as a normal struct) and immediate_llvm_type (which returns the two-element struct that llvm_type used to produce). The rest is fixing things up to no longer assume these are the same. In particular, this switches places that try to get pointers to the ScalarPair elements to use byte-geps instead of struct-geps.
2023-12-15Don't pass lint back out of lint decoratorMichael Goulet-1/+3
2023-12-14Rollup merge of #118933 - nnethercote:cleanup-errors-even-more, ↵Jubilee-1/+1
r=compiler-errors Cleanup errors handlers even more A sequel to #118587. r? `@compiler-errors`