Commit Graph

296 Commits

Author SHA1 Message Date
Kuba Mracek
f036837f5d Prefix all EFFECT() values with RuntimeEffect:: in RuntimeFunctions.def 2025-03-21 13:28:56 -07:00
Kuba Mracek
71a5e397e4 [embedded][Concurrency] Fix missing swift_deletedAsyncMethodError 2025-03-01 06:48:39 -08:00
Nate Chandler
dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Saleem Abdulrasool
2733879c62 Runtime: correct homing module for swift_coroFrameAlloc
This function is part of the Swift standard library, not the *C*
standard library. Correct the library name for the module to ensure that
it is properly exported.
2025-02-11 15:06:22 -08:00
Rashmi Mudduluru
f60394db46 [SUA][Runtime] Define swift_coroFrameAlloc function that allocates typed memory (#79200)
[SUA][Runtime] Define `swift_coroFrameAlloc` function that allocates typed memory

Define `swift_coroFrameAlloc` that allocates typed memory if SWIFT_STDLIB_HAS_MALLOC_TYPE is defined.
This function will be used by IRGen to emit typed memory allocations for property accessors.

rdar://141235539
2025-02-11 09:57:08 -08:00
Dario Rexin
923cccf1ea [Runtime] Add specialized CVW entry points for multi payload enums
rdar://143852239

Adding these specialized entry points reduces the overhead of the witness functions by removing the first indirection.
2025-01-30 14:44:49 -08:00
Dario Rexin
e15bdc132c [Runtime] Rename CVW entry points for compatibility 2025-01-27 15:43:01 -08:00
Saleem Abdulrasool
ec70054c93 IRGen: further generalise runtime function generation
This adjusts the runtime function declaration handling to track the
owning module for the well known functions. This allows us to ensure
that we are able to properly identify if the symbol should be imported
or not when building the shared libraries. This will require a
subsequent tweak to allow for checking for static library linkage to
ensure that we do not mark the symbol as DLLImport when doing static
linking.
2025-01-15 13:54:34 -08:00
Joe Groff
a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Kuba (Brecka) Mracek
341d6305ff Merge pull request #76767 from kubamracek/embedded-concurrency-task-groups
[Concurrency] Enable TaskGroup/DiscardingTaskGroup in Embedded Swift
2024-10-03 19:29:54 -07:00
Kuba Mracek
a2dcb6045c [embedded] Introduce a new swift_taskGroup_initializeWithOptions runtime entrypoint 2024-10-01 14:56:38 -07:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Alejandro Alonso
f2f82a7de6 Add initRawStructMetadata2 for safety 2024-09-04 15:13:51 -07:00
Alejandro Alonso
22349bcfb9 Use intptr_t instead of ssize_t and more test fixes 2024-09-04 15:13:49 -07:00
Alejandro Alonso
4f07c060b7 Future proof the initRawStructMetadata entrypoint 2024-09-04 15:13:46 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Mykola Pokhylets
9a0df5bcbf Don't add swift_retainCount() to RuntimeFunctions.def, but explicitly link it in linkEmbeddedRuntimeFromStdlib() 2024-08-21 14:53:09 +02:00
Mykola Pokhylets
0412597731 Added swift_retainCount to EmbeddedRuntime.swift
Fixes test/embedded/concurrency-actors.swift
2024-08-19 23:41:33 +02:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Allan Shortlidge
e4331af916 IRGen: Introduce macCatalyst target variant version check builtins. 2024-07-23 17:00:10 -07:00
Mykola Pokhylets
ab4d338f6a Added flags to be able to control task-locals behaviour in the future 2024-07-11 13:09:08 +02:00
Mykola Pokhylets
35f0334eb6 Rename performOnExecutor into deinitOnExecutor.
It cannot be used for executing general-purpose work, because such function would need to have a different signature to pass isolated actor instance.

And being explicit about using this method only for deinit allows to use object pointer for comparison with executor identity.
2024-07-11 13:09:07 +02:00
Mykola Pokhylets
b7e23c2e2e Runtime support for isolated deinit 2024-07-11 13:09:04 +02:00
Becca Royal-Gordon
d1f14e5814 Eliminate objcImpl field offset vectors
We really don’t need ‘em; we can just adjust the direct field offsets.

The runtime entry point currently uses a weird little hack that we will refactor away shortly.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
427386feea Support resilient stored properties in objcImpl
When an @objc @implementation class requires the use of `ClassMetadataStrategy::Update` because some of its stored properties do not have fixed sizes, we adjust the direct field offsets during class realization by emitting a custom metadata update function which calls a new entry point in the Swift runtime. That entry point adjusts field offsets like `swift_updateClassMetadata2()`, but it only assumes that the class has Objective-C metadata, not Swift metadata.

This commit introduces an alternative mechanism which does the same thing without using any Swift-only metadata. It’s a rough implementation with important limitations:

• We’re currently using the field offset vector, which means that field offsets are being emitted into @objc @implementation classes; these will be removed.
• The new Swift runtime entry point duplicates a lot of `swift_updateClassMetadata2()`’s implementation; it will be refactored into something much smaller and more compact.
• Availability bounds for this feature have not yet been implemented.

Future commits in this PR will correct these issues.
2024-04-30 12:03:44 -07:00
Erik Eckstein
1b1d5ed020 IRGen: support the @sensitive attribute
Call `swift_clearSensitive` after destroying or taking "sensitive" struct types.

Also, support calling C-functions with "sensitive" parameters or return values. In SIL, sensitive types are address-only and so are sensitive parameters/return values.
Though, (small) sensitive C-structs are passed directly to/from C-functions. We need re-abstract such parameter and return values for C-functions.
2024-04-09 12:01:11 +02:00
Erik Eckstein
ce33d47a4c stdlib: add the swift_clearSensitive runtime function 2024-04-09 12:01:10 +02:00
Alastair Houghton
25e9ca02b0 [Runtime][Test] Add a leading underscore to swift_exceptionPersonality.
The other new runtime functions appear to have a leading underscore.
It makes sense in this case because we don't expect anything to call
this directly (other than the unwinder).

rdar://120952971
2024-02-06 16:21:09 +00:00
Alastair Houghton
143a473aa4 [Runtime][IRGen] Trap C++ exceptions on *throw*, not catch.
The previous approach was effectively to catch the exception and then
run a trap instruction.  That has the unfortunate feature that we end
up with a crash at the catch site, not at the throw site, which leaves
us with very little information about which exception was thrown or
where from.

(Strictly we do have the exception pointer and could obtain exception
information, but it still won't tell us what threw it.)

Instead of that, set a personality function for Swift functions that
call potentially throwing code, and have that personality function
trap the exception during phase 1 (i.e. *before* the original stack
has been unwound).

rdar://120952971
2024-02-06 16:19:17 +00:00
Kuba Mracek
a565d1ab85 [embedded] Make embedded print() not depend on untyped throwing and allocations 2024-01-13 21:35:37 +01:00
Kuba Mracek
2c24c1216f [embedded] In -no-allocations, avoid linking allocating/deallocating runtime functions 2024-01-04 13:28:56 +01:00
Konrad `ktoso` Malawski
5546f4da7b Rename ExecutorRef to SerialExecutorRef 2023-11-01 18:39:44 +09:00
Doug Gregor
40e07cf900 [Typed throws] IR generation and runtime support for function type metadata
Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.

Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.

Introduce all of the runtime mangling/demangling support needed for
thrown error types.
2023-10-29 09:12:32 -07:00
Slava Pestov
c9c0572be5 IRGen: Weak-link references to swift_getExtendedExistentialTypeMetadata()
Fixes rdar://117530421.
2023-10-27 17:36:28 -04:00
Nate Chandler
6ccd08b4e0 Merge branch 'main' into rebranch.
Resolve conflicts introduced in
https://github.com/apple/swift/pull/67944 as follows:

```
diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def
index 3c973b5884b..44cde707d17 100644
--- a/include/swift/Runtime/RuntimeFunctions.def
+++ b/include/swift/Runtime/RuntimeFunctions.def
@@ -2537,16 +2537,10 @@ FUNCTION(AutoDiffCreateLinearMapContextWithType,
          swift_autoDiffCreateLinearMapContextWithType, SwiftCC,
          DifferentiationAvailability,
          RETURNS(RefCountedPtrTy),
-<<<<<<< HEAD
-         ARGS(SizeTy),
+         ARGS(TypeMetadataPtrTy),
          ATTRS(NoUnwind),
          EFFECT(AutoDiff),
          MEMEFFECTS(ArgMemOnly))
-=======
-         ARGS(TypeMetadataPtrTy),
-         ATTRS(NoUnwind, ArgMemOnly),
-         EFFECT(AutoDiff))
->>>>>>> public-github/main

 // void *swift_autoDiffProjectTopLevelSubcontext(AutoDiffLinearMapContext *);
 FUNCTION(AutoDiffProjectTopLevelSubcontext,
@@ -2563,16 +2557,10 @@ FUNCTION(AutoDiffAllocateSubcontextWithType,
          swift_autoDiffAllocateSubcontextWithType, SwiftCC,
          DifferentiationAvailability,
          RETURNS(Int8PtrTy),
-<<<<<<< HEAD
-         ARGS(RefCountedPtrTy, SizeTy),
+         ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
          ATTRS(NoUnwind),
          EFFECT(AutoDiff),
          MEMEFFECTS(ArgMemOnly))
-=======
-         ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
-         ATTRS(NoUnwind, ArgMemOnly),
-         EFFECT(AutoDiff))
->>>>>>> public-github/main
```
2023-08-24 16:24:32 -07:00
Kshitij Jain
d5a3e2e630 [AutoDiff] Fixes memory leaks in autodiff linear map context allocation builtins (#67944)
When the differentiating a function containing loops, we allocate a linear map context object on the heap. This context object may store non-trivial objects, such as closures, that need to be released explicitly. Fix the autodiff linear map context allocation builtins to correctly release such objects and not just free the memory they occupy.
2023-08-24 13:57:10 -07:00
Evan Wilde
8662d9a99e Add memeffects to InitRawStructMetadata
This patch adds the missing memory effects to InitRawStructMetadata to
keep rebranch building.
2023-08-16 13:24:43 -07:00
swift-ci
c5f45eb8e3 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 07:18:10 -07:00
Alejandro Alonso
44198d16a4 Merge pull request #67611 from Azoy/raw-types-are-cool!
[WIP] Implement dependent layouts for raw types
2023-08-16 06:55:42 -07:00
Alejandro Alonso
c20ab10cef Use an i32 argument instead of size
more int32

zzz
2023-08-15 19:49:44 -07:00
Ben Barham
249f2d030a [rebranch] Correct read only argument memory and apply in getRuntimeFn
`ReadOnly, ArgMemOnly` previously meant `can only read argument memory`.
But with the rebranch changes, this became `(can only read *all* memory)
and (can read or write argument memory)`. Use `ArgMemReadOnly` for this
instead.

To expand on this, these attributes (prior to memory effects) used to be
split into two. There was the *kind* of access, eg.
```
readnone
readonly
writeonly
```
and the accessed *location*, eg.
```
argmemonly
inaccessiblememonly
inaccessiblemem_or_argmemonly
```

So `RuntimeFunctions.def` would use `ReadOnly, ArgMemOnly` to mean `can
only read argument memory`.

In the previous rebranch commits, this was changed such that `ReadOnly`
mapped to `MemoryEffectsBase::readOnly()` and `ArgMemOnly` to
`MemoryEffectsBase::argMemOnly()`.

And there lies the issue -
  - `MemoryEffectsBase::readOnly()` == `MemoryEffectsBase(Ref)` ie. all
    locations can only read
  - `MemoryEffectsBase::argMemOnly()` == `MemoryEffectsBase(ArgMem,
    ModRef)`, ie. can only access argument memory

But then OR'ing those together this would become:
```
ArgMem: ModRef, InaccessibleMem: Ref, Other: Ref
```
rather than the previously intended:
```
ArgMem: Ref, InaccessibleMem: NoModRef, Other: NoModRef
```
2023-08-10 22:03:50 -07:00
Ben Barham
6c43018b56 Merge pull request #67661 from bnbarham/fix-mem-effects
[rebranch] Finish off memory effects change
2023-08-02 09:28:12 -07:00
Ben Barham
f70e168616 [rebranch] Rename NO_MEMEFFECTS to UNKNOWN_MEMEFFECTS
`NO_MEMEFFECTS` is quite similar to "none", which isn't the same as
unknown in this context. Rename to `UNKNOWN_MEMEFFECTS` for clarity.
2023-08-02 09:26:09 -07:00
swift-ci
4427f22c22 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-01 22:57:48 -07:00
Konrad `ktoso` Malawski
95920b2570 [Concurrency] Fix init task group with flags availability
resolves rdar://112469076
2023-08-02 12:02:27 +09:00
Ben Barham
1d3b5f40a0 [rebranch] Finish off memory effects change
`ReadOnly`/`ArgMemOnly` were mostly moved over, but a few were missed.
Update them all. Also default to `unknown` for no memory effects rather
than none (ie. we should be conservative).
2023-08-01 15:29:40 -07:00
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
Evan Wilde
874299d5fa Move to llvm::MemoryEffects
The memory effects are no longer represented as raw attributes, but as
its own type. This patch migrates IRGen over to using the new unified
memory effect type.
2023-07-26 14:39:07 -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