Commit Graph

42 Commits

Author SHA1 Message Date
Nate Chandler
9de809d398 [IRGen] TypeID is 0 when typed-malloc is disabled.
Produce a value of 0 when typed-malloc is disabled to avoid spurious
materialization of type ids with more interesting values.
2025-10-30 03:59:18 -07:00
Nate Chandler
511050ed73 [NFC] IRGen: Lift this function from IGF to IGM. 2025-10-30 03:59:18 -07:00
Nate Chandler
76881b1d52 [CoroutineAccessors] Add frame de/alloc functions.
To enable ABIs which store extra info in the frame, add two new slots to
the coroutine allocator function table.  For example, a frame could have
a header containing a context pointer at a negative offset from the
address returned from `swift_coro_alloc_frame`.  The frame deallocation
function would then know to deallocate more space correspondingly.
2025-10-22 21:00:17 -07:00
nate-chandler
454160bca5 Merge pull request #84831 from nate-chandler/general-coro/20251009/1
[CoroutineAccessors] Sign de/allocation functions.
2025-10-13 20:03:09 -07:00
Nate Chandler
603dc2e0b3 [CoroutineAccessors] Sign de/allocation functions.
Allocator structs are passed in to new ABI yield-once coroutines and
contain pointers to functions to de/allocate memory.  Here, those
pointers are signed.
2025-10-10 16:32:19 -07:00
Anthony Latsis
442825d9de [rebranch] IRGen: Fix omission in hash computation after switching API
Issue introduced by 0d2d6cb8a0.
`llvm::getPointerAuthStableSipHash` produces the combined result of
the obsoleted `clang::CodeGen::computeStableStringHash` and
our `getDiscriminatorForHash`, so we no longer need to call both.
2025-04-30 21:45:46 +01:00
Anthony Latsis
0d2d6cb8a0 IRGen, LLVMPasses: Switch from obsoleted APIs to llvm::getPointerAuthStableSipHash
Per d68f8b96b1ff39cfcfcad94d5b16d28adaf6b5d0 (llvm-project).
2025-04-24 01:52:45 +01:00
Slava Pestov
e475b08011 AST: Remove AssociatedType 2025-04-03 17:35:35 -04:00
Nate Chandler
6581fec9e1 [CoroutineAccessors] PtrAuth. 2025-03-07 11:46:51 -08:00
Rashmi Mudduluru
0b8efc9f26 [SUA][IRGen] Change IRGen to emit calls to swift_coroFrameAlloc (#79384)
When TMO is enabled, change IRGen to pass the newly introduced runtime function `swift_coroFrameAlloc` (and pass an additional argument — the hash value) instead of `malloc` when it inserts calls to `coro_id_retcon_once`.
The hashValue is computed based on the  current function name (computed in `getDiscriminatorForString`)

rdar://141235957
2025-02-21 14:45:23 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
swift-ci
8a2edbc4c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-11 17:05:06 -07:00
Nate Chandler
df1c4f6b25 [CoroutineAccessors] Add new SILFnTy CoroKind.
For `modify` and `read` coroutines, produce SILFunctionType's whose
coroutineKind is ::YieldOnce2.
2024-10-11 08:25:02 -07:00
Ben Barham
8e9ac93bd3 [IRGen] Use ConstantInt for otherDiscriminator 2024-07-01 14:52:51 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
John McCall
d5142668f4 SIL and IRGen support for @isolated(any). SILGen to come. 2024-02-13 03:04:13 -05:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07: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
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
Meghana Gupta
7d169a9088 Add additional PointerAuthInfo::emit api 2023-02-07 00:18:38 -08:00
Meghana Gupta
1dac5d48d3 Support for address discriminated pointers 2023-01-27 01:56:44 -08:00
Meghana Gupta
901c279bea Add IRGen support for reads and writes to imported __ptrauth qualified field function pointers
Access to such pointers are protected by begin_access [signed]/end_access.
Generate code to auth/sign them before access.
2023-01-25 14:03:19 -08:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
swift_jenkins
31f3c479a3 Merge remote-tracking branch 'origin/main' into next 2022-04-21 14:33:57 -07:00
Josh Soref
9fa14ca215 Spelling irgen (#42470)
* spelling: abstractable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: across

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: command

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: current

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declared

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: discrimination

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: entities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: except

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inserted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interfere

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: intrinsic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: might

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: objective

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outlined

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: payload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rearchitecting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reverse

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewritable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: shareably

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specializations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: speedup

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: template

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: witness

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 14:02:03 -07:00
swift_jenkins
dd989022c6 Merge remote-tracking branch 'origin/main' into next 2022-01-31 14:40:48 -08:00
Alastair Houghton
14da34d4a9 Fix crash on systems with pointer authentication.
hashStringForType() needed updating to deal with ExistentialType.

rdar://87717024
2022-01-31 15:46:07 +00:00
swift_jenkins
770e7f1c2b Merge remote-tracking branch 'origin/main' into next 2022-01-06 18:02:41 -08:00
zoecarver
036361d1e4 [cxx-interop] Add SIL function representation cxx_method; Support extending C++ types.
There are three major changes here:
    1. The addition of "SILFunctionTypeRepresentation::CXXMethod".
    2. C++ methods are imported with their members *last*. Then the arguments are switched when emitting the IR for an application of the function.
    3. Clang decls are now marked as foreign witnesses.

These are all steps towards being able to have C++ protocol conformance.
2022-01-06 14:26:47 -08:00
Arnold Schwaighofer
2df553cc02 arm64e: Update for LLVM ptr_auth intrinsics differences
ptr_auth intrinsics are not polymorphic rather expect an int64 type.

rdar://85583820
2021-11-29 10:15:40 -08:00
Robert Widmann
1329f3cfbd [NFC] Lift getGenericEnvironment() into GenericSignature 2021-07-22 23:33:02 -07:00
Robert Widmann
a0615e9848 [NFC] Use GenericSIgnature::getGanonicalSignature Where Possible 2021-07-22 23:27:06 -07:00
Nate Chandler
d3e0e7af07 [ptrauth] Signed AsyncFunctionPointers as data.
Previously, AsyncFunctionPointer constants were signed as code.  That
was incorrect considering that these constants are in fact data.  Here,
that is fixed.

rdar://76118522
2021-04-05 18:24:41 -07:00
Doug Gregor
47b0abfda4 Remove Actor.enqueue(partialTask:) and all its magic.
The backs out of some early decisions we made about actor layout
that we don't need. Custom actors will use a different approach.

This should suffice for the remainder of rdar://70146827.
2021-03-04 22:49:10 -08:00
Nate Chandler
659c1ed88f [Async CC] Resigning AFP results in AFP.
Previously, when a FunctionPointer whose kind was AsyncFunctionPointer
was resigned, the underlying function pointer was loaded from the
AsyncFunctionPointer struct and that value was signed.  That was
incorrect: a resigned pointer to an AsyncFunctionPointer struct should
again be a pointer to an AsyncFunctionPointer struct.  Here that error
is corrected and the result of resigning is again a pointer to an
AsyncFunctionPointer struct.
2020-12-04 18:11:05 -08:00
Nate Chandler
2d21932672 [Async CC] Add constant "pointer" for async func.
An AsyncFunctionPointer, defined in Task.h, is a struct consisting of
two i32s: (1) the relative address of the async function and (2) the
size of the async context to be allocated when calling that function.

Here, such structs are emitted for every async SILFunction that is
emitted.
2020-11-12 18:20:10 -08:00
Fero
28f3e44213 Fix typo 2020-10-02 01:16:22 +02:00
Doug Gregor
34996bf9a6 [Concurrency] Give Actor enqueue(partialTask:) its own ptrauth discriminator.
For actor class's implementations of `enqueue(partialTask:)`, use a
fixed ptrauth discriminator. Paired with the fixed vtable location,
this allows one to invoke this operation on any native actor instance
without knowing the specific type.
2020-09-30 00:02:17 -07:00
Nate Chandler
2701a0809b [metadata prespecialization] Ptrauth for compared protocol conformances.
Two protocol conformance descriptors are passed to
swift_compareProtocolConformanceDecriptors from generic metadata
accessors when there is a canonical prespecialization and one of the
generic arguments has a protocol requirement.

Previously, the descriptors were incorrectly being passed without
ptrauth processing: one from the witness table in the arguments that are
passed in to the accessor and one known statically.

Here, the descriptor in the witness table is authed using the
ProtocolConformanceDescriptor schema.  Then, both descriptors are signed
using the ProtocolConformanceDescriptorsAsArguments schema.  Finally, in
the runtime function, the descriptors are authed.
2020-07-09 11:45:16 -07:00
Arnold Schwaighofer
147144baa6 SIL: Thread type expansion context through to function convention apis
This became necessary after recent function type changes that keep
substituted generic function types abstract even after substitution to
correctly handle automatic opaque result type substitution.

Instead of performing the opaque result type substitution as part of
substituting the generic args the underlying type will now be reified as
part of looking at the parameter/return types which happens as part of
the function convention apis.

rdar://62560867
2020-05-04 13:53:30 -07:00
Saleem Abdulrasool
fa46f7131c sprinkle some llvm_unreachable for MSVC (NFC)
MSVC does not realize that the switch is exhaustive and requires that
the path is explicitly marked as unreachable.  This silences the C4715
warning ("not all control paths return a value").
2020-04-24 18:59:07 -07:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00