Commit Graph

7182 Commits

Author SHA1 Message Date
Stephen Canon
102df47a4c Make static [milli/micro/nano]seconds members on Duration inlinable (#73429)
This means that they can't use _Int128 for their implementation, but efficient implementation of these using only 64b arithmetic is pretty straightforward, so that's OK. This allows them to be specialized and mostly optimized away in release builds.
2024-05-04 10:39:17 -04:00
Nate Chandler
06921cfe84 [SIL] Hollow out Builtin.copy, deprecate _copy.
The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
2024-05-03 15:56:25 -07:00
Karoy Lorentey
3061531cb6 [stdlib] ManagedBuffer: Fix misapplied linkage names for legacy entry points
I accidentally copy and pasted the mangled symbol names in the wrong order, so existing callers got directed to the wrong entry points, and things got terribly, terribly wrong.

(We badly need a sensible replacement for these `@_silgen_name` hacks.)

Huge thanks to @edymtt for spotting this!

rdar://127016847
2024-05-02 14:24:55 -07:00
Kuba Mracek
1d48f28d84 [KeyPath] Fix regression in == on keypaths 2024-04-30 12:50:03 -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
Joe Groff
2f954ef5d7 Merge pull request #73259 from jckarter/external-key-path-generic-environment-binding
IRGen: Fix key path generic environment marshalling for external property descriptors.
2024-04-25 16:24:42 -07:00
Nate Chandler
b12def9c6a [BitwiseCopyable] Deprecate unbound overloads.
The unconstrained overloads of loadUnaligned and storeBytes were
deprecated in SE-0426.
2024-04-25 11:44:15 -07:00
Nate Chandler
f9ad81e106 [BitwiseCopyable] Remove #ifs. 2024-04-25 11:44:15 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00
Alex Martini
587c79b6f1 Fix plurals
Incorporates feedback from Slava Pestov <spestov@apple.com>
2024-04-25 11:05:35 -07:00
Joe Groff
02e1f2ea15 IRGen: Fix key path generic environment marshalling for external property descriptors.
The layout of a computed key path component carries an argument buffer for captures, which has
the following layout:

```
---
captured values (subscript indices)
---
generic arguments
---
```

When we reference an externally-defined public property or subscript from a key path, and the
external declaration has a property descriptor, then the generic arguments for the external
declaration get appended to the end of this buffer, giving:

```
---
captured values (subscript indices)
---
generic arguments
---
external property's generic arguments
---
```

The convention for key path accessors to bind their generic environment is thus to unpack them
from the end of the argument buffer, so that the external keypath's accessors can find the
arguments to bind the external generic environment while still allowing the enclosing key path
to save the original captured generic environment (which may be necessary to capture the
appropriate conditional and/or retroactive `Equatable` and `Hashable` conformances for
subscript indices).

However, our code generation for binding the generic arguments out of the argument buffer
contained a flawed optimization: for a property, we know there are never any captured values,
so I had assumed that the generic parameters could always be bound from the beginning of the
argument buffer, assuming that the generic parameters make up the totality of the buffer. This
falls over for external property descriptor references when the key path itself captures a
generic environment, since the external property's expected generic environment appears after
the key path's original generic environment. We can fix this by removing the conditional
entirely, and always adjusting the offset we load the generic environment from to look at the
end of the buffer. Fixes rdar://125886333.
2024-04-25 10:36:13 -07:00
Alex Martini
3c54f6819b Fill in reference for Copyable 2024-04-24 16:58:00 -07:00
Nate Chandler
6e975da805 [BitwiseCopyable] Promote ConformanceSuppression.
The ability to suppress conformance to BitwiseCopyable was part of the
accepted SE-428.
2024-04-24 15:52:20 -07:00
Nate Chandler
ed5c7ef7ae [BitwiseCopyable] Promote to feature.
SE-0426 was accepted.
2024-04-24 15:52:20 -07:00
Alex Martini
8468088e55 Add requirements & sketch TSPL cross reference 2024-04-23 09:12:15 -07:00
Kavon Farvardin
f0a69a3ef1 prevent uses of Escapable in general
This protocol appears in the stdlib as scaffolding for the
`NonescapableTypes` feature, which is still experimental and not gone
through evolution as an approved addition to the stdlib.

Rather than delete it from the stdlib, because it needs to still remain
to support that feature work, gate references to it behind a feature
flag.

Additionally, prevent documentation from seeing this declaration.

rdar://126705184
2024-04-22 20:40:11 -07:00
GG
739ff6f0c2 Fix typo in Result.swift 2024-04-21 21:17:22 +09:00
Dave Lee
e57f70bd4d [Debugging] Add DebugDescriptionMacro experimental feature (#73107)
This removes the leading underscore from the macro.
2024-04-18 17:25:44 -07:00
nate-chandler
b00b5aad4f Merge pull request #72646 from nate-chandler/bitwise-copyable/20240327/1
[BitwiseCopyable] Allow suppression via ~.
2024-04-18 07:05:10 -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
153c001b15 [stdlib] Undo typed throws on withExtendedLifetime
https://github.com/apple/swift/pull/73045 has uncovered a compiler crash with existing code of this form:

       try withExtendedLifetime(statement) { // 💥silgen crash
            do {
                try dbPool.close()
                XCTFail("Expected Error")
            } catch DatabaseError.SQLITE_BUSY { }
        }

This patterns can happen with any of the newly typed throwing entry points, but the source compat suite only seems to have caught this with `withExtendedLifetime`; let’s see if we can get away with only rolling back this one.
2024-04-16 17:10:24 -07:00
Karoy Lorentey
fab25dc984 [stdlib] Optional, Result: Update borrowing switch syntax (_borrowing → borrowing) 2024-04-16 01:15:33 -07:00
Karoy Lorentey
5679bf6697 [stdlib] Generalize temporary allocations for noncopyable result types
We can’t do typed throws here yet. (They involve implicit stack allocations that interfere with the explicit stack allocation builtins.)
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
Nate Chandler
eb1f0ac68a [BitwiseCopyable] Suppress via ~.
In addition to the existing language mechanism of
`@available(*, unavailable)`.
2024-04-15 16:46:24 -07:00
Nate Chandler
deeea710ae [NFC] stdlib: Separate type decl from members. 2024-04-15 16:46:00 -07:00
Artem Chikin
01d891ad99 Merge pull request #72834 from artemcm/UpstreamVisionOS
Introduce visionOS Platform
2024-04-15 09:33:49 -07:00
Alex Martini
325e033547 Add initial reference for Copyable
Drawing from SE-0427.
2024-04-12 16:55:52 -07:00
Yuta Saito
10410f1030 Merge pull request #72973 from kateinoigakukun/yt/repair-embedded-wasm-class
[embedded][wasm] Fix missing putchar symbol in test
2024-04-12 00:06:35 +09:00
Yuta Saito
7a205dca32 [embedded] Use @_extern(c) instead of @_silgen_name for putchar 2024-04-11 02:55:23 +00:00
Kuba Mracek
8dfee7de2b [embedded] Conditionalize assert printing to debug assert config 2024-04-10 19:22:00 -07:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Kuba Mracek
67f3d34d02 [embedded] Fix fatalError() to produce a trap in Release configurations 2024-04-09 11:36:39 -07:00
Kuba Mracek
309dbe1c1a [embedded] Make fatalError() in embedded Swift only print in non-production builds (-Onone or -assert-config Debug) 2024-04-09 11:36:38 -07:00
Kuba Mracek
757e4e56b0 [embedded] In -assert-config Debug, print errors in assertions, preconditions, fatalErrors 2024-04-09 11:36:21 -07:00
Yuta Saito
ef07102b88 Merge pull request #72891 from kateinoigakukun/yt/fix-wasm-float16 2024-04-10 01:01:58 +09:00
Erik Eckstein
ce33d47a4c stdlib: add the swift_clearSensitive runtime function 2024-04-09 12:01:10 +02:00
Yuta Saito
c32c7f55fe [wasm] Fix build failure due to lack of _Float16 support
WebAssembly does not support _Float16 type, so we need to guard the use
of the type. Unfortunately, Clang does not provide a good way to detect
the support of _Float16 type at compile time, so just disable for wasm
targets.
2024-04-07 16:34:11 +00:00
Stephen Canon
6ac852f3f4 Move Float16 print tests to their own file and test exhaustively (#72859)
We can easily test all 2**16 values, so let's do it. Also now _Float16 is properly supported in clang, so we can pass arguments to CPP that way, which lets us get snan right on more platforms.
2024-04-05 19:55:19 -04:00
Meghana Gupta
b3b2f37262 Merge pull request #72822 from stephentyrone/a-a-ambiguity-breaker-part-ii
Further ambiguity breakers for UDC & SEDC
2024-04-04 15:10:59 -07:00
Stephen Canon
cb400c61bb Add further ambiguity breakers for UDC & SEDC 2024-04-03 18:47:19 -04:00
Alejandro Alonso
e71a55eb19 Print a special message when we fail getting a keypath value 2024-04-03 15:35:55 -07:00
Stephen Canon
cbf9cb2734 Break ambiguity for types conforming to both UEC and SVEC (#72800)
* Break ambiguity for types conforming to both UEC and SVEC

If an encoding container conforms to _both_ UEC and SVEC and does not
itself implement support for [U]Int128, there is an ambiguity between
the two default implementations. Add additional defaults defined on
the intersection of the protocols to resolve this.

* Update abi tests for new ambiguity breakers.
2024-04-03 16:53:48 -04:00
Stephen Canon
a381589524 SE-0425 implementation (#72139) 2024-04-02 16:24:41 -04:00
Nate Cook
38e1370884 Revert "Revert count(where:)" (#70816)
* Revert "Revert count(where:)"

This reverts commit 779ea19a6a.

Now that SE-0220 has been re-accepted, this adds the `count(where:)` 
Sequence method to the standard library.
2024-03-29 13:53:53 -05: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
Alejandro Alonso
af11b95f4d Merge pull request #72656 from weissi/jw-fix-json
fix GroupInfo.json: was invalid JSON
2024-03-28 13:31:23 -07:00
Alejandro Alonso
07eb52a80d Merge pull request #72636 from Azoy/destroy-array-opt
[IRGen] Optimize Builtin.arrayDestroy when count is 1
2024-03-28 11:32:43 -07:00