Commit Graph

143 Commits

Author SHA1 Message Date
Karoy Lorentey
201430522b [stdlib] Generalize ManagedBufferPointer.== 2025-03-24 12:15:41 -07:00
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Kuba Mracek
0b50c2155e Don't emit upcast to the same type in SimplifyAllocRefDynamic, add test, add comment 2024-09-24 08:48:51 -07:00
Kuba Mracek
c7a5569c4f [embedded] Add support for ManagedBuffer to Embedded Swift
This makes ManagedBuffer available and usable in Embedded Swift, by:

- Removing an internal consistency check from ManagedBuffer that relies on metatypes.
- Making the .create() API transparent (to hoist the metatype to the callee).
- Adding a AllocRefDynamicInst simplification to convert `alloc_ref_dynamic` to `alloc_ref`, which removes a metatype use.
- Adding tests for the above.
2024-09-23 13:32:50 -07:00
Guillaume Lessard
f9eb3223fe [stdlib] mark ManagedBufferPointer non-Sendable 2024-08-08 11:26:30 -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
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
Guillaume Lessard
3b09ecec74 [gardening] update copyright notice
[gardening] update copyright notice

[gardening] update copyright notice

[gardening] update copyright notice

[gardening] update copyright notice
2024-03-18 11:08:32 -07:00
Karoy Lorentey
afa459edd8 [stdlib] ManagedBuffer: Add @_preInverseGenerics for $Embedded 2024-03-18 11:08:32 -07:00
Karoy Lorentey
ce62475cd9 [stdlib] ManagedBuffer: Support for noncopyable Element
Header is tricky, but it’s on the TODO list for later.
2024-03-18 11:03:49 -07:00
Alejandro Alonso
f9f640b141 Sendablize the standard library
oops dont add this flag

no more nonisolated
2024-03-05 15:02:09 -08:00
Erik Eckstein
75e2f363a0 embedded stdlib: make the ManagedBuffer initializer public in the embedded stdlib
Otherwise derived classes cannot be specialized.

Fixes a compile time error when using ManagedBuffer in embedded mode.
rdar://122414669
2024-02-14 09:51:43 +01:00
Kuba Mracek
89bdcb8dc6 [embedded] Ifdef newly added _assertionFailure + isKnownUniquelyReferenced variants to avoid exposing new APIs outside of embedded Swift 2023-09-17 19:58:15 -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
Erik Eckstein
a5744b2bb5 stdlib: make deinit of ManagedBuffer inlinable
This allows to eliminate dead allocations of a ManagedBuffer object.

https://github.com/apple/swift/issues/66496
2023-06-26 12:10:15 +02:00
Alex Martini
f81d11492a Remove repetitive wording.
Fixes <rdar://59618453>
2021-10-29 11:05:21 -07:00
Alex Martini
9eabba58cb Make abstracts one sentence long.
The second sentence was added while rewriting to remove 'iff' in commit
6bc4c85005.
2021-02-17 15:31:24 -08:00
3405691582
cd7570fdee ManagedBuffer capacity is unavailable on OpenBSD.
On OpenBSD, malloc introspection (e.g., malloc_usable_size or
malloc_size) is not provided by the platform allocator. Since allocator
introspection is currently a load-bearing piece of functionality for
ManagedBuffer and ManagedBufferPointer, pending any API changes, as a
stopgap measure, this commit marks methods in ManagedBuffer and
ManagedBufferPointer calling _swift_stdlib_malloc_size and methods
dependent thereon unavailable on OpenBSD.

This may induce some compatibility issues for some files, but at least
this change ensures that we can get stdlib to build on this platform
until the evolution process addresses this problem more thoroughly.
2020-09-09 18:57:58 -04:00
Karoy Lorentey
9638e9167c [doc] ManagedBuffer: Fix cross-reference to isKnownUniquelyReferenced 2019-09-10 18:52:26 -07:00
Karoy Lorentey
6bc4c85005 [doc] Avoid use of “iff” in public API documentation 2019-09-10 18:52:01 -07:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
Slava Pestov
ec4c597156 stdlib: ManagedBuffer.init(_doNotCallMe:) was ABI in Swift 5 and should be @usableFromInline 2019-06-01 00:08:05 -04: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
Ben Cohen
eb083ce84d Revert "implement ManagerBuffer.reallocated to allow realloc'ing the storage" (#21874)
* Revert "implement ManagerBuffer.reallocated to allow realloc'ing the storage"
2019-01-16 10:22:58 -08:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Johannes Weiss
17e5fa3506 Merge pull request #19421 from weissi/jw-managed-buffer-realloc
implement ManagerBuffer.reallocated to allow realloc'ing the storage
2018-11-09 17:14:08 +00:00
Ben Cohen
6aab1c8b0d Remove last addressWithNativeOwner use (#20448) 2018-11-09 06:22:13 -08:00
Karoy Lorentey
713ff13d58 [stdlib] ManagedBufferPointer: inlinability audit & slight reorganization 2018-11-09 10:37:20 +00:00
Karoy Lorentey
e3a5750aa3 [stdlib] ManagedBufferPointer: Remove _My typealias. 2018-11-09 10:37:20 +00:00
Johannes Weiss
2d9fa20c6b implement ManagerBuffer.reallocated to allow realloc'ing the storage 2018-11-08 18:18:23 +00:00
Karoy Lorentey
a8f29a3ce5 [stdlib] Simplify _HeapBuffer; limit its scope and rename to _BridgingBuffer
- HeapBuffer was at the wrong abstraction level, for no good reason. We have ManagedBuffer for the general case; we don’t need a slightly less general variant of it.
- Current usages of HeapBuffer are hyper specific: they all are flat buffers of AnyObjects, facilitating bridging. It makes sense to dedicate _HeapBuffer for this single usecase.
- Introduce a dedicate ManagedBuffer subclass for bridging buffers. This will make it slightly easier to recognize these in heap dumps.
- Inlinability audit.
2018-10-26 23:53:06 +01:00
Mike Ash
e18e03171f [Stdlib] Change SWIFT_RUNTIME_STDLIB_INTERNAL to not export the symbol.
The functions in LibcShims are used externally, some directly and some through @inlineable functions. These are changed to SWIFT_RUNTIME_STDLIB_SPI to better match their actual usage. Their names are also changed to add "_swift" to the front to match our naming conventions.

Three functions from SwiftObject.mm are changed to SPI and get a _swift prefix.

A few other support functions are also changed to SPI. They already had a prefix and look like they were meant to be SPI anyway. It was just hard to notice any mixup when they were #defined to the same thing.

rdar://problem/35863717
2018-10-03 09:55:33 -04:00
Ben Cohen
d414ece556 Switch ManagedBuffer.header to use _modify (#19226) 2018-09-11 17:40:43 -07:00
Erik Eckstein
7c06d4f8ab Remove the pinning built-ins.
They are not used anymore after removing the pinning adressors.
2018-08-23 12:47:56 -07:00
Karoy Lorentey
23c630ac92 [stdlib] Add @usableFromInline to internal typealiases that need it
This fixes 3659 warnings in the standard library.
2018-06-18 16:34:19 +01: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
Dave Abrahams
5a61dc1dd7 Revert "Avoid two uses of defer {}" 2018-02-28 15:28:15 -08:00
Dave Abrahams
6a3a91d0fc Avoid two uses of defer {}
Last time I checked, things done in defer were not well-optimized and could cause closure allocation.
2018-02-27 15:41:03 -08:00
Nate Cook
0782b482b3 [stdlib] Documentation improvements
- Revise Equatable and Hashable for synthesized requirements
- Complete Strideable and stride(from:...:by:) documentation
- Revise DoubleWidth type docs
- Add complexity notes for Set.index(of:) and .contains(_:)
- Fix typos in Set.formUnion docs
- Add missing axioms for SetAlgebra (SR-6319)
- Improve guidance for description and debugDescription
- Add note about the result of passing duplicate keys to
  Dictionary(uniqueKeysWithValues:)
- Fix typo in BinaryInteger docs
- Update Substring docs with better conversion example
- Improve docs for withMemoryRebound and isKnownUniquelyReferenced
- Add missing docs not propagated from protocols
2018-01-05 17:06:44 -06:00
Greg Parker
da14cd79a6 [runtime] Clean up symbol exports in libc functions. (#13202) 2017-12-01 17:49:11 -08:00
taylor swift
c85880899d implement SE 184: add allocation methods to Unsafe buffer pointers, drop all parameters from deallocation, adjust namings, and add repeated-value assignment methods 2017-11-17 21:28:03 -08:00
Max Moiseev
a24998a5b1 [stdlib] Add missing @_fixed_layout attributes to fix resilience build 2017-10-02 15:19:06 -07:00
Max Moiseev
53b8419279 [stdlib] Make all the stdlib APIs @_inlineable
This change in theory should allow us to remove a special stdlib-only
sil-serialize-all compilation mode.

<rdar://problem/34138683>
2017-09-29 11:26:56 -07:00
Maxim Moiseev
ee5fb33656 [stdlib] Remove the Grand Renaming artifacts of Swift 3 era 2017-08-28 15:54:11 -07:00
Dave Abrahams
c497969987 [stdlib] Swift4 Modernizations Compatible with Swift 3.2 2017-07-14 17:54:33 -07:00
Dave Abrahams
b2e4bd5d09 [stdlib] Replace _HeapBuffer with a thin wrapper
...over ManagedBufferPointer
2017-06-01 04:40:52 -07:00
Nate Cook
ca5c65f93c [stdlib] Nest some additional operators (#9646) 2017-05-17 19:44:08 -07:00
Roman Levenstein
29ad714bb7 Annotate stdlib functions to get a good performance even in resilient mode, when -sil-serialize-all is disabled
This commit mostly improves the performance of arrays and ranges.
It does not cover Strings, Dictionaries and Sets yet.
2017-03-16 19:46:11 -07:00
Michael Gottesman
6d7b11c8eb [stdlib] Cleanup usage of Builtin.castToNativeObject(...).
Previously often times when casting a value, we would just pass along the
cleanup of the uncasted value. With semantic SIL this is no longer correct since
the cleanup now needs to be on the cast result.

This caused problems for certain usages of Builtin.castToNativeObject(...) by
the stdlib. Specifically, the stdlib was using this on AnyObject values that
were not necessarily native. Since we were recreating the cleanup on the native
value, a swift native release was being used =><=.

In this commit I solve this problem by:

1. Adding an assert in Builtin.castToNativeObject(...) that ensures that any value
passed to Builtin.castToNativeObject() is known conservatively to use swift
native reference counting.

2. I changed all uses where we do not have a precondition of a native ref
counting type to use Builtin.castToUnknownObject(...).

3. I added a new Builtin called Builtin.unsafeCastToNativeObject(...) that does
not have the compile time check. I used this to rewrite callsites in the stdlib
where we know via preconditions that an AnyObject will dynamically always be
native.

rdar://29791263
2017-03-14 00:10:16 -07:00