Commit Graph

96 Commits

Author SHA1 Message Date
Jonathan Grynspan
276706eceb Don't abort on Linux if withLockIfAvailable() is called recursively. (#85448)
On all platforms except Linux, calling `withLockIfAvailable()`
recursively just returns `nil`. However, our Linux implementation
chooses to abort the process instead. We don't need this
inconsistent/destructive behaviour and can just return `nil` as we do
elsewhere.
2025-11-11 23:34:12 -08:00
Alejandro Alonso
6c2f04d154 Merge pull request #84367 from valeriyvan/representation
Fix doc comment to make it match code
2025-10-28 16:46:25 -07:00
Valeriy Van
0826d47a8b Fix bug in internal func _tryLock in OpenBSDImpl.swift (#84619)
`pthread_mutex_trylock` return `0` on success.

```
NAME
     pthread_mutex_trylock – attempt to lock a mutex without blocking

SYNOPSIS
     #include <pthread.h>

     int
     pthread_mutex_trylock(pthread_mutex_t *mutex);

DESCRIPTION
     The pthread_mutex_trylock() function locks mutex.  If the mutex is already locked,
     pthread_mutex_trylock() will not block waiting for the mutex, but will return an error
     condition.

RETURN VALUES
     If successful, pthread_mutex_trylock() will return zero, otherwise an error number will
     be returned to indicate the error.

ERRORS
     The pthread_mutex_trylock() function will fail if:

     [EINVAL]           The value specified by mutex is invalid.

     [EBUSY]            Mutex is already locked.
```
2025-10-29 00:50:47 +05:30
Eric Miotto
e798e9c3cc CMake: allow to specify a SDK when building a triple for Embedded Swift (#84817)
To achieve this, add a new cache variable
`SWIFT_EMBEDDED_STDLIB_SDKS_FOR_TARGET_TRIPLES` to be set like in the
following examples.
    
```
-DSWIFT_EMBEDDED_STDLIB_SDKS_FOR_TARGET_TRIPLES=aarch64-vendor-os@/usr/local/aarch64-vendor-os-sdk;aaarch-vendor-anotheros@/opt/aarch64-vendor-anotheros-sdk
```
    
We chose to use another setting instead of e.g. folding this into
`SWIFT_EMBEDDED_STDLIB_EXTRA_TARGET_TRIPLES` so it is clear this is opt
in and it does not regress existing configurations that set the SDK
directly (like it's the case for the WASM stdlib).

Addresses rdar://162368529
2025-10-15 06:37:54 -07:00
Alejandro Alonso
65ef99c82d Merge pull request #84616 from valeriyvan/AtomicRepresentable
Fix typo in AtomicRepresentable.swift
2025-10-01 15:48:37 -07:00
Alejandro Alonso
ae848b1d92 Merge pull request #84615 from valeriyvan/AtomicBool
Fix typo in AtomicBool.swift
2025-10-01 15:48:22 -07:00
Valeriy Van
5fc6e5494c Fix typo in AtomicRepresentable.swift 2025-10-01 18:07:58 +02:00
Valeriy Van
82ec38efa7 Fix typo in AtomicBool.swift 2025-10-01 18:05:45 +02:00
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Valeriy Van
21837beb0b Fix doc comment to make it match code 2025-09-18 11:12:37 +02:00
Alejandro Alonso
19b8bed884 Change the builtin used to get the address for Atomic 2025-07-29 09:33:44 -07:00
Alejandro Alonso
12a4415f28 Merge pull request #82392 from 3405691582/openbsd_mutex_pthread
Use libpthread primitives for OpenBSD mutexes.
2025-07-22 12:48:11 -07:00
Allan Shortlidge
008efc432f stdlib: Fix missing unsafe operators in more places.
Add `unsafe` where it is still missing. I missed these in previous passes due
to conditional compilation.
2025-06-22 18:46:57 -07:00
3405691582
3bb369cd91 Use libpthread primitives for OpenBSD mutexes.
There has been some discussion as to whether this is the right approach,
centered around internal pointers in the underlying mutex structure.
After much thought, let's commit this for now. The argument:

* While it is true that OpenBSD has futex(2) and in fact is used in
  the underlying implementations in Dispatch. I'm not confident right now
  creating robust locking primitives by hand from futexes.
  It would be ideal to just delegate all of this to Dispatch, but
  Dispatch doesn't expose a ready-use API for mutexes. Cobbling one
  together might be possible, but that would take some time and finesse.

* While recent versions of C and C++ have language support for mutexes,
  they are implemented in many cases by libpthread anyway, so there
  is nothing inherently gained right now by not using the pthread API
  other than portability.

* While the concern for internal pointers for the pthread API is
  important, the OpenBSD is mitigated by the fact that pthread_mutex_t is
  pointer-valued on the platform. The concern that this might not always
  be the case is mitigated by the fact that this commit does not attempt
  to use the pthread implementation as a catch-all for all platforms.

* The alternative is to use MutexUnavailable, but given Foundation has
  some dependencies on Mutex, this may cause problems elsewhere
  throughout the port.
2025-06-21 10:26:39 -04:00
(null)
d6811260a9 Merge commit '665515c781999a81094bbe4f8302a7cb1a6a6b39' into mchiu/freebsd 2025-06-17 15:12:23 -04:00
Ian Anderson
8bbee17b88 [embedded][overlay] _Builtin_float and Synchronization cannot be imported in embedded Swift mode
The _Builtin_float and Synchronization modules are getting the SDK_NAME encoded in their embedded modules, preventing them from being used outside of macOS in embedded mode.
2025-06-08 13:53:23 -07:00
Alastair Houghton
d5ed335339 Merge pull request #81440 from al45tair/currentos-availability
[Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
2025-06-03 15:01:22 +01:00
michael-yuji
8738e722bd Merge branch 'main' into mchiu/freebsd 2025-05-28 14:44:11 -07:00
Ian Anderson
15345ef2d5 [CMake][Darwin] Remove support for building the SDK overlays on Apple platforms
The SDK overlays have been provided in the Apple SDKs for many years, and the interface and implementation has diverged in more recent years such that trying to build the Swift version no longer works. Remove all of the dead code.

rdar://151889154
2025-05-23 23:38:08 -07:00
michael-yuji
9a948a9c3b Merge branch 'main' into mchiu/freebsd 2025-05-21 16:29:16 -07:00
Karoy Lorentey
02adf95cfb Merge pull request #78799 from lorentey/note-cas-loops
[doc] Atomic.add, .subtract: Add note on atomic codegen
2025-05-16 19:05:10 -07:00
Alastair Houghton
28f96e64ab [Concurrency][Stdlib] Add SwiftStdlibCurrentOS availability, use it.
If you use SwiftStdlibCurrentOS availability, you will be able to
use new types and functions from within the implementation. This
works by, when appropriate, building with the CurrentOS availability
set to the current deployment target.

rdar://150944675
2025-05-12 12:07:24 +01:00
Eric Miotto
8c7e8550aa CMake: add explicit dependency to _Builtin_float to targets...
... that would import that as a result of importing Darwin from the SDK.

Amend my previous change to Differentiation and Distributed in this
sense.

Addresses rdar://150400049
2025-05-05 10:39:14 -07:00
Eric Miotto
231a9d989d Add _Builtin_float dependency to Distributed and Synchronization
This will avoid errors in CI when the latter ones are scheduled before
the former.

Addresses rdar://149558141
2025-04-28 09:37:07 -07:00
Doug Gregor
fe6856726e [Strict memory safety] Remove now-extraneous "unsafe" from the standard libraries
Now that we aren't propagating "unsafe" to nested types, remove
unnecessary "unsafe" keywords from the standard library.
2025-04-19 08:13:05 -07:00
Alejandro Alonso
c384db5b91 Merge pull request #80658 from Azoy/public-cell
[stdlib] Make _Cell public
2025-04-14 12:07:46 -07:00
Max Desiatov
99a4b887f9 NFC: fix comment in WasmImpl.swift (#80760)
Wasm is not an acronym, thus it's not uppercased [per the spec](https://webassembly.github.io/spec/core/intro/introduction.html#wasm).
2025-04-11 12:30:01 -07:00
Alejandro Alonso
fafdc8663b Make _Cell public 2025-04-08 16:07:54 -07:00
Kuba (Brecka) Mracek
a1cdd336f0 Merge pull request #80420 from kubamracek/embedded-drop-mach-apple
[embedded] Stop using -D__APPLE__ and -D__MACH__
2025-04-01 06:25:44 -07:00
Allan Shortlidge
3a574c0e6f stdlib: Address StrictMemorySafety warnings in Concurrency related code. 2025-03-31 16:45:08 -07:00
Kuba Mracek
6d71f45101 [embedded] Stop using -D__APPLE__ and -D__MACH__ 2025-03-31 15:07:11 -07:00
Michael Chiu
0c47c45303 Adding FreeBSD support
This commit adds required conditional compilation blocks to enable bulding on
FreeBSD (tested on x86_64 FreeBSD 14.1-RELEASE-p6). Also implements FreeBSD
synchronization shims using `_umtx_op(2)`
2025-03-14 02:15:15 -04:00
Doug Gregor
53f14688a6 Update strict memory safety annotations for Synchronization module 2025-03-10 15:42:32 -07:00
Doug Gregor
1efb994375 Enable strict memory safety in the Synchronization module 2025-02-26 14:28:28 -08:00
Ben Rimmington
4bb3cf1496 [stdlib] Update WordPair: Comparable conformance (#79606) 2025-02-25 10:17:05 -08:00
Alejandro Alonso
d2309d264d Fix tests 2025-01-28 12:50:51 -08:00
Alejandro Alonso
9af4a76b52 Use tuple comparison 2025-01-23 15:55:19 -08:00
Alejandro Alonso
8500d0cba1 Less than is a static function.. 2025-01-23 13:09:47 -08:00
Alejandro Alonso
22d5acd207 Fix logic around comparison 2025-01-23 11:55:21 -08:00
Alejandro Alonso
d5b131a436 Add Comparable conformance to WordPair 2025-01-23 10:08:52 -08:00
Karoy Lorentey
d52ed4c602 [doc] Atomic.add, .subtract: Add note on codegen 2025-01-21 15:58:32 -08:00
Meghana Gupta
20eff53585 Revert "Make Atomic.deinit @_transparent"
This reverts commit dd037f896f.

@_transparent on deinit was diagnosed as an error in older compilers

Making Atomic.deinit @_transparent will break compiling newer sdk with older compilers

Fixes rdar://139194948
2024-11-05 14:58:04 -08:00
Meghana Gupta
dd037f896f Make Atomic.deinit @_transparent 2024-10-31 13:42:34 -07:00
Meghana Gupta
02a58738a0 Remove -enable-ossa-module for Synchronization and Distributed
These modules import Darwin which is not in ossa. -enable-ossa-modules
results in a one-time recompilation of dependencies when they are not in ossa.
This is not compatible with Explicit Build Modules when the original invocation
did not have -enable-ossa-modules.
2024-10-31 10:55:35 -07:00
Doug Gregor
8378562e12 Adopt @unsafe throughout the standard library
Annotate all of the `Unsafe*` types and `unsafe` functions in the standard
library (including concurrency, synchronization, etc.) as `@unsafe`. Add a
few tests to ensure that we detect uses of these types in clients that
have disabled unsafe code.
2024-08-19 14:33:09 -07:00
Evan Wilde
cae88d3344 Fix add_swift_target_library for the static SDK
add_swift_target_library was missing pieces for passing sources and
flags to the static SDK build. As a result, the static SDK was missing
pieces (specifically Mutex).

Also adding the Musl import to the Linux Mutex implementation.
2024-08-13 15:59:31 -07:00
Doug Gregor
ac0f574fdb Merge pull request #75127 from carlos4242/embedded-avr-cross-compile-stdlib
[AVR] standard library support for AVR
2024-07-17 22:17:42 -07:00
Alejandro Alonso
24a46c422b Merge pull request #74946 from Azoy/mutex-sending-inout
[stdlib] Adopt inout sending for Mutex
2024-07-17 10:56:57 -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
Allan Shortlidge
0ba007661a AST: Promote BuiltinAddressOfRawLayout to baseline. 2024-07-09 14:29:30 -07:00