Commit Graph

3491 Commits

Author SHA1 Message Date
Alejandro Alonso d8afabc892 Merge pull request #89553 from Azoy/revert-ref-nonescapable
Revert [stdlib] Let Ref reference nonescapable types
2026-06-03 23:08:54 -07:00
Alejandro Alonso 32846bffa8 Update RefMutableRef.swift 2026-06-03 15:26:01 -07:00
Matt Massicotte a8020e48ad Asynchronous Catching Result initializer (#88465)
- **Explanation**:

Implementation of an async catching initializer for Result as part of
https://github.com/swiftlang/swift-evolution/pull/3234

- **Scope**:

Details in proposal.

- **Issues**:

- **Original PRs**:

- **Risk**:

- **Testing**:

I've added two tests to cover some of functionality that was being
exercised for the synchronous cases. It seems sufficient to me, but I'd
like feedback on this.

- **Reviewers**:

Would love for @ktoso to have a peek before finalizing.

---------

Co-authored-by: Jamie <2119834+jamieQ@users.noreply.github.com>
Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
Co-authored-by: Ben Rimmington <me@benrimmington.com>
Co-authored-by: Konrad Malawski <ktoso@apple.com>
2026-06-01 11:48:00 -07:00
Xiaodi Wu c2ce1e4cc3 [stdlib] Restore NaN printing behavior that matches documented guarantees (#89579)
Since Swift 4.x, NaN printing behavior has drifted from version to
version. But we actually have documented guarantees about how it should
behave.

From `CustomStringConvertible`:
> If the passed instance conforms to `CustomStringConvertible`, the
`String(describing:)` initializer and the `print(_:)` function use the
instance’s custom `description` property.

From `description` on `Double` (or `Float`, etc.):
> For any NaN value, the property’s value is “nan”

As of recent versions of Swift, this is not so for stdlib floating-point
types: `print(-Float.nan)` outputs the _debug_ description instead of
the non-debug description. These two string representations are
distinguishable because `debugDescription` shows the sign (and, if
nonzero, the payload) of NaN.

---

The underlying implementation-level issue is that stdlib floating-point
types were made to conform to `TextOutputStreamable` as part of string
interpolation work for performance reasons. That implementation elected
to use debugging output, but (afaict) that decision does not seem to
have been based on a deliberate choice specifically to change the
behavior of NaN interpolation. Prior to that change, streaming and
interpolation used the non-debug description for stdlib floating-point
types (verified with Swift 4.x using SwiftFiddle).

(It seems an unstated invariant of `TextOutputStreamable` assumed by
various bits of the stdlib—including the quoted documentation above
since `TextOutputStreamable` conformance "trumps"
`CustomStringConvertible` conformance when it comes to printing—is that
what's written to the stream matches `description`.)

Therefore, this PR adds an explicit code path to
`TextOutputStreamable.write` to restore `"nan"` as the printed,
interpolated, and streamed output for floating-point NaN. This parallels
the existing explicit code path for `description` itself.

Additional testing is added to prevent this behavior from silently
drifting again from documented guarantees. (It's telling that getting CI
to pass on all platforms required no changes to any existing test.)

Resolves #89496 

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2026-06-01 11:10:09 -04:00
Alejandro Alonso 2757f7666c Revert "Merge pull request #88990 from Azoy/nonescapable-ref"
This reverts commit 66a1326cdb, reversing
changes made to 33ae606011.
2026-05-29 10:43:52 -07:00
Tim Kientzle b882d4bd6e Merge pull request #88547 from tbkka/tbkka-new-fp-description
Faster FP printing + Float80

**Explanation**: Implements a new, faster debugDescription for floating-point types that uses a modified form of Rafaello Giulietti's Schubfach algorithm. Also expands the Swift-based printing and parsing routines to fully support Float80.

**Scope**: The new routines provide exactly the same API and behavior as the previous floating-point printing and parsing. The addition of Float80 parsing support insulates us from OS-specific variations in strtold support.

**Risk**: Modest. The code has been well-tested, but there has been a history of 32-bit issues with previous work in this area.

**Testing**: Existing unit tests all pass, including tests that verify that we're exporting the same internal endpoints. In addition, correctness has been verified with an offline test suite.

Notes:
* The core _Float64ToASCII function is about 1/2 the code+data of the previous implementation and also nearly 2x faster than before. This means that Double.debugDescription now spends most of its time allocating memory for the returned String.
* The Float80 support for printing and parsing has enough extra precision to also support Float128 if we ever want to add that.
2026-05-26 12:53:03 -07:00
Guillaume Lessard ef271b4bef Merge pull request #89231 from jmschonfeld/wcsia-simple-collection
Implement withContiguousStorageIfAvailable for EmptyCollection and CollectionOfOne
2026-05-20 14:10:48 -07:00
Guillaume Lessard e85af127a1 [test] wCSIA for EmptyCollection and CollectionOfOne 2026-05-18 17:05:44 -07:00
Guillaume Lessard 616e61a367 Merge pull request #89188 from glessard/rdar177198190-ref-mutableref-conformances 2026-05-18 13:00:24 -07:00
Tim Kientzle b876de4bdb Float16.debugDescription: mis-rounding due to buffer underrun
An off-by-one led to a rounding decision based on the
word just before the work buffer.  This would randomly fail
depending on the contents of that word.

Fixes the bug and adds some more ties-round-even tests
to ensure coverage of all branches in this section.
2026-05-18 08:43:59 -07:00
Guillaume Lessard d4e57530a5 [test] Ref and MutableRef conformances 2026-05-15 16:20:57 -07:00
Guillaume Lessard 79ac549c9e [test] add idiomatic availability requirements 2026-05-15 16:04:07 -07:00
Guillaume Lessard 459a3208c4 Merge pull request #89063 from glessard/rdar139816157-se0525-followup
[stdlib] remove functions deferred from SE-0525
2026-05-12 20:20:06 -07:00
Guillaume Lessard b61089961a [test] remove functions deferred from SE-0525 2026-05-12 15:24:13 -07:00
Alejandro Alonso f5561eaa4a Let Ref reference nonescapable types 2026-05-09 11:00:23 -07:00
David Smith ed3eec2cd1 Change String growth to resize by 1.625x instead of 2x (#88973)
Fixes rdar://59684914
2026-05-09 08:48:39 -07:00
David Smith f08afd00c3 Vectorize UTF16->UTF8 transcoding (#83073)
Fixes rdar://141789595
2026-05-08 11:49:00 -07:00
Guillaume Lessard 590bef642b Merge pull request #88788 from glessard/wasi-expectCrash-skip
[StdlibUnittest] Skip crash testing based on test runner feature rather than platform
2026-05-08 09:18:11 -07:00
Guillaume Lessard b55e6120ad [test] rename .requireCapability to .require in gyb tests 2026-05-07 19:13:53 -07:00
Guillaume Lessard cb85c226c0 [StdlibUnittest] rename .requireCapability to .require 2026-05-07 15:30:25 -07:00
Guillaume Lessard a2c9886d62 [test] replace wasi-based skips with feature-based requirements 2026-05-07 13:20:40 -07:00
Guillaume Lessard 45eb3ac16a [test] skip a test for a different WASI-related reason. 2026-05-07 13:20:39 -07:00
Guillaume Lessard a4c6bec0c2 [test] skip rather than avoid crash tests for WASI 2026-05-07 13:20:39 -07:00
David Smith 5039cccf80 Add a cross-encoding version of strcmp, use it in bridged String equality, and expose it for Foundation's use (#87271)
There's a longstanding problem in implementing `-isEqualToString:`,
where if you don't know how to get fast access to the other NSString's
contents, you have to pick between doing it character by character (very
slow), or calling [other isEqualToString: self], which risks infinite
recursion if the other string does the same.

This cuts the gordian knot by adding a new method
`isEqualToBytes:encoding:count:`, so you can get the contents out of
`self`, and hand it to the other string, confident that it will not need
to (nor, in fact be able to) ask you anything that might recurse.
2026-05-07 02:10:44 -07:00
Alejandro Alonso 6b960acf30 Merge pull request #88766 from Azoy/fix-box-test
[test] Change Box test to not be a FileCheck test
2026-05-05 10:26:45 -07:00
Guillaume Lessard 86c01256e2 [test] add an availability guard
- and fix discrepancies with internal branch
2026-05-04 12:24:33 -07:00
Doug Gregor 6c555aa605 Merge pull request #88786 from Azoy/borrow-to-ref
[stdlib] Rename Borrow and Inout to Ref and MutableRef
2026-05-03 22:02:17 -07:00
Doug Gregor 64e9cea4ab Merge pull request #88702 from glessard/rdar139816157-safe-loading-api-rawspan
[SE-0525] Safe loading API for `RawSpan` family
2026-05-03 21:52:19 -07:00
Ben Cohen 0c615e7d42 Remove old feature flag tests 2026-05-03 10:51:14 -07:00
Guillaume Lessard 5aed20039d [stdlib] rename append(elementCount:…)
Argument label `elementCount` becomes `upTo`.
2026-05-02 05:48:12 -07:00
Guillaume Lessard 728b64846d [test] don’t depend on Float16 2026-05-02 05:48:11 -07:00
Guillaume Lessard b030553b89 [test] fix two tests for wasi 2026-05-02 05:48:11 -07:00
Guillaume Lessard 001176b0a0 [test] make compatible with 32-bit targets 2026-05-02 05:48:11 -07:00
Guillaume Lessard 79f20b20e2 Update test/stdlib/Span/OutputRawSpanTests.swift 2026-05-02 05:48:10 -07:00
Guillaume Lessard 5007cf2bd8 [stdlib] consistency fixes 2026-05-02 05:48:09 -07:00
Guillaume Lessard 7c65afe773 [test] bitCast function 2026-05-02 05:48:09 -07:00
Guillaume Lessard 5390c91696 [test] validate new conformances and non-conformances 2026-05-02 05:48:09 -07:00
Guillaume Lessard e30a692e7d [test] SE-0525 additions to OutputRawSpan 2026-05-02 05:48:08 -07:00
Guillaume Lessard a61701237f [test] SE-0525 additions to MutableRawSpan 2026-05-02 05:47:48 -07:00
Guillaume Lessard 25a75244bc [test] SE-0525 additions to RawSpan 2026-05-02 05:47:17 -07:00
Guillaume Lessard 8215fc336a [test] SE-0525 addition to OutputSpan 2026-05-02 05:47:17 -07:00
Guillaume Lessard 66bf01916b [test] SE-0525 additions to MutableSpan 2026-05-02 05:47:16 -07:00
Guillaume Lessard 020af45f93 [test] SE-0525 additions to Span 2026-05-02 05:47:16 -07:00
Guillaume Lessard 070c664c0c [test] basic test for safe loading API 2026-05-02 05:46:28 -07:00
Alejandro Alonso b87c07a487 Rename Borrow and Inout to Ref and MutableRef 2026-05-01 16:54:42 -07:00
Guillaume Lessard 1bda8e21e3 [gardening] more line-length pruning 2026-05-01 14:12:00 -07:00
Guillaume Lessard b33db0b3a5 [test] replace fatalError with expectUnreachable
When testing, the unexpected should not be fatal.
2026-05-01 14:10:26 -07:00
Guillaume Lessard 8716b95f89 [test] skip tests rather than use conditional compilation 2026-05-01 14:10:16 -07:00
Guillaume Lessard 191408e05a [test] temporary allocation tests with -strict-memory-safety 2026-05-01 14:07:58 -07:00
Max Desiatov dcd67ec3ee Add OutputRawSpan overload of withTemporaryAllocation 2026-05-01 00:14:51 +01:00