Commit Graph

285 Commits

Author SHA1 Message Date
Kuba Mracek
a2dcb6045c [embedded] Introduce a new swift_taskGroup_initializeWithOptions runtime entrypoint 2024-10-01 14:56:38 -07: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
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
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
Dario Rexin
3524945cd4 [IRGen+Runtime] Implement getEnumTag for singleton enums in layout strings (#66985) 2023-06-28 14:25:34 -07:00
Dario Rexin
ca664141cc [IRGen+Runtime] Add support for initializeBufferWithCopyOfBuffer to layout strings (#66965) 2023-06-27 18:05:30 -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