Commit Graph

42 Commits

Author SHA1 Message Date
Karoy Lorentey
5bc723d703 [stdlib] Adjust lifetime declarations 2025-03-24 12:16:20 -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
6ead0d8cd6 [stdlib] Postpone generalizing Result.flatMapError 2025-03-24 12:16:13 -07:00
Karoy Lorentey
8a7fcc3bbf [stdlib] Update syntax for conditional conformances to invertable protocols 2025-03-24 12:16:02 -07:00
Karoy Lorentey
4db7b7c69d [stdlib] Note some syntactic wrinkles 2025-03-24 12:15:47 -07:00
Karoy Lorentey
b9d7206028 [stdlib] Start generalizing Result
- Allow nonescapable `Success` types
- Generalize `Sendable` conformance
- Generalize `Result.mapError`
- Generalize `Result.get()`

Do not generalize `Result.init(catching:)` or higher-order functions involving the success value: they cannot possibly work correctly yet.
2025-03-24 12:15:44 -07:00
Guillaume Lessard
a35dea18c5 [gardening] remove obsolete annotations 2024-09-19 12:56:31 -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
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
GG
739ff6f0c2 Fix typo in Result.swift 2024-04-21 21:17:22 +09: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
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
0885068325 [stdlib] Undo the generalization of Result.map & .flatMap for now
We didn’t do this for Optional’s equivalent methods yet, so it seems premature to do it for Result.
2024-03-20 18:42:07 -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
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
72fa98c4b6 [stdlib] Result: Initial support for noncopyable payloads 2024-03-18 11:03:49 -07:00
Doug Gregor
0b2cc84dbf Fix typo in mangled name for old ABI entrypoint of Result.init(catching:) 2024-01-13 10:30:15 -08:00
Doug Gregor
7d74b3ba5c [SE-0413] Adopt typed throws in Result
Make `init(catching:)` and `get()` use typed throws. The former infers
the `Failure` type from the closure provided (once full type inference
is in place) and the latter only throws errors of the `Failure` type.
2024-01-13 06:45:08 -08:00
Jager-yoo
60dc7cda12 Revise: applied trailing closure syntax to some examples
- For clearer closure style with shorthand argument names.
2022-05-12 02:58:05 +09:00
Slava Pestov
2716874f01 stdlib: Remove some redundant generic requirements 2022-04-04 15:52:05 -04:00
Robert Widmann
c5a751212d Merge pull request #36446 from wonhee009/Result 2021-03-21 09:58:14 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
wonhee
09971acf8c fix Result flatMapError remark 2021-03-16 14:03:18 +09:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Erik Eckstein
e7efa6cb15 stdlib: Make Result methods inlinable
The "Result" type is expected to have no overhead when used.
This requires the member functions to be inlinable.
Which is probably okay for library evolution, because it's unlikely that those methods change in an incompatible way.
2020-07-29 21:57:51 +02:00
eunjiChung
ffe471ada8 [stdlib] Add flatMap example in Result.swift 2020-06-04 21:39:12 +09:00
eunjiChung
cf9fcb975d [stdlib] Add flatMap example in Result.swift 2020-05-31 17:43:22 +09:00
Valeriy Van
9a551ab9d7 Uses default catch 2020-05-02 16:32:36 +02:00
Valeriy Van
75f30676b9 Fixes example snippet in Result.swift 2020-05-02 13:30:49 +02:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Nate Cook
f19aca6cb0 [WIP] Revise documentation for Swift 5 stdlib additions (#21333)
* Revise the Unicode scalar/Character properties
* Minor revisions to `compactMapValues` docs.
* Add documentation for AdditiveArithmetic, revise Numeric
* Apply minor style updates to count(where:).
* Revise string interpolation docs.

- Convert table of interpolation examples to a list of examples. Tables
aren't supported by Swift markup, so this wouldn't render properly in
Xcode or on the web.
- Add a description of what a user must implement in a custom
string interpolation type to get the behavior they want.

* Revise isMultiple(of:) docs.

- In particular, add emphasis to mathematical symbols and equations to
match how we document such things elsewhere.
- I'm using asterisks for single symbols, and underscores for equations
because it's easier to read in-source when you don't have to escape
multiplication within emphasis.

* Add some abstracts to the SIMD vector types.

- Adds a dictionary of spelled out numbers. Only numbers < 10
  should be spelled out according to editorial.
- Adds abstracts to some of the basic members.
- Includes parameter descriptions for the xyzw properties and inits,
but not for the unlabeled initializers. Combined with the protocol
extension method abstracts, this should complete coverage of the concrete
types.
2019-01-03 18:19:20 -06:00
Nate Cook
2bb0b5c842 Revise some documentation comments. 2018-12-10 14:31:28 -06:00
Jon Shier
c739498c9b Remove usage lines from docs. 2018-12-09 19:20:49 -05:00
Jon Shier
e4a700c32d Update inline documentation. 2018-12-09 19:08:41 -05:00
Jon Shier
2bc4cbbfdd Update for revised proposal. 2018-12-05 23:17:35 -05:00
Jon Shier
7fb5905f5f Updates for review comments. 2018-12-03 21:52:21 -05:00
Jon Shier
33dcfc462f Add update Result type to standard library. 2018-12-02 22:15:02 -05:00