about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2022-11-01Rollup merge of #103638 - ia0:multivalue, r=nagisaManish Goregaokar-0/+1
Add `multivalue` target feature to WASM target This PR is similar to #99643 and #97808. It addresses #96472 for the `multivalue` target feature. The problem I am trying to fix is to remove the following warning when compiling with `-C target-feature=+multivalue` for `--target=wasm32-unknown-unknown`. ``` warning: unknown feature specified for `-Ctarget-feature`: `multivalue` | = note: it is still passed through to the codegen backend = note: consider filing a feature request ```
2022-10-31Rewrite implementation of `#[alloc_error_handler]`Amanieu d'Antras-4/+14
The new implementation doesn't use weak lang items and instead changes `#[alloc_error_handler]` to an attribute macro just like `#[global_allocator]`. The attribute will generate the `__rg_oom` function which is called by the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom` function is defined in any crate then the compiler shim will call `__rdl_oom` in the alloc crate which will simply panic. This also fixes link errors with `-C link-dead-code` with `default_alloc_error_handler`: `__rg_oom` was previously defined in the alloc crate and would attempt to reference the `oom` lang item, even if it didn't exist. This worked as long as `__rg_oom` was excluded from linking since it was not called. This is a prerequisite for the stabilization of `default_alloc_error_handler` (#102318).
2022-10-31[debuginfo] Make debuginfo type names for slices and str consistent.Michael Woerister-13/+13
Before this PR, the compiler would emit the debuginfo name `slice$<T>` for all kinds of slices, regardless of whether they are behind a reference or not and regardless of the kind of reference. As a consequence, the types `Foo<&[T]>`, `Foo<[T]>`, and `Foo<&mut [T]>` would end up with the same type name `Foo<slice$<T> >` in debuginfo, making it impossible to disambiguate between them by name. Similarly, `&str` would get the name `str` in debuginfo, so the debuginfo name for `Foo<str>` and `Foo<&str>` would be the same. In contrast, `*const [bool]` and `*mut [bool]` would be `ptr_const$<slice$<bool> >` and `ptr_mut$<slice$<bool> >`, i.e. the encoding does not lose information about the type. This PR removes all special handling for slices and `str`. The types `&[bool]`, `&mut [bool]`, and `&str` thus get the names `ref$<slice2$<bool> >`, `ref_mut$<slice2$<bool> >`, and `ref$<str$>` respectively -- as one would expect.
2022-10-31Rollup merge of #103603 - camsteffen:refactor-lang, r=oli-obkDylan DPC-7/+6
Lang item cleanups Various cleanups related to lang items.
2022-10-31Use `br` instead of `switch` in more cases.Nicholas Nethercote-2/+28
`codegen_switchint_terminator` already uses `br` instead of `switch` when there is one normal target plus the `otherwise` target. But there's another common case with two normal targets and an `otherwise` target that points to an empty unreachable BB. This comes up a lot when switching on the tags of enums that use niches. The pattern looks like this: ``` bb1: ; preds = %bb6 %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4 %4 = sub i8 %3, 2 %5 = icmp eq i8 %4, 0 %_6 = select i1 %5, i64 0, i64 1 switch i64 %_6, label %bb3 [ i64 0, label %bb4 i64 1, label %bb2 ] bb3: ; preds = %bb1 unreachable ``` This commit adds code to convert the `switch` to a `br`: ``` bb1: ; preds = %bb6 %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4 %4 = sub i8 %3, 2 %5 = icmp eq i8 %4, 0 %_6 = select i1 %5, i64 0, i64 1 %6 = icmp eq i64 %_6, 0 br i1 %6, label %bb4, label %bb2 bb3: ; No predecessors! unreachable ``` This has a surprisingly large effect on compile times, with reductions of 5% on debug builds of some crates. The reduction is all due to LLVM taking less time. Maybe LLVM is just much better at handling `br` than `switch`. The resulting code is still suboptimal. - The `icmp`, `select`, `icmp` sequence is silly, converting an `i1` to an `i64` and back to an `i1`. But with the current code structure it's hard to avoid, and LLVM will easily clean it up, in opt builds at least. - `bb3` is usually now truly dead code (though not always, so it can't be removed universally).
2022-10-29Cleanup weak lang itemsCameron Steffen-7/+6
2022-10-27Add `multivalue` target feature to WASM targetJulien Cretin-0/+1
2022-10-27Accept `TyCtxt` instead of `TyCtxtAt` in `Ty::is_*` functionsMaybe Waffle-4/+3
Functions in answer: - `Ty::is_freeze` - `Ty::is_sized` - `Ty::is_unpin` - `Ty::is_copy_modulo_regions`
2022-10-25Rollup merge of #103511 - nnethercote:bb-tweaks, r=bjorn3Dylan DPC-82/+75
Codegen tweaks Best reviewed one commit at a time. r? `@bjorn3`
2022-10-25Simplify `cast_shift_expr_rhs`.Nicholas Nethercote-24/+18
It's only ever used with shift operators.
2022-10-25Inline and remove `cast_shift_rhs`.Nicholas Nethercote-9/+0
It has a single call site.
2022-10-25Clarify some cleanup stuff.Nicholas Nethercote-6/+10
- Rearrange the match in `llbb_with_landing_pad` so the `(Some,Some)` cases are together. - Add assertions to indicate two MSVC-only paths.
2022-10-25Rename two `TerminatorCodegenHelper` methods.Nicholas Nethercote-13/+16
`TerminatorCodegenHelper` has three methods `llblock`, `llbb`, and `lltarget`. They're all similar, but the names given no indication of the differences. This commit renames `lltarget` as `llbb_with_landing_pad`, and `llblock` as `llbb_with_cleanup`. These aren't fantastic names, but at least it's now clear that `llbb` is the lowest-level of the three and the other two wrap it.
2022-10-25rustc_codegen_ssa: use more consistent naming.Nicholas Nethercote-30/+31
Ensure: - builders always have a `bx` suffix; - backend basic blocks always have an `llbb` suffix, - paired builders and basic blocks have consistent prefixes.
2022-10-24Support raw-dylib functions being used inside inlined functionsDaniel Paoliello-5/+37
2022-10-23Introduce dedicated `-Zdylib-lto` flag for enabling LTO on `dylib`sJakub Beránek-4/+12
2022-10-23Allow LTO for dylibsbjorn3-11/+29
2022-10-23Add missing export for the oom strategy symbolbjorn3-1/+10
2022-10-23Migrate all diagnosticsNilstrieb-62/+62
2022-10-22Auto merge of #103240 - BelovDV:issue-102290, r=petrochenkovbors-0/+4
Add architectures to fn create_object_file Fixes #102290 r? `@petrochenkov`
2022-10-22Auto merge of #103231 - ecnelises:le_fix, r=lcnrbors-4/+2
Remove byte swap of valtree hash on big endian This addresses problem reported in #103183. The code was originally introduced in https://github.com/rust-lang/rust/commit/e14b34c386ad2809e937e0e6e0379c5cc5474954. (see https://github.com/rust-lang/rust/pull/96591) On big-endian environment, this operation sequence actually put the other half from 128-bit result, thus we got different hash result on LE and BE.
2022-10-22Auto merge of #103196 - Nilstrieb:no-meta-query, r=cjgillotbors-1/+1
Get rid of native_library projection queries They don't seem particularly useful as I don't expect native libraries to change frequently. Maybe they do provide significant value of keeping incremental compilation green though, I'm not sure.
2022-10-20Auto merge of #103092 - petrochenkov:weaklto, r=wesleywiserbors-4/+9
linker: Fix weak lang item linking with combination windows-gnu + LLD + LTO In https://github.com/rust-lang/rust/pull/100404 this logic was originally disabled for MSVC due to issues with LTO, but the same issues appear on windows-gnu with LLD because that LLD uses the same underlying logic as MSVC LLD, just with re-syntaxed command line options. So this PR just disables it for LTO builds in general.
2022-10-19Get rid of native_library projection queriesnils-1/+1
They don't seem particularly useful as I don't expect native libraries to change frequently.
2022-10-19Add architectures to fn create_object_fileDaniil Belov-0/+4
2022-10-19Remove byte swap of valtree hash on big endianQiu Chaofan-4/+2
2022-10-18Auto merge of #102418 - citrus-it:illumos-strip-debug, r=nagisabors-9/+40
The illumos linker does not support --strip-debug When building and testing rust 1.64.0 on illumos, we saw a large number of failing tests associated with: ``` = note: ld: fatal: unrecognized option '--strip-debug' ld: fatal: use the -z help option for usage information collect2: error: ld returned 1 exit status ``` The illumos linker does not support the `--strip-debug` option (although it does support `--strip-all`).
2022-10-15linker: Fix weak lang item linking with combination windows-gnu + LLD + LTOVadim Petrochenkov-4/+9
2022-10-15The illumos linker does not support --strip-debugAndy Fiddaman-9/+40
2022-10-15Auto merge of #101832 - compiler-errors:dyn-star-plus, r=eholkbors-34/+57
Make `dyn*` casts into a coercion, allow `dyn*` upcasting I know that `dyn*` is likely not going to be a feature exposed to surface Rust, but this makes it slightly more ergonomic to write tests for these types anyways. ... and this was just fun to implement anyways. 1. Make `dyn*` into a coercion instead of a cast 2. Enable `dyn*` upcasting since we basically get it for free 3. Simplify some of the cast checking code since we're using the coercion path now r? `@eholk` but feel free to reassign cc `@nikomatsakis` and `@tmandry` who might care about making `dyn*` casts into a coercion
2022-10-14Sort target features alphabeticallynils-96/+112
2022-10-14Address nits, add test for implicit dyn-star coercion without feature gateMichael Goulet-2/+5
2022-10-14Allow dyn* upcastingMichael Goulet-34/+54
2022-10-13Rollup merge of #102641 - eholk:dyn-star-box, r=compiler-errorsYuki Okushi-0/+9
Support casting boxes to dyn* Boxes have a pointer type at codegen time which LLVM does not allow to be transparently converted to an integer. Work around this by inserting a `ptrtoint` instruction if the argument is a pointer. r? ``@compiler-errors`` Fixes #102427
2022-10-12Add a fixmeEric Holk-0/+3
2022-10-12Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errorsDylan DPC-2/+5
translation: eager translation Part of #100717. See [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/295010720) for additional context. - **Store diagnostic arguments in a `HashMap`**: Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`. - **Add `AddToDiagnostic::add_to_diagnostic_with`**: `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure. - **Add `DiagnosticMessage::Eager`**: Add variant of `DiagnosticMessage` for eagerly translated messages (messages in the target language which don't need translated by the emitter during emission). Also adds `eager_subdiagnostic` function which is intended to be invoked by the diagnostic derive for subdiagnostic fields which are marked as needing eager translation. - **Support `#[subdiagnostic(eager)]`**: Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`. - **Finish migrating `rustc_query_system`**: Using eager translation, migrate the remaining repeated cycle stack diagnostic. - **Split formatting initialization and use in diagnostic derives**: Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move. This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg` anyway. However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as: let diag = { /* create diagnostic */ }; diag.span_suggestion_with_style( span, fluent::crate::slug, format!("{}", __binding_0), Applicability::Unknown, SuggestionStyle::ShowAlways ); /* + other subdiagnostic additions */ diag.set_arg("foo", __binding_0); /* + other `set_arg` calls */ diag.emit(); For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first. Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition. By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added. let diag = { /* create diagnostic */ }; let __code_0 = format!("{}", __binding_0); /* + other formatting */ diag.set_arg("foo", __binding_0); /* + other `set_arg` calls */ diag.span_suggestion_with_style( span, fluent::crate::slug, __code_0, Applicability::Unknown, SuggestionStyle::ShowAlways ); /* + other subdiagnostic additions */ diag.emit(); - **Remove field ordering logic in diagnostic derive:** Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem. r? ```@compiler-errors```
2022-10-11Rollup merge of #102612 - ↵Matthias Krüger-91/+414
JhonnyBillM:migrate-codegen-ssa-to-diagnostics-structs, r=davidtwco Migrate `codegen_ssa` to diagnostics structs - [Part 1] Initial migration of `codegen_ssa`. Going to split this crate migration in at least two PRs in order to avoid a huge PR and to quick off some questions around: 1. Translating messages from "external" crates. 2. Interfacing with OS messages. 3. Adding UI tests while migrating diagnostics. _See comments below._
2022-10-10errors: use `HashMap` to store diagnostic argsDavid Wood-2/+5
Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-08Rollup merge of #102675 - ouz-a:mir-technical-debt, r=oli-obkMatthias Krüger-2/+8
Remove `mir::CastKind::Misc` As discussed in #97649 `mir::CastKind::Misc` is not clear, this PR addresses that by creating a new enum variant for every valid cast. r? ````@oli-obk````
2022-10-07Cast vtable type tooEric Holk-0/+1
2022-10-07ADD - implement IntoDiagnostic for thorin::Error wrapperJhonny Bill Mena-12/+193
2022-10-07Address PR commentsJhonny Bill Mena-45/+13
- UPDATE - revert migration of logs - UPDATE - use derive on LinkRlibError enum - [Gardening] UPDATE - alphabetically sort fluent_messages - UPDATE - use PathBuf and unify both AddNativeLibrary to use Display (which is what PathBuf uses when conforming to IntoDiagnosticArg) - UPDATE - fluent messages sort after rebase
2022-10-07ADD - initial port of link.rsJhonny Bill Mena-58/+141
2022-10-07DELETE - unused error after PR# 100101 was mergedJhonny Bill Mena-6/+0
2022-10-07UPDATE - resolve fixme and emit errors via HandlerJhonny Bill Mena-13/+6
2022-10-07UPDATE - codege-ssa errors to new Diagnostic macro nameJhonny Bill Mena-16/+16
2022-10-07UPDATE - migrate write.rs to new diagnostics infraJhonny Bill Mena-22/+67
2022-10-07UPDATE - migrate linker.rs to new diagnostics infraJhonny Bill Mena-18/+59
2022-10-07UPDATE - LibDefWriteFailure to accept type instead of formatted stringJhonny Bill Mena-7/+8
This follows team’s suggestions in this thread https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20diag.20translation/near/295305249
2022-10-07ADD - migrate lib.def write fatal errorJhonny Bill Mena-3/+10
This diagnostic has no UI test 🤔 Should we add some? If so, how?