about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2023-03-01Rollup merge of #108505 - Nilstrieb:further-unify-validity-intrinsics, ↵Matthias Krüger-31/+11
r=michaelwoerister Further unify validity intrinsics Also merges the inhabitedness check into the query to further unify the code paths. Depends on #108364
2023-02-28Auto merge of #106774 - Nugine:master, r=Amanieubors-2/+1
Stabilize cmpxchg16b_target_feature Tracking issue for target features + #44839 stdarch issue + https://github.com/rust-lang/stdarch/issues/827 stdarch PR + https://github.com/rust-lang/stdarch/pull/1358 reference PR + https://github.com/rust-lang/reference/pull/1331 It's my first time contributing to rust-lang/rust. Please tell me if I missed something.
2023-02-28Auto merge of #99767 - LeSeulArtichaut:stable-target-feature-11, r=estebankbors-29/+18
Stabilize `#![feature(target_feature_11)]` ## Stabilization report ### Summary Allows for safe functions to be marked with `#[target_feature]` attributes. Functions marked with `#[target_feature]` are generally considered as unsafe functions: they are unsafe to call, cannot be assigned to safe function pointers, and don't implement the `Fn*` traits. However, calling them from other `#[target_feature]` functions with a superset of features is safe. ```rust // Demonstration function #[target_feature(enable = "avx2")] fn avx2() {} fn foo() { // Calling `avx2` here is unsafe, as we must ensure // that AVX is available first. unsafe { avx2(); } } #[target_feature(enable = "avx2")] fn bar() { // Calling `avx2` here is safe. avx2(); } ``` ### Test cases Tests for this feature can be found in [`src/test/ui/rfcs/rfc-2396-target_feature-11/`](https://github.com/rust-lang/rust/tree/b67ba9ba208ac918228a18321fc3a11a99b1c62b/src/test/ui/rfcs/rfc-2396-target_feature-11/). ### Edge cases - https://github.com/rust-lang/rust/issues/73631 Closures defined inside functions marked with `#[target_feature]` inherit the target features of their parent function. They can still be assigned to safe function pointers and implement the appropriate `Fn*` traits. ```rust #[target_feature(enable = "avx2")] fn qux() { let my_closure = || avx2(); // this call to `avx2` is safe let f: fn() = my_closure; } ``` This means that in order to call a function with `#[target_feature]`, you must show that the target-feature is available while the function executes *and* for as long as whatever may escape from that function lives. ### Documentation - Reference: https://github.com/rust-lang/reference/pull/1181 --- cc tracking issue #69098 r? `@ghost`
2023-02-27Implement checked Shl/Shr at MIR building.Camille GILLOT-11/+0
2023-02-27Unify all validity check intrinsicsNilstrieb-31/+11
Also merges the inhabitedness check into the query to further unify the code paths.
2023-02-27Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errorsMatthias Krüger-3/+6
Unify validity checks into a single query Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check in #100423, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one. I am not entirely happy with the naming and key type and open for improvements. r? oli-obk
2023-02-24Rename many interner functions.Nicholas Nethercote-5/+5
(This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup
2023-02-23Unify validity checks into a single queryNilstrieb-3/+6
Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one.
2023-02-22Auto merge of #108340 - eggyal:remove_traversal_trait_aliases, r=oli-obkbors-3/+3
Remove type-traversal trait aliases #107924 moved the type traversal (folding and visiting) traits into the type library, but created trait aliases in `rustc_middle` to minimise both the API churn for trait consumers and the arising boilerplate. As mentioned in that PR, an alternative approach of defining subtraits with blanket implementations of the respective supertraits was also considered at that time but was ruled out as not adding much value. Unfortunately, it has since emerged that rust-analyzer has difficulty with these trait aliases at present, resulting in a degraded contributor experience (see the recent [r-a has become useless](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/r-a.20has.20become.20useless) topic on the #t-compiler/help Zulip stream). This PR removes the trait aliases, and accordingly the underlying type library traits are now used directly; they are parameterised by `TyCtxt<'tcx>` rather than just the `'tcx` lifetime, and imports have been updated to reflect the fact that the trait aliases' explicitly named traits are no longer automatically brought into scope. These changes also roll-back the (no-longer required) workarounds to #107747 that were made in b409329c624b9e3bbd7d8e07697e2e9f861a45b6. Since this PR is just a find+replace together with the changes necessary for compilation & tidy to pass, it's currently just one mega-commit. Let me know if you'd like it broken up. r? `@oli-obk`
2023-02-22Remove type-traversal trait aliasesAlan Egerton-3/+3
2023-02-22various: translation resources from cg backendDavid Wood-0/+4
Extend `CodegenBackend` trait with a function returning the translation resources from the codegen backend, which can be added to the complete list of resources provided to the emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22errors: generate typed identifiers in each crateDavid Wood-2/+7
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-21Linker: use -z <params> instead of -z<params>Frank Denis-8/+8
The GNU linker accepts -z<params>, but this is undocumented, and not supported by other linkers. In particular, `zig cc`, when used as the C compiler/linker (e.g. when using `cargo-zigbuild`), will not accept this undocumented syntax. In `linker.rs`, both syntaxes are also used inconsistently. The Go compiler used to have the same issue, but fixed it: https://github.com/golang/go/commit/38607c553878da21b5042e63997ecb3b7201e684
2023-02-20Fix metadata encoding and decoding to use the right lengthRune Tynan-1/+6
2023-02-20Try adding metadata length prefix, and obey it while decodingRune Tynan-0/+1
2023-02-20Move the resolver into a queryOli Scherer-0/+1
2023-02-19Auto merge of #107921 - cjgillot:codegen-overflow-check, r=tmiaskobors-39/+7
Make codegen choose whether to emit overflow checks ConstProp and DataflowConstProp currently have a specific code path not to propagate constants when they overflow. This is meant to have the correct behaviour when inlining from a crate with overflow checks (like `core`) into a crate compiled without. This PR shifts the behaviour change to the `Assert(Overflow*)` MIR terminators: if the crate is compiled without overflow checks, just skip emitting the assertions. This is already what happens with `OverflowNeg`. This allows ConstProp and DataflowConstProp to transform `CheckedBinaryOp(Add, u8::MAX, 1)` into `const (0, true)`, and let codegen ignore the `true`. The interpreter is modified to conform to this behaviour. Fixes #35310
2023-02-18Stop implementing _with_overflow intrinsics in codegen backends.Camille GILLOT-25/+0
2023-02-18Remove special case in rvalue codegen.Camille GILLOT-12/+0
2023-02-18Make name more explicit.Camille GILLOT-2/+2
2023-02-18Comment codegen optimization.Camille GILLOT-0/+3
2023-02-18Remove outdated comment.Camille GILLOT-3/+0
2023-02-18Adapt interpreter.Camille GILLOT-10/+6
2023-02-18Do not codegen overflow check when not required.Camille GILLOT-2/+11
2023-02-18Emit the right types for vtable pointers when dropping dyn*Michael Goulet-80/+78
2023-02-18Use inttoptr to support usize as dyn* value, use pointercast to make sure ↵Michael Goulet-0/+8
pointers are compatible
2023-02-18make first component of dyn* use pointer layout+type, and adjust DynStar commentRalf Jung-8/+1
2023-02-18Auto merge of #99679 - repnop:kernel-address-sanitizer, r=cuviperbors-1/+2
Add `kernel-address` sanitizer support for freestanding targets This PR adds support for KASan (kernel address sanitizer) instrumentation in freestanding targets. I included the minimal set of `x86_64-unknown-none`, `riscv64{imac, gc}-unknown-none-elf`, and `aarch64-unknown-none` but there's likely other targets it can be added to. (`linux_kernel_base.rs`?) KASan uses the address sanitizer attributes but has the `CompileKernel` parameter set to `true` in the pass creation.
2023-02-17Rollup merge of #108149 - tshepang:typo, r=Dylan-DPCMatthias Krüger-1/+1
typo
2023-02-17typoTshepang Mbambo-1/+1
2023-02-17Rollup merge of #108086 - alexcrichton:wasm-relaxed-simd-feature, r=eholkMatthias Krüger-0/+1
wasm: Register the `relaxed-simd` target feature This WebAssembly proposal is likely to reach stage 4 soon so this starts the support in Rust for the proposal by adding a target feature that can be enabled via attributes for the stdarch project to bind the intrinsics.
2023-02-16Replace some `then`s with some `then_some`sMaybe Waffle-1/+1
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-8/+5
2023-02-15Auto merge of #108012 - compiler-errors:issue-107999, r=oli-obkbors-2/+8
Don't ICE in `might_permit_raw_init` if reference is polymorphic Emitting optimized MIR for a polymorphic function may require computing layout of a type that isn't (yet) known. This happens in the instcombine pass, for example. Let's fail gracefully in that condition. cc `@saethlin` fixes #107999
2023-02-15Auto merge of #108006 - cjgillot:def-impl, r=oli-obkbors-41/+39
Avoid accessing HIR when it can be avoided Experiment to see if it helps some incremental cases. Will be rebased once https://github.com/rust-lang/rust/pull/107942 gets merged. r? `@ghost`
2023-02-15wasm: Register the `relaxed-simd` target featureAlex Crichton-0/+1
This WebAssembly proposal is likely to reach stage 4 soon so this starts the support in Rust for the proposal by adding a target feature that can be enabled via attributes for the stdarch project to bind the intrinsics.
2023-02-14Add `kernel-address` sanitizer support for freestanding targetsWesley Norris-1/+2
2023-02-14Make permit_uninit/zero_init fallibleMichael Goulet-2/+8
2023-02-14Do not fetch HIR to check target features.Camille GILLOT-8/+5
2023-02-14Do not fetch HIR to compute symbols.Camille GILLOT-33/+34
2023-02-14s/eval_usize/eval_target_usize/ for clarityOli Scherer-8/+17
2023-02-13Alias folding/visiting traits instead of re-exportAlan Egerton-1/+1
2023-02-13Reduce direct `mk_ty` usage.Nicholas Nethercote-4/+3
We use more specific `mk_*` functions in most places, might as well use them as much as possible.
2023-02-12Auto merge of #105601 - BelovDV:change-rlib-with-not-stable, r=petrochenkovbors-96/+41
Enable new rlib in non stable cases If bundled static library uses cfg (unstable) or whole-archive (wasn't supported) bundled libs are packed even without packed_bundled_libs. r? `@petrochenkov`
2023-02-10remove redundant clonesMatthias Krüger-1/+1
2023-02-10[link] enable packed bundled lib in non stable casesDaniil Belov-96/+41
2023-02-05Remove misleading target feature aliasesCaleb Zulawski-3/+0
2023-02-04Auto merge of #107267 - cjgillot:keep-aggregate, r=oli-obkbors-11/+12
Do not deaggregate MIR This turns out to simplify a lot of things. I haven't checked the consequences for miri yet. cc `@JakobDegen` r? `@oli-obk`
2023-02-02Codegen SetDiscriminant after field assignment.Camille GILLOT-15/+11
This matches the order in which deaggregation was performed.
2023-02-02Interpret aggregates.Camille GILLOT-0/+5