Commit Graph

68 Commits

Author SHA1 Message Date
Arnold Schwaighofer
02d7fe5110 Document the difference of embedded swift's swift_allocBox 2025-11-17 12:48:48 -08:00
Arnold Schwaighofer
62ac48a17e Complete support for outline existential storage
... or so I believe
2025-11-17 12:48:45 -08:00
Arnold Schwaighofer
eda5eadfd4 Start outline storage support: Add swift_allocBox/deallocBox
Code using the outline heap storage path will crash and burn because
support is incomplete. But at least inline storage existential
inhabitants should compile and run.
2025-11-17 12:46:35 -08:00
Doug Gregor
9ea8671c3f Use @c instead of @_cdecl in the Embedded Swift runtime
This change moves us toward the official feature, and eliminates the
extra level of "thunk" that was implied by `@_cdecl`. Amusingly, this
trips up the LLVM-level ARC optimizations, because we are trying to
perform ARC optimizations within the retain/release runtime functions.
Teach those optimization passes to leave swift_retainN et al alone.
2025-11-13 18:39:10 -08:00
Valeriy Van
c53d71bb2a Fix typos 2025-10-04 12:53:44 +02:00
Tim Kientzle
ff50f8f2be Fill in two missing functions for Embedded Swift
`swift_coroFrameAlloc` is needed by `_read`/`_modify` accessors

`swift_deallocUninitializedObject` which I believe is needed for failable class initializers

Resolves rdar://157028375
Resolves rdar://157276375
2025-08-29 16:57:08 -07:00
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +01:00
Allan Shortlidge
f8fb99320a Embedded: Suppress spurious unused result warnings.
The results of `swift_retain(object:)` and `swift_bridgeObjectRetain(object:)`
should be discardable since it's typcial to not need the pointer returned from
these calls. Suppresses unused result warnings that were generated previously.
2025-05-18 10:40:13 -07:00
Doug Gregor
050a514588 [Strict memory safety] Update standard library for unsafe treated as a call effect 2025-04-25 21:54:23 -07:00
Kuba Mracek
c0ea02f86d [embedded] Add swift_allocEmptyBox to the embedded runtime 2025-04-21 15:47:34 -07:00
Doug Gregor
f668feaf64 [Standard library] Additional strict-memory-safety annotations 2025-03-10 15:42:05 -07:00
Kuba Mracek
01d7e231c3 [embedded] Allow string-interpolating fatalError in Embedded Swift 2025-02-28 08:53:09 -08:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Kuba Mracek
f4c69e1ca0 [embedded] Also allow nil in swift_isEscapingClosureAtFileLocation to match the C++ runtime 2025-01-27 10:20:23 -08:00
Kuba Mracek
8e3ee38324 [embedded] Support withoutActuallyEscaping in Embedded Swift 2025-01-25 15:24:20 -08:00
Kuba Mracek
db94dc7d36 [Concurrency] Fix memory leak around mismatched refcounting in Concurrency 2024-10-31 21:43:02 -07:00
Kuba Mracek
0048c1c624 [embedded] Document the details of the Embedded Swift's refcounting scheme 2024-10-21 08:56:22 -07:00
Kuba Mracek
8666aef39f [embedded] Fix a memory leak caused by incorrect refcounting logic around doNotFreeBit 2024-10-18 23:19:40 -07:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
Kuba (Brecka) Mracek
d3c5149714 Merge pull request #76658 from kubamracek/embedded-managed-buffer
[embedded] Add support for ManagedBuffer to Embedded Swift
2024-09-25 02:54:55 -07:00
Kuba Mracek
c7a5569c4f [embedded] Add support for ManagedBuffer to Embedded Swift
This makes ManagedBuffer available and usable in Embedded Swift, by:

- Removing an internal consistency check from ManagedBuffer that relies on metatypes.
- Making the .create() API transparent (to hoist the metatype to the callee).
- Adding a AllocRefDynamicInst simplification to convert `alloc_ref_dynamic` to `alloc_ref`, which removes a metatype use.
- Adding tests for the above.
2024-09-23 13:32:50 -07:00
Konrad `ktoso` Malawski
7d1ce789ad Revert "Revert "Isolated synchronous deinit"" 2024-09-17 17:35:38 +09:00
Kuba (Brecka) Mracek
142df19324 Merge pull request #76231 from kubamracek/embedded-deinit-release
[embedded] Handle retain/retain ops inside deinit in Embedded Swift's swift_release
2024-09-16 16:13:08 -07:00
Kuba Mracek
b4431db2c5 [embedded] Add a more detailed explaining comment to swift_release_n_ 2024-09-16 10:37:40 -07:00
Alex Hoppen
c5aa49ba64 Revert "Isolated synchronous deinit" 2024-09-03 18:11:26 -07:00
Kuba Mracek
249f7e6073 [embedded] Handle retain/retain ops inside deinit in Embedded Swift's swift_release 2024-09-03 14:38:03 -07:00
Mykola Pokhylets
0412597731 Added swift_retainCount to EmbeddedRuntime.swift
Fixes test/embedded/concurrency-actors.swift
2024-08-19 23:41:33 +02:00
Philippe Hausler
5b20f7d10f [Embedded] Correct the signature of free to avoid using Builtin module for potential client implementations (#75496) 2024-07-30 11:59:24 -07:00
Carl Peto
3689427834 [AVR] standard library support for AVR
- when compiling embedded cross compile target standard libraries, include AVR
- add 16-bit pointer as a conditional compilation condition and get the void pointer size right for gyb sources
- attempt to fix clang importer not importing __swift_intptr_t correctly on 16 bit platforms
- changed the unit test target to avr-none-none-elf to match the cmake build

[AVR] got the standard library compiling in a somewhat restricted form:

General
- updated the Embedded Runtime
- tweaked CTypes.swift to fix clang import on 16 bit platforms

Strings
- as discussed in https://forums.swift.org/t/stringguts-stringobject-internals-how-to-layout-on-16-bit-platforms/73130, I went for just using the same basic layout in 16 bit as 32 bit but with 16 bit pointers/ints... the conversation is ongoing, I think something more efficient is possible but at least this compiles and will probably work (inefficiently)

Unicode
- the huge arrays of unicode stuff in UnicodeStubs would not compile, so I skipped it for AVR for now.

Synchronization
- disabled building the Synchronization library on AVR for now. It's arguable if it adds value on this platform anyway.
2024-07-16 12:28:27 +01:00
Erik Eckstein
13ecb51612 embedded: add swift_dynamicCastClass runtime function
To enable dynamic class casts

rdar://129672994
2024-06-12 18:23:38 +02:00
Kuba (Brecka) Mracek
545c2434c0 Merge pull request #70446 from kubamracek/embedded-string
[embedded] Port Swift.String to embedded Swift
2024-05-26 12:59:01 -07:00
Erik Eckstein
162139364e IRGen: support read-only statically initialized arrays in embedded swift
Arrays buffers need to be initialized with a (minimal) metatype and with an immortal reference count.
2024-05-21 18:04:10 +02:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
Kuba Mracek
757e4e56b0 [embedded] In -assert-config Debug, print errors in assertions, preconditions, fatalErrors 2024-04-09 11:36:21 -07:00
Erik Eckstein
ce33d47a4c stdlib: add the swift_clearSensitive runtime function 2024-04-09 12:01:10 +02:00
Kuba Mracek
37d9be636a [embedded] Handle NULL IVarDestroyers, expand test 2024-03-26 21:14:21 -07:00
Kuba Mracek
b8bd832fba [embedded] Add IVarDestroyers into class metadata, add support for throws in initializers 2024-03-26 20:52:17 -07:00
Kuba Mracek
8f247e2d36 [embedded] Add swift_isUniquelyReferenced_native into the embedded runtime 2024-03-25 11:51:01 -07:00
Doug Gregor
3fa07a0e7a Implement swift_willThrow variant for typed throws.
`swift_willThrow` is called with an error right before it is thrown.
This existing entrypoint requires an already-boxed error existential;
with typed errors, we don't have the error existential on hand, so we
would need to allocate the box to throw a typed error. That's not okay.

Introduce a new `swift_willThrowTypedImpl` entry point into the runtime
that will first check for the presence of an error handler and, if one
is present, box the error to provide to the error handler. This
maintains the no-allocations path for typed errors while still
allowing existing error handlers to work.

This new entrypoint isn't available on older Swift runtimes, so create
a back-deployable shim called by the compiler. On new-enough platforms,
this will call through to `swift_willThrowTypedImpl`. On older
platforms, we drop the error and don't call the registered will-throw
handler at all. This is a compromise that avoids boxing when throwing
typed errors, at the cost of a slightly different experience for this
new feature on older runtimes.

Fixes rdar://119828459.
2024-02-05 15:06:55 -08:00
Kuba Mracek
6383d05ea1 [embedded] Fix calling convention on embedded runtime APIs (switch @_silgen_name for @_cdecl) 2024-01-29 15:37:46 -08:00
Kuba Mracek
2c30b0a0e2 [embedded] Resolve ptrauth crashes by signing HeapObjects's isa pointers in embedded Swift 2024-01-22 16:45:07 -08:00
Kuba Mracek
943c7c2ee5 [embedded] Drop 'public' from forward declaration of arc4random_buf 2023-12-20 14:04:35 +01:00
Kuba Mracek
d3849fe843 [embedded] Use @_extern(c) instead of @_silgen_name on arc4random_buf 2023-12-13 11:28:17 -08:00
Kuba Mracek
2f0883ab24 [embedded] Add Set to the embedded stdlib 2023-12-13 11:28:17 -08:00
Erik Eckstein
c8db45907f EmbeddedRuntime: add swift_willThrow 2023-11-08 16:23:28 +01:00
Kuba Mracek
95d5d71d51 [embedded] Add asserts on predicate value into swift_once 2023-10-30 09:10:30 -07:00
Kuba Mracek
b057417e52 [embedded] Make embedded swift_once thread-safe 2023-10-29 20:33:43 -07:00
Kuba Mracek
6900efe42c [embedded] Fix an LLVMARCOpts crash by avoiding direct calls to swift_retain/swift_release 2023-10-18 14:44:18 -07:00
Kuba Mracek
c8a5ac0142 [embedded] Use Builtin.RawPointer as the argument type on swift_release_n 2023-10-13 20:55:58 -07:00
Kuba Mracek
e9961323d8 [embedded] Avoid using Optional in the forward declared free() function in EmbeddedRuntime 2023-10-03 11:29:11 -07:00