Commit Graph

103 Commits

Author SHA1 Message Date
Alex Martini
587c79b6f1 Fix plurals
Incorporates feedback from Slava Pestov <spestov@apple.com>
2024-04-25 11:05:35 -07:00
Alex Martini
3c54f6819b Fill in reference for Copyable 2024-04-24 16:58:00 -07:00
Alex Martini
8468088e55 Add requirements & sketch TSPL cross reference 2024-04-23 09:12:15 -07:00
Alex Martini
325e033547 Add initial reference for Copyable
Drawing from SE-0427.
2024-04-12 16:55:52 -07:00
Meghana Gupta
806921c0c8 Allow ~Escapable types to be _BitwiseCopyable 2024-03-06 21:57:03 -08:00
Kavon Farvardin
3908c8182d NCGenerics: sometimes synth. Copyable/Escapable
When the Swift module is not available, we'll synthesize the
Copyable/Escapable decls into the Builtin module.

In the future, it might be nice to just do this always, and define
typealiases for those types in the stdlib to refer to the ones in the
builtin module.
2024-02-02 18:47:03 -08: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
Doug Gregor
9e4e9ea400 Replace rethrowing map with generic typed throws
Adopt typed throws for the `map` operation to propagate thrown error
types through the `map` API. This is done in a manner that is backward
compatible for almost all cases:

* The new typed-throws entrypoint is `@_alwaysEmitIntoClient` so it
can back-deploy all the way back.
* The old `rethrows` entrypoint is left in place, using
`@usableFromInline` with `internal` so it is part of the ABI but not
the public interface, and `@_disfavoredOverload` so the type checker
avoids it while building the standard library itself. The old
entrypoint is implemented in terms of the new one.

Note that the implementation details for the existential collection
"box" classes rely on method overriding of `_map` operations, and the
types are frozen, so  we don't get to change their signatures. However,
these are only implementations, not API: the actual API `map`
functions can be upgraded to typed throws.

Note that this code makes use of a known hole in `rethrows` checking
to allow calling between `rethrows` and typed throws. We'll need to do
something about this for source-compatibility reasons, but I'll follow
up with that separately.
2024-01-12 10:17:58 -08:00
Kavon Farvardin
8b870e9e6c [NCGenerics] fix Copyable/Escapable declarations
When building the stdlib with noncopyable generics enabled,
requirements for Copyable and Escapable  end up being inferred on the
protocols Copyable and Escapable, themselves. So we need to opt-out
Copyable from requiring Escapable, and vice versa.
2024-01-10 19:37:21 -08:00
Kavon Farvardin
b43f861827 [NCGenerics] delete _Copyable from stdlib
resolves rdar://115793371
2023-12-16 11:17:31 -08:00
Kavon Farvardin
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00
Nate Chandler
b266abe5c0 [BitwiseCopyable] Add a marker protocol.
Behind the experimental feature BitwiseCopyable.
2023-11-30 15:25:46 -08:00
Doug Gregor
3baf6ac31a Revert "[Typed throws] Support overrides that are contravariant in the thrown error" 2023-11-16 10:40:23 -08:00
Doug Gregor
0d15d4edbe Replace rethrowing map with generic typed throws
Adopt typed throws for the `map` operation to propagate thrown error
types through the `map` API. This is done in a manner that is backward
compatible for almost all cases:

* The new typed-throws entrypoint is `@_alwaysEmitIntoClient` so it
can back-deploy all the way back.
* The old `rethrows` entrypoint is left in place, using
`@usableFromInline` with `internal` so it is part of the ABI but not
the public interface, and `@_disfavoredOverload` so the type checker
avoids it while building the standard library itself. The old
entrypoint is implemented in terms of the new one.

Note that the implementation details for the existential collection
"box" classes rely on method overriding of `_map` operations, and the
types are frozen, so  we don't get to change their signatures. However,
these are only implementations, not API: the actual API `map`
functions can be upgraded to typed throws.

Note that this code makes use of a known hole in `rethrows` checking
to allow calling between `rethrows` and typed throws. We'll need to do
something about this for source-compatibility reasons, but I'll follow
up with that separately.
2023-11-13 11:47:00 -08:00
Kavon Farvardin
cc7a41fc2c [stdilb] introduce Copyable protocol
This replaces the old, unavailable `_Copyable`.

rdar://110420673
2023-09-21 00:55:17 -07: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
Kavon Farvardin
091d63a5c8 revise how the Copyable constraint is added
The _Copyable constraint was implemented as a marker protocol.
That protocol is part of the KnownProtocol's in the compiler.
When `ASTContext::getProtocol(KnownProtocolKind kind)` tries
to find the ProtocolDecl for Copyable, it will look in the
stdlib module (i.e., Swift module), which is where I initially
planned to put it.

That created problems initially when some regression tests
use `-parse-stdlib` failed to do that protocol lookup, which is
essential for adding the constraint (given the current implementation).

That led to believe we need to pull Copyable out of the stdlib, but that's
wrong. In fact, when building the Swift module itself, we do `-parse-stdlib`
but we also include `-module-name Swift`. This causes the _Copyable protocol
defined in the Stdlib to be correctly discovered while building the stdlib
itself (see the test case in this commit). So, the only downside of
having the Copyable protocol in the Stdlib is that `-parse-stdlib` tests
in the compiler can't use move-only types correctly, as they'll be
allowed in generic contexts. No real program would build like this.

Until I have time to do a further refactoring, this is an acceptable trade-off.

fixes rdar://104898230
2023-03-04 11:42:09 -08:00
Kavon Farvardin
ab130883a3 Initial ban of move-only types from being used generically
Since values of generic type are currently assumed to always
support copying, we need to prevent move-only types from
being substituted for generic type parameters.

This approach leans on a `_Copyable` marker protocol to which
all generic type parameters implicitly must conform.

A few other changes in this initial implementation:

- Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable.
- Narrowly ban writing a concrete type `[T]` when `T` is move-only.
2023-02-01 23:38:28 -08:00
Konrad `ktoso` Malawski
4fa0855907 [Distributed] RemoteCallTarget now pretty prints and hides mangled names 2022-03-15 17:34:04 +09:00
Hassan
1d4f220ed4 [stdlib] Replace precondition with the internal _precondition 2021-11-04 23:51:10 +02:00
Karoy Lorentey
8ed81ae063 [stdlib] Adopt availability macros 2021-10-31 15:00:58 -07:00
Erik Eckstein
a5030a63b0 stdlib: add a _unsafePerformance function which disable performance diagnostics in the passed closure. 2021-10-28 18:44:44 +02:00
Alejandro Alonso
7e0eaf7b99 Remove metadata section functions from the stdlib (#39236)
add aliases in test suite
2021-09-14 11:55:39 -07:00
Chéyo Jiménez
c87c9fe998 precondition message wording in stdlib/public/core/Misc.swift 2020-12-24 15:44:55 -05:00
Jordan Rose
fc6b14faf7 stdlib: Remove unused, unsafe helper function _withUninitializedString (#33704)
No functionality change.
2020-09-14 18:16:38 +01:00
Vedant Kumar
2308bb18b1 Add _getMetadataSection{,Count,Name} to API digester allow list (#33138)
These APIs are needed to build SwiftReflectionTest.swift when testing
Release builds.

This rolls back 014918c0, which hid these APIs in non-asserts builds
causing a failure:

  https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64/5708/consoleText

rdar://66103895
2020-07-28 15:19:18 -07:00
eeckstein
5fffeb81fb Merge pull request #33128 from eeckstein/string-optimization
SIL optimizer: Add a new string optimization
2020-07-28 10:17:28 +02:00
Nate Cook
014918c0ca Only include _getMetadataSection functions in stdlib builds w/ assertions 2020-07-27 17:12:27 -05:00
Erik Eckstein
b42bce4ba4 stdlib: changes for the StringOptimization
To be able to constant fold string interpolation, the right semantic attributes must be in place.
Also, the interpolation's write function must be inlinable.
For the _typeName constant folding, a semantic attribute is required.
2020-07-27 21:32:56 +02:00
Augusto Noronha
3cb8f9b6fc Add entrypoints to the runtime that exposes metadata necessary for reflection tests on Linux (#32339) 2020-07-24 15:26:15 -07:00
Mishal Shah
272c466e47 Update master to build with Xcode 12 beta 2020-06-22 15:43:20 -07:00
Konrad `ktoso` Malawski
5faf82c553 Improve usability of _mangledTypeName with Any.Type arguments 2020-04-05 12:27:50 +09:00
Konrad `ktoso` Malawski
34b6e4fe58 Add precondition that no repairs were made to _mangledTypeName string 2020-03-18 11:51:28 +09:00
Konrad `ktoso` Malawski
ea6b69eabc Add missing @available marker on _getMangledTypeName 2020-03-10 14:04:47 +09:00
Konrad `ktoso` Malawski
33444489e5 Add _mangledTypeName to allow round trips T->mangledName->T 2020-03-10 12:20:08 +09:00
Joe Groff
e30c86769a KeyPath: Allow existing context descriptors to be used as generic environment.
If a key path literal appears in a generic context with an existing context descriptor, this will allow us to
save some code size by not having to emit a separate GenericEnvironment descriptor.
2018-12-11 09:05:47 -08:00
Joe Groff
85eb634191 stdlib: Make _typeByName Foundation SPI reject symbolic references.
It's used for recovering type metadata from deserialized mangled names, which should never have symbolic
references in them.
2018-12-10 20:22:03 -08:00
Joe Groff
021053d499 Runtime: Make getTypeByMangledNameIn(Context|Environment) a public entry point.
This can be used by compiler-generated code as a size optimization for metadata access, using a
mangled name instead of possibly many open-coded metadata calls. It can also allow reflection
libraries outside of the standard library to turn type reference strings into in-process metadata
pointers in a robust way. rdar://problem/46451849
2018-12-10 14:22:41 -08:00
Doug Gregor
cc2ee165a1 [ABI] Use generic environment to handle mangled generic keypath types.
Always use mangled type names to represent type metadata in keypath patterns.
For generic types, use the generic environment to pull substituted types
from the instantiation arguments.

Finishes the type metadata part of rdar://problem/38038799.
2018-11-16 10:13:07 -08:00
Doug Gregor
723b56e64f [Standard library] Simplify _getTypeByMangledName.
Simplify the signature of the internal _getTypeByMangledName() used by the
standard library to what we actually (currently) use. Drop it as a
compatibility override, because it’s not a useful place to introduce
customization.
2018-11-15 16:10:11 -08:00
Doug Gregor
041ffe82d4 [Standard library] Eliminate some newly-introduced warnings. 2018-11-15 11:21:42 -08:00
Doug Gregor
a53b2e285c [Standard library] Drop _typeByMangledName().
This underscored function was only intended for testing; drop it from the
ABI. We’re keeping _typeByName because it’s used by Foundation.
2018-11-15 11:06:52 -08:00
Ben Cohen
92d2959a46 Regroup ABI expected list by change 2018-11-08 06:45:20 -08:00
Ben Cohen
b1038e9b9b Misc inlinability fixes 2018-11-08 06:45:20 -08:00
Michael Ilseman
7aea40680d [String] NFC iterator fast-paths
Refactor and rename _StringGutsSlice, apply NFC-aware fast paths to a
new buffered iterator.

Also, fix bug in _typeName which used to assume ASCIIness and better
SIL optimizations on StringObject.
2018-11-04 10:42:41 -08:00
Ben Cohen
a6952decab [stdlib] Remove inlineable annotation from transparent functions (#17800)
* Remove inlineable annotation from transparent functions
2018-07-07 08:47:02 -07:00
Slava Pestov
2e5aef9c8d stdlib: Remove redundant @usableFromInline attributes 2018-04-06 00:02:30 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Michael Ilseman
cdfeb88cfe [string] Simplify creation logic, especially for C strings.
Streamline internal String creation. Previously, everything funneled
into a single generic function, however, every single call of the
generic funnel had relevant specific information that could be used
for a more efficient algorithm.

In preparation for efficiently forming small strings, refactor this
logic into a handful of more specialized subroutines to preserve more
specific information from the callers.
2018-03-27 10:49:02 -07:00
Xiaodi Wu
f4a3947632 Remove _countLeadingZeros and _floorLog2 2018-02-02 09:58:00 -06:00