Commit Graph

53 Commits

Author SHA1 Message Date
katelyn a. martin df45c579de rustc_target: add "unwind" payloads to `Abi`
### Overview

    This commit begins the implementation work for RFC 2945. For more
    information, see the rendered RFC [1] and tracking issue [2].

    A boolean `unwind` payload is added to the `C`, `System`, `Stdcall`,
    and `Thiscall` variants, marking whether unwinding across FFI
    boundaries is acceptable. The cases where each of these variants'
    `unwind` member is true correspond with the `C-unwind`,
    `system-unwind`, `stdcall-unwind`, and `thiscall-unwind` ABI strings
    introduced in RFC 2945 [3].

 ### Feature Gate and Unstable Book

    This commit adds a `c_unwind` feature gate for the new ABI strings.
    Tests for this feature gate are included in `src/test/ui/c-unwind/`,
    which ensure that this feature gate works correctly for each of the
    new ABIs.

    A new language features entry in the unstable book is added as well.

 ### Further Work To Be Done

    This commit does not proceed to implement the new unwinding ABIs,
    and is intentionally scoped specifically to *defining* the ABIs and
    their feature flag.

 ### One Note on Test Churn

    This will lead to some test churn, in re-blessing hash tests, as the
    deleted comment in `src/librustc_target/spec/abi.rs` mentioned,
    because we can no longer guarantee the ordering of the `Abi`
    variants.

    While this is a downside, this decision was made bearing in mind
    that RFC 2945 states the following, in the "Other `unwind` Strings"
    section [3]:

    >  More unwind variants of existing ABI strings may be introduced,
    >  with the same semantics, without an additional RFC.

    Adding a new variant for each of these cases, rather than specifying
    a payload for a given ABI, would quickly become untenable, and make
    working with the `Abi` enum prone to mistakes.

    This approach encodes the unwinding information *into* a given ABI,
    to account for the future possibility of other `-unwind` ABI
    strings.

 ### Ignore Directives

    `ignore-*` directives are used in two of our `*-unwind` ABI test
    cases.

    Specifically, the `stdcall-unwind` and `thiscall-unwind` test cases
    ignore architectures that do not support `stdcall` and
    `thiscall`, respectively.

    These directives are cribbed from
    `src/test/ui/c-variadic/variadic-ffi-1.rs` for `stdcall`, and
    `src/test/ui/extern/extern-thiscall.rs` for `thiscall`.

    This would otherwise fail on some targets, see:
    fcf697f902

 ### Footnotes

[1]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
[2]: https://github.com/rust-lang/rust/issues/74990
[3]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md#other-unwind-abi-strings
2021-03-09 14:38:29 -05:00
Erin Power 79c5fa1f0c Revert non-power-of-two vector restriction 2021-03-02 09:41:41 +01:00
bors 1fdadbf13a Auto merge of #82159 - BoxyUwU:uwu, r=varkor
Use correct param_env in conservative_is_privately_uninhabited

cc `@lcnr`
r? `@varkor` since this is your FIXME that was removed ^^
2021-02-24 21:54:52 +00:00
Ellen 42cbfd6346 yeet 2021-02-23 23:35:59 +00:00
Simonas Kazlauskas 7130e462ee Fix sizes of repr(C) enums on hexagon
Enums on hexagon use a smallest size (but at least 1 byte) that fits all
the enumeration values. This is unlike many other ABIs where enums are
at least 32 bits.
2021-02-22 01:05:17 +02:00
bors bb587b1a17 Auto merge of #80652 - calebzulawski:simd-lanes, r=nagisa
Improve SIMD type element count validation

Resolves rust-lang/stdsimd#53.

These changes are motivated by `stdsimd` moving in the direction of const generic vectors, e.g.:
```rust
#[repr(simd)]
struct SimdF32<const N: usize>([f32; N]);
```

This makes a few changes:
* Establishes a maximum SIMD lane count of 2^16 (65536).  This value is arbitrary, but attempts to validate lane count before hitting potential errors in the backend.  It's not clear what LLVM's maximum lane count is, but cranelift's appears to be much less than `usize::MAX`, at least.
* Expands some SIMD intrinsics to support arbitrary lane counts.  This resolves the ICE in the linked issue.
* Attempts to catch invalid-sized vectors during typeck when possible.

Unresolved questions:
* Generic-length vectors can't be validated in typeck and are only validated after monomorphization while computing layout.  This "works", but the errors simply bail out with no context beyond the name of the type.  Should these errors instead return `LayoutError` or otherwise provide context in some way?  As it stands, users of `stdsimd` could trivially produce monomorphization errors by making zero-length vectors.

cc `@bjorn3`
2021-02-07 22:25:14 +00:00
Hugues de Valon ce9818f2b7 Add a new ABI to support cmse_nonsecure_call
This commit adds a new ABI to be selected via `extern
"C-cmse-nonsecure-call"` on function pointers in order for the compiler to
apply the corresponding cmse_nonsecure_call callsite attribute.
For Armv8-M targets supporting TrustZone-M, this will perform a
non-secure function call by saving, clearing and calling a non-secure
function pointer using the BLXNS instruction.

See the page on the unstable book for details.

Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
2021-02-02 13:04:31 +00:00
bors b05fd2a15d Auto merge of #81388 - bjorn3:wasm_bindgen_fix, r=nikomatsakis
Fix abi for wasm-bindgen

Hopefully fixes https://github.com/rust-lang/rust/issues/81386. `@alexcrichton` can you confirm this fixes wasm-bindgen?

r? `@alexcrichton`
2021-01-28 22:01:42 +00:00
Yuki Okushi 446edd1e1a
Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Refractor a few more types to `rustc_type_ir`

In the continuation of #79169, ~~blocked on that PR~~.

This PR:
 - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance`
 - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler.

~~I will split up that commit to make this easier to review and to have a better commit history.~~
EDIT: done, I split the PR in commits of 200-ish lines each

r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-28 15:09:02 +09:00
bjorn3 c1c06f3e3f Use PassMode::Direct for Abi::Aggregate by default 2021-01-26 14:49:35 +01:00
bjorn3 eb99ea5142 Revert "Wasm-bindgen abi compat using cast_to"
This reverts commit 903c553f4a.
2021-01-26 13:38:59 +01:00
bjorn3 903c553f4a Wasm-bindgen abi compat using cast_to 2021-01-26 11:31:37 +01:00
bjorn3 ecbc661030 Revert "Fix abi for wasm-bindgen"
This reverts commit 4d2766e352.
2021-01-26 11:09:09 +01:00
bjorn3 36df9c55e5 Revert "Share wasm-bindgen compat abi selection code"
This reverts commit e7a056fe20.
2021-01-26 11:09:06 +01:00
bjorn3 e7a056fe20 Share wasm-bindgen compat abi selection code 2021-01-25 21:32:57 +01:00
bjorn3 4d2766e352 Fix abi for wasm-bindgen 2021-01-25 18:48:49 +01:00
Caleb Zulawski 8451656fe7 Fix maximum SIMD lane count, and expose it to other crates. Disallow SIMD vectors with non-power-of-two lengths. 2021-01-23 16:33:19 -05:00
bjorn3 fa12fdbc29 Fix review comments 2021-01-23 17:55:39 +01:00
bjorn3 a93dace55c Never create an temporary PassMode::Direct when it is not a valid pass mode for a type 2021-01-23 10:30:39 +01:00
bjorn3 ba484de538 Move some code around 2021-01-23 10:30:39 +01:00
bjorn3 da0309c711 Use PassMode::Pair by default for Abi::ScalarPair for all abi's and in return position
Abi::ScalarPair is only ever used for types that don't have a stable
layout anyway so this doesn't break any FFI. It does however reduce the
amount of special casing on the abi outside of the code responsible for
abi specific adjustments to the pass mode.
2021-01-23 10:30:38 +01:00
LeSeulArtichaut 933bb18956 Use `rustc_type_ir::{IntTy,UintTy,FloatTy} instead of the `rustc_ast` ones in types 2021-01-18 21:09:23 +01:00
Tomasz Miąsko 5ea1d0e865 Don't ICE when computing a layout of a generator tainted by errors 2021-01-14 13:13:13 +01:00
Caleb Zulawski 07db2bfe39 Implement floating point SIMD intrinsics over all vector widths, and limit SIMD vector lengths. 2021-01-03 01:06:54 -05:00
Matthias Krüger 0c3af22e08 don't redundantly repeat field names 2020-12-29 22:26:58 +01:00
Jack Huey 328fcee4af Make BoundRegion have a kind of BoungRegionKind 2020-12-18 15:27:28 -05:00
bors a094ff9590 Auto merge of #79547 - erikdesjardins:byval, r=nagisa
Pass arguments up to 2*usize by value

In https://github.com/rust-lang/rust/pull/77434#discussion_r498719533, `@eddyb` said:

> I wonder if it makes sense to limit this to returns [...]

Let's do a perf run and find out.

It seems the `extern "C"` ABI will pass arguments up to 2*usize in registers: https://godbolt.org/z/n8E6zc. (modified from https://github.com/rust-lang/rust/issues/26494#issuecomment-619506345)

r? `@nagisa`
2020-12-02 15:17:32 +00:00
Erik Desjardins 0183b4109a Pass arguments up to 2*usize by value 2020-11-29 20:08:00 -05:00
Aman Arora e35e46c113 Be cautious of calling upvar_tys before mir 2020-11-29 19:20:28 -05:00
bors 760430e6fd Auto merge of #78863 - KodrAus:feat/simd-array, r=oli-obk
Support repr(simd) on ADTs containing a single array field

This is a squash and rebase of `@gnzlbg's` #63531

I've never actually written code in the compiler before so just fumbled my way around until it would build 😅

I imagine there'll be some work we need to do in `rustc_codegen_cranelift` too for this now, but might need some input from `@bjorn3` to know what that is.

cc `@rust-lang/project-portable-simd`

-----

This PR allows using `#[repr(simd)]` on ADTs containing a single array field:

```rust
 #[repr(simd)] struct S0([f32; 4]);
 #[repr(simd)] struct S1<const N: usize>([f32; N]);
 #[repr(simd)] struct S2<T, const N: usize>([T; N]);
```

This should allow experimenting with portable packed SIMD abstractions on nightly that make use of const generics.
2020-11-29 09:28:09 +00:00
bjorn3 43968aa8b8 Replace sext() and zext() with single ext() method 2020-11-21 19:22:31 +01:00
bjorn3 39b8b2b623 Remove StructRet arg attr
It is applied exactly when the return value has an indirect pass mode.
Except for InReg on x86 fastcall, arg attrs are now only used for
optimization purposes and thus are fine to ignore.
2020-11-21 19:22:31 +01:00
bjorn3 42b0b8080d Replace ByVal attribute with on_stack field for Indirect
This makes it clearer that only PassMode::Indirect allows ByVal
2020-11-21 19:22:30 +01:00
bjorn3 967a228208 Replace ZExt and SExt flags with ArgExtension enum
Both flags are mutually exclusive
2020-11-21 19:07:38 +01:00
Mara Bos 43d13e2d58
Rollup merge of #79158 - lcnr:lazy-norm-coerce, r=oli-obk
type is too big -> values of the type are too big

strictly speaking, `[u8; usize::MAX]` or even `[[[u128; usize::MAX]; usize::MAX]; usize::MAX]` are absolutely fine types as long as you don't try to deal with any values of it.

This error message seems to cause some confusion imo, for example in https://github.com/rust-lang/rust/pull/79135#issuecomment-729361380 so I would prefer us to be more precise here.

See the added test case which uses one of these types without causing an error.

r? ``@oli-obk``
2020-11-18 15:46:40 +01:00
Bastian Kauschke 88584d5800 change error for `LayoutErr::SizeOverflow` 2020-11-18 11:38:30 +01:00
Bastian Kauschke 2bf93bd852 compiler: fold by value 2020-11-16 22:34:57 +01:00
Vadim Petrochenkov dc004d4809 rustc_target: Rename some target options to avoid tautology
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`
2020-11-08 17:29:13 +03:00
Vadim Petrochenkov bf66988aa1 Collapse all uses of `target.options.foo` into `target.foo`
with an eye on merging `TargetOptions` into `Target`.

`TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
2020-11-08 17:29:13 +03:00
gnzlbg 6e88e96ccf Support repr(simd) on ADTs containing a single array field
This PR allows using `#[repr(simd)]` on ADTs containing a
single array field:

```rust
 #[repr(simd)] struct S0([f32; 4]);
 #[repr(simd)] struct S1<const N: usize>([f32; N]);
 #[repr(simd)] struct S2<T, const N: usize>([T; N]);
```

This should allow experimenting with portable packed SIMD
abstractions on nightly that make use of const generics.
2020-11-08 12:01:48 +10:00
est31 4fa5578774 Replace target.target with target and target.ptr_width with target.pointer_width
Preparation for a subsequent change that replaces
rustc_target::config::Config with its wrapped Target.

On its own, this commit breaks the build. I don't like making
build-breaking commits, but in this instance I believe that it
makes review easier, as the "real" changes of this PR can be
seen much more easily.

Result of running:

find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \;
./x.py fmt
2020-10-15 12:02:24 +02:00
est31 a0fc455d30 Replace absolute paths with relative ones
Modern compilers allow reaching external crates
like std or core via relative paths in modules
outside of lib.rs and main.rs.
2020-10-13 14:16:45 +02:00
Yuki Okushi d50349ba8d
Rollup merge of #76995 - LingMan:middle_matches, r=varkor
Reduce boilerplate with the matches! macro

Replaces simple bool `match`es of the form

    match $expr {
        $pattern => true
        _ => false
    }

and their inverse with invocations of the matches! macro.

Limited to rustc_middle for now to get my feet wet.
2020-10-06 16:25:58 +09:00
Jonas Schievink b01694e0a2 Returns values up to 2*usize by value 2020-10-02 00:23:25 +02:00
Jonas Schievink 4c5acc4ed7 Return values up to 128 bits in registers 2020-09-26 15:34:26 +02:00
bors 5b9e886403 Auto merge of #73453 - erikdesjardins:tuplayout, r=eddyb
Ignore ZST offsets when deciding whether to use Scalar/ScalarPair layout

This is important because Scalar/ScalarPair layout previously would not be used if any ZST had nonzero offset.
For example, before this change, only `((), u128)` would be laid out like `u128`, not `(u128, ())`.

Fixes #63244
2020-09-25 14:42:20 +00:00
LingMan a6ff925f8b Reduce boilerplate with the matches! macro
Replaces simple bool `match`es of the form

    match $expr {
        $pattern => true
        _ => false
    }

and their inverse with invocations of the matches! macro.
2020-09-21 05:28:40 +02:00
Bastian Kauschke 6734230425 do not ICE on `ty::Bound` in Layout::compute 2020-09-20 08:22:35 +02:00
LeSeulArtichaut 3e14b684dd Change ty.kind to a method 2020-09-04 17:47:51 +02:00
Dan Aloni 75a042e74b Fix some unwanted uses of Debug formatting on user-facing messages
While formatting for user diagnostics used `Display` for all most cases,
some small amount of cases used `Debug` instead.  Until now, `Display`
and `Debug` yielded the same output for many types. However, with path
trimming, we want to show a shorter path for the user, these cases need
fixing.
2020-09-02 10:40:10 +03:00