Commit Graph

3149 Commits

Author SHA1 Message Date
Alejandro Alonso
df17f7be90 Implement dependent layouts for raw types
Update raw_layout.swift

Allow for concrete specializations of raw layout

Make test platform agnostic
2023-08-01 14:09:23 -07:00
Dario Rexin
b82ac6bcdf Merge pull request #67599 from drexin/wip-112474091
[Runtime] Fix _swift_refCountBytesForMetatype for reference types
2023-07-28 14:53:56 -07:00
Dario Rexin
f257b3bbab [Runtime] Fix _swift_refCountBytesForMetatype for reference types
_swift_addRefCountStringForMetatype and _swift_refCountBytesForMetatype diverged in the code that determines whether a type is a reference, causing the size number of ref count bytes to differ from the actually used bytes. This can cause early termination of the runtime interpreter functions, which in turn causes unbalanced reference counts.

rdar://112474091
2023-07-28 11:55:53 -07:00
Slava Pestov
3a24b5361d TypeDecoder: Push one-element tuple unwrapping down into createTupleType() implementations
The old behavior was only correct when building substituted types,
ie, if createTupleType() was never called with a pack expansion type.

This was the case in the runtime's MetadataLookup which applies
substitutions to an interface type to ultimately construct metadata
for a fully-concrete type, but not in the ASTDemangler, where we
actually build interface types.

Since TypeDecoder doesn't have any way to query the kind of type
it just built, let's just instead make this decision inside the
implementation of the type builder concept.

Fixes https://github.com/apple/swift/issues/67322.
2023-07-27 12:14:54 -04:00
Mike Ash
b7f73cd52b [Runtime] Gracefully handle null genericArgs in SubstGenericParametersFromMetadata.
If a caller passes NULL generic parameters when looking up a generic type, we'll error and return NULL instead of crashing.

rdar://112153818
2023-07-26 16:49:52 -04:00
Slava Pestov
82c172c8e3 Merge pull request #67527 from slavapestov/rdar112866068
Runtime: Lift prohibition on packs in swift_getTypeByMangledName() overload used by mirrors
2023-07-26 06:49:00 -04:00
Slava Pestov
e454458e2a Runtime: Lift prohibition on packs in swift_getTypeByMangledName() overload used by mirrors
Fixes rdar://problem/112866068.
2023-07-25 23:15:01 -04:00
Dario Rexin
620d516fe7 [Runtime] Fix MultiPayloadEnumFN case in swift_resolve_resilientAccessors
rdar://112825968

Offsets were wrong, causing invalid memory accesses
2023-07-25 13:50:17 -07:00
Dario Rexin
f96b099ce9 Merge pull request #67485 from drexin/wip-fix-offset-writing-resolve
[Runtime] Fix issues with dynamic layout string instantiation
2023-07-24 13:09:52 -07:00
Ben Barham
b962cab6e1 Merge pull request #67478 from finagolfin/droid-ci
[Backtracing][Linux] Disable invoking process_vm_readv() for older Android APIs
2023-07-24 10:14:19 -07:00
Dario Rexin
6fb232510b [Runtime] Fix SinglePayloadEnumSimple read offset in swift_resolve_resilientAccessors
The offset was off by 1, causing subsequent tags to not be resolved properly.
2023-07-24 09:47:42 -07:00
Evan Wilde
669285fd17 Merge pull request #65534 from stephank/fix/cmake-3.25
build: fix accidental cmake expansions
2023-07-24 09:44:14 -07:00
Dario Rexin
10685367ce [Runtime] Use the properly resolved tag when adding offset after resolving relative pointers in layout strings
The tag was overwritten after resolve when a prior field caused a non-zero offset. This then caused the runtime to treat is a relative instead of an absolute pointer, causing invalid pointers to be dereferenced.
2023-07-24 09:36:26 -07:00
Finagolfin
4cbbb33dbf [Backtracing][Linux] Disable invoking process_vm_readv() for older Android APIs 2023-07-23 20:11:26 +05:30
Dario Rexin
937d1727a3 [IRGen] Fix enum metadata instantiation for resilient payload
The metadata can't be constant when we generate a layout string at runtime.
2023-07-17 16:00:41 -07:00
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Kuba Mracek
aab7eab240 Be consistent about guarding SWIFT_HAS_OPAQUE_ISAS with SWIFT_OBJC_INTEROP 2023-07-13 09:03:19 -07:00
Mike Ash
2d238bcea5 Merge pull request #67168 from mikeash/ptrauth-struct-context-descriptors
[Runtime][IRGen] Sign type context descriptor pointers.
2023-07-11 17:03:53 -04:00
Mike Ash
fe7e13bba5 [Runtime][IRGen] Sign type context descriptor pointers.
Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
2023-07-07 18:10:35 -04:00
Dario Rexin
b3cdcda6c7 Merge pull request #67173 from drexin/wip-singleton-inject
Support destructiveInjectEnumTag in singleton enums with layout strings
2023-07-06 19:33:05 -07:00
Dario Rexin
de177dc2ec [Runtime] Add destructiveEnumInject support for singleton enums with layout strings 2023-07-06 15:46:59 -07:00
Dario Rexin
81153489f6 [Runtime] Add destructiveEnumInject support for simple single payload enums in layout strings 2023-07-06 15:23:38 -07:00
Slava Pestov
b471cd308f TypeDecoder: Don't demangle freestanding PackExpansionTypes 2023-07-05 16:35:17 -04:00
Slava Pestov
da145aa43a Runtime: Relax prohibition on packs in SubstGenericParameterFn implementations 2023-07-05 16:35:16 -04:00
Slava Pestov
f40a447980 TypeDecoder: Implement lane-wise pack expansion 2023-07-05 16:35:16 -04:00
Slava Pestov
338cb7ccb9 TypeDecoder: Change createTupleType() to take labels as ArrayRef<StringRef> instead of std::string 2023-07-05 16:33:43 -04:00
Dario Rexin
fd4ef74266 Merge pull request #67067 from drexin/wip-refactor-simple-enum-tag
[Runtime] Abstract handling of simple single payload enum handling
2023-06-30 17:03:02 -07:00
Dario Rexin
13930c9347 [Runtime] Abstract handling of simple single payload enum handling
We can re-use some of this in destructiveInjectEnumTag, so adding the abstraction in preparation of that.
2023-06-30 13:51:47 -07:00
Dario Rexin
e2b8366fdb [Runtime] Remove incorrect skip in handleSinglePayloadEnumGenericTag 2023-06-30 13:05:32 -07:00
Dario Rexin
36914d9a68 Merge pull request #67039 from drexin/wip-mp-gen-destr-inject-tag
Support destructiveInjectEnumTag in generic multi payload enums with layout strings
2023-06-29 19:20:38 -07:00
Yuta Saito
af9b8293e0 Merge pull request #67014 from swiftwasm/pr-5212f18969d0b9d9853af4bc8293cb156ac57eec
[wasm][stdlib] Add wasi-libc support for Heap.cpp
2023-06-30 09:00:08 +09:00
Dario Rexin
8114ecc3e0 [Runtime] Add destructiveInjectEnumTag support for generic multi payload enums with layout strings 2023-06-29 16:34:10 -07:00
Dario Rexin
89d37da9ee [Runtime] Add destructiveInjectEnumTag support for generic single payload enums with layout strings 2023-06-29 10:37:51 -07:00
Yuta Saito
cc6f53efed [wasm][stdlib] Add wasi-libc support for Heap.cpp
Pointers returned by malloc() are 16-byte aligned on wasi-libc, even
it's 32-bit architecture. See wasi-libc's dlmalloc configuration:
aecd368c6d/dlmalloc/src/dlmalloc.c (L31)
2023-06-29 08:32:09 +00:00
Dario Rexin
964a51f4e9 [Runtime] Abstract tag handling for generic single payload enums (#67002)
* [Runtime] Abstract tag handling for generic single payload enums

This functionality will be shared across multiple functions, so adding the abstraction in preparation of that.

* Update BytecodeLayouts.cpp
2023-06-28 22:13:58 -07:00
Yuta Saito
7aa6cbbe2d Merge pull request #66851 from kateinoigakukun/katei/patch-series/driver-wasm-toolchain
Re-land `static-executable-args.lnk` changes
2023-06-29 12:38:51 +09:00
Dario Rexin
8733969222 [Runtime] Fix sign-compare warning in BytecodeLayouts (#67001) 2023-06-28 19:14:37 -07:00
Dario Rexin
3524945cd4 [IRGen+Runtime] Implement getEnumTag for singleton enums in layout strings (#66985) 2023-06-28 14:25:34 -07:00
Mike Ash
811950eb93 Merge pull request #66959 from mikeash/standard-protocol-manglings-go-faster
[Runtime] Fast-path lookup of protocol descriptors with standard manglings.
2023-06-28 09:48:44 -04:00
Dario Rexin
ca664141cc [IRGen+Runtime] Add support for initializeBufferWithCopyOfBuffer to layout strings (#66965) 2023-06-27 18:05:30 -07:00
Mike Ash
516c21a790 [Runtime] Fast-path lookup of protocol descriptors with standard manglings.
We weren't taking advantage of standard manglings in _findProtocolDescriptor like wo do in _findContextDescriptor. Extract out the "standard mangling" code and call it from both to speed up those searches.

rdar://111235115
2023-06-27 14:15:15 -04:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Dario Rexin
fc6834daf6 [IRGen+Runtime] Add getEnumTag for layout strings on simple single payload enums (#66941) 2023-06-26 19:32:51 -07:00
Dario Rexin
253d8fbf33 [IRGen+Runtime] Add getEnumTag for layout strings on generic single payload enum (#66911) 2023-06-23 20:43:28 -07:00
Dario Rexin
270089f297 [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset (#66899)
* [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset

getEnumTag impl for layout strings of fixed sized enums that use a function to fetch the enum tag

* Fix potential UB in IRGen
2023-06-23 18:10:55 -07:00
Alastair Houghton
e5ece81cc9 [Freestanding] Remove uses of stat() and dlsym().
We shouldn't be using stat() or dlsym() in the freestanding
runtime.

rdar://111214571
rdar://106555012
2023-06-23 17:05:59 +01:00
Dario Rexin
36ddb77fcd [IRGen+Runtime] Layout string getEnumTag for generic multi payload enums (#66872)
We already store all necessary information to extract the tag in the layout string, so we should utilize it for the getEnumTag witness
2023-06-22 19:07:50 -07:00
Alastair Houghton
4f4d0147ca Merge pull request #66721 from al45tair/eng/PR-110665213
[Threading][TSan] Fix TSan errors from lazy init on Linux.
2023-06-22 20:03:00 +01:00
Dario Rexin
37220ed37f [Runtime] Handle generic multi payload enums in resilient resolve (#66848)
* [Runtime] Handle generic multi payload enums in resilient resolve

* Update BytecodeLayouts.cpp

* Update BytecodeLayouts.cpp
2023-06-22 12:02:46 -07:00