Commit Graph

210 Commits

Author SHA1 Message Date
Karoy Lorentey
5bc723d703 [stdlib] Adjust lifetime declarations 2025-03-24 12:16:20 -07:00
Karoy Lorentey
192b404947 [stdlib] Work around ~Escapable breaking Optional.init syntax 2025-03-24 12:16:19 -07:00
Karoy Lorentey
b17a8d493d Generalize Optional._consumingUncheckedUnwrapped()
This is just to round things out — this internal function was sticking out from the public interfaces. No stdlib code needs this generalization yet, but I see no reason to delay it.
2025-03-24 12:16:18 -07:00
Karoy Lorentey
dc5e9f585f Add some missing @lifetime attributes
We were relying on infererred lifetimes by accident — it’s better to spell things out for now.
2025-03-24 12:16:17 -07:00
Karoy Lorentey
21169d12e8 Reinstate generalization of Optional.unsafelyUnwrapped 2025-03-24 12:16:16 -07:00
Karoy Lorentey
c2d33b4f71 [stdlib] Take out generalization of Optional.unsafelyUnwrapped for now 2025-03-24 12:16:08 -07:00
Karoy Lorentey
8a7fcc3bbf [stdlib] Update syntax for conditional conformances to invertable protocols 2025-03-24 12:16:02 -07:00
Karoy Lorentey
538f2742ef [stdlib] Roll back generalization of the nil-coalescing operator ??
We cannot currently express its proper lifetime semantics: its result’s lifetime should depend on the intersection of the lifetime of the left argument and the lifetime of the result of the right argument.

`@lifetime(optional, defaultValue.result)` is what we want, but the `.result` part is not currently expressible. (Tying the dependency on the closure argument itself may be a viable option, but we aren’t confident enough to ship it like that yet.)
2025-03-24 12:16:01 -07:00
Karoy Lorentey
b7b75aeace [stdlib] Generalize Optional.unsafelyUnwrapped 2025-03-24 12:15:56 -07:00
Karoy Lorentey
0e55d96a22 [stdlib] Generalize Optional.take(), ?? and nil comparisons 2025-03-24 12:15:52 -07:00
Karoy Lorentey
84b63956bf [stdlib] Generalize Optional’s “some” initializer 2025-03-24 12:15:51 -07:00
Karoy Lorentey
4db7b7c69d [stdlib] Note some syntactic wrinkles 2025-03-24 12:15:47 -07:00
Karoy Lorentey
a52c060924 [stdlib] dependsOn → @lifetime 2025-03-24 12:15:46 -07:00
Karoy Lorentey
351adc7d4a [stdlib] Enable NonescapableTypes 2025-03-24 12:15:41 -07:00
Karoy Lorentey
9b322e3e8e [stdlib] Optional: Allow non-escapable wrapped types 2025-03-24 12:15:38 -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
Allan Shortlidge
b1bf693f3f stdlib: Remove #if $NoncopyableGenerics guards.
The stdlib is always built with NoncopyableGenerics enabled, so `#if
$NoncopyableGenerics` guards in non-inlinable code are superfluous.
Additionally, the stdlib's interface no longer needs to support compilers
without the feature, so the guards in inlinable code can also be removed.
2024-07-08 17:44:24 -07:00
Kuba (Brecka) Mracek
7d8a62a9a0 Merge pull request #74642 from kubamracek/embedded-fix-warnings
[embedded] Fix 3 compilation warnings in embedded stdlib
2024-06-22 06:54:13 -07:00
Kuba Mracek
1d9cebeb22 [embedded] Fix 3 compilation warnings in embedded stdlib 2024-06-21 21:28:33 -07:00
Karoy Lorentey
470a04cca3 Merge pull request #73807 from lorentey/stdlib-noncopyable-additions
[stdlib] API additions for basic noncopyable primitives
2024-06-20 13:32:23 -07:00
Kavon Farvardin
ec4a125f3e NCGenerics: ext's might not infer invertible req's
If the extension adds conformance to an invertible protocol, it's
confusing for people to also infer conditional requirements on the
generic parameters for those invertible protocols. This came up in the
review of SE-427.
2024-06-12 14:44:22 -07:00
Karoy Lorentey
ab51f1630c [stdlib] API additions for basic noncopyable primitives
- Add `exchange(_:with:)`
- Add `Optional.take()`
- Add `Unsafe[Mutable]BufferPointer.extracting(_:)`
- Finish generalizing `withExtendedLifetime`
- Radically simplify the implementation of `swap(_:_:)`
2024-06-07 14:09:53 -07: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
Allan Shortlidge
ca70312879 stdlib: Fix a borrowing switch condfail.
Resolves rdar://128249510
2024-05-16 23:35:25 -07:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
nate-chandler
bcd08c0c9a Merge pull request #73235 from nate-chandler/bitwise-copyable/enable
[BitwiseCopyable] Promote to feature.
2024-05-04 10:16:40 -07:00
Allan Shortlidge
250758335c Merge pull request #73306 from tshortli/the-condfails-never-end
stdlib: Fix more typed throws and non-copyable generics condfails
2024-04-27 16:07:28 -07:00
Allan Shortlidge
7fc2179c31 stdlib: Fix more typed throws and non-copyable generics condfails.
There were two categories of problem for older compilers that consume the
stdlib `.swiftinterface`:

- The `case .some(borrowing x)` syntax isn't accepted; use `_borrowing`
- Various functions that addopted `~Copyable` generic constraints conflict with
  the `@usableFromInline` ABI stubs that were left in to preserve compatibility
  when the functions are printed with `~Copyable` constraints stripped. The stubs
  need to have different names to get out of the way.

Resolves rdar://127132742
2024-04-26 16:37:09 -07:00
Karoy Lorentey
775aab0c8e [stdlib] Optional.map, .flatMap: Remove @_disfavoredOverload
We don’t need this to worka round the known source compat issue, and it is triggering “expression too complex” errors, causing harm.

rdar://127015095
2024-04-26 11:58:09 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00
Karoy Lorentey
c6bc1965f6 [stdlib] Optional, Result: Try adding @_disfavoredOverload to work around a shadowing issue
The new ~Copyable generalizations have changed the function signature enough that alternative definitions of `map`/`flatMap` in existing code that used to be considered to shadow the originals no longer do so. This leads to use sites becoming ambiguous — a source break.

While we consider approaches to resolve this on the compiler side, let’s try slapping a `@_disfavoredOverload` on these and see if that helps.
2024-04-16 17:13:56 -07:00
Karoy Lorentey
fab25dc984 [stdlib] Optional, Result: Update borrowing switch syntax (_borrowing → borrowing) 2024-04-16 01:15:33 -07:00
Karoy Lorentey
cafc99369b [stdlib] Round out ~Copyable generalizations in stdlib primitives
- `Optional.map`, `.flatMap`: Allow noncopyable results. Implement typed throws.

- `Result.map`, `.flatMap`: Allow noncopyable types for the new success.
- `Result.flatMapError`: Generalize for noncopyable Success.

- `Unsafe[Mutable][Buffer]Pointer.withMemoryRebound`: Alllow typed throws.
- `Unsafe[Mutable]BufferPointer: Generalize CustomDebugStringConvertible conformance for noncopyable `Element`s.

- `OpaquePointer.init(_: UnsafeMutablePointer)`, `.init(_: UnsafeMutablePointer?)`: Allow noncopyable pointee types.

- `ManagedBuffer.withUnsafeMutablePointerToHeader`, `.withUnsafeMutablePointerToElements`, `.withUnsafeMutablePointers`: Generalize for typed throws and noncopyable return types. Avoid `@_preInverseGenerics`.
- `ManagedBufferPointer`: Ditto.

- `withExtendedLifetime`: Use typed throws. Stop using `@_preInverseGenerics`.

rdar://117753275
2024-04-16 01:15:33 -07:00
Joe Groff
233c1675cf Merge pull request #72647 from jckarter/borrowing-switch-expr-based-ownership
Alternative noncopyable switch design based on expression kind.
2024-03-28 14:44:16 -07:00
Joe Groff
ba3494802a Alternative noncopyable switch design based on expression kind.
If an expression refers to noncopyable storage, then default to performing
a borrowing switch, where `let` bindings in patterns borrow out of the
matched value. If an expression refers to a temporary value or explicitly
uses the `consume` keyword, then perform a consuming switch, where
`let` bindings take ownership of corresponding parts of the matched value.
Allow `_borrowing` to still be used to explicitly bind a pattern variable
as a borrow, with no-implicit-copy semantics for copyable values.
2024-03-28 08:32:48 -07:00
Allan Shortlidge
37034282a1 stdlib: Adopt @_disallowFeatureSuppression(NoncopyableGenerics).
This prevents some re-declaration errors when building the standard library
from its `.swiftinterface` with older compilers.
2024-03-27 22:20:50 -07:00
Karoy Lorentey
cf1c92f461 [stdlib] Remove all new public API for now 2024-03-18 11:03:49 -07:00
Karoy Lorentey
38001ae739 [stdlib] Apply @Azoy’s remaining review notes (thanks!) 2024-03-18 11:03:49 -07:00
Karoy Lorentey
2a1f15587e [stdlib] Use hasFeature(Foo) instead of opaque $Foo syntax 2024-03-18 11:03:49 -07:00
Karoy Lorentey
776ec74dcf [stdlib] {consuming,borrowing}{Flat,}Map: adopt typed throws 2024-03-18 11:03:49 -07:00
Karoy Lorentey
71519aaf98 [stdlib] Apply minor review notes 2024-03-18 11:03:49 -07:00
Karoy Lorentey
d70f197c24 [stdlib] Update SwiftStdlibLegacyABI convention to use @available(swift, obsoleted: 1)
Using version `2` here is just weird for no reason.
2024-03-18 11:03:49 -07:00
Karoy Lorentey
5d90d81dac [stdlib] Optional: Add @_preInverseGenerics to ExpressibleByNilLiteral conformance 2024-03-18 11:03:49 -07:00
Karoy Lorentey
baa317c29a [stdlib] Optional: Adopt @_preInverseGenerics 2024-03-18 11:03:49 -07:00
Karoy Lorentey
85a6b97e7a [stdlib] Optional: Initial support for noncopyable payloads
- Enable BorrowingSwitch feature within the stdlib
- ExpressibleByNilLiteral: Add retroactive support for noncopyable conforming types
- Optional: draft an API surface for noncopyable payloads

[stdlib] Oops, the ExpressibleByNilLiteral conformance kept its implicit copyability
2024-03-18 11:03:49 -07:00
Nate Chandler
c49738eecf [BitwiseCopyable] Remove gating from protocol decl
It's harmless to have the protocol defined in the swiftinterface for
older compilers and removing the gating permits the gating to be omitted
from conformances
2024-01-19 07:25:15 -08:00
Nate Chandler
2133c94add [stdlib] Optional conforms to _BitwiseCopyable. 2024-01-15 17:08:32 -08:00
Kuba Mracek
ae2e903574 [embedded] Build an initial embedded Swift standard library
This isn't a "complete" port of the standard library for embedded Swift, but
something that should serve as a starting point for further iterations on the
stdlib.

- General CMake logic for building a library as ".swiftmodule only" (ONLY_SWIFTMODULE).
- CMake logic in stdlib/public/core/CMakeLists.txt to start building the embedded stdlib for a handful of hardcoded target triples.
- Lots of annotations throughout the standard library to make types, functions, protocols unavailable in embedded Swift (@_unavailableInEmbedded).
- Mainly this is about stdlib functionality that relies on existentials, type erasure, metatypes, reflection, string interpolations.
- We rely on function body removal of unavailable functions to eliminate the actual problematic SIL code (existentials).
- Many .swift files are not included in the compilation of embedded stdlib at all, to simplify the scope of the annotations.
- EmbeddedStubs.swift is used to stub out (as unavailable and fatalError'd) the missing functionality.
2023-09-16 12:38:46 -07:00
Alex Martini
36114194c3 Fix missing word.
Co-authored-by: Ben Rimmington <me@benrimmington.com>
2022-08-08 15:40:58 -07:00
Alex Martini
e46a285a98 Reference doesn't allow code voice in abstract.
Fixes <rdar://86212313>
2022-07-06 17:07:45 -07:00