Commit Graph

29 Commits

Author SHA1 Message Date
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Kuba Mracek
7120279755 [embedded] Avoid using a metatype variable in _allocateUninitializedArray 2024-05-12 22:07:00 -07:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
nate-chandler
a9e03df58c Revert "[Diagnostics] Require explicit releasenone." 2023-10-04 14:19:15 -07:00
Kuba Mracek
65d706db0d [embedded] Avoid use of a metatype in array implementation for embedded Swift 2023-09-18 20:36:53 -07:00
Kuba Mracek
c0735eee75 [embedded] Drop unnecessary #if in _makeCollectionDescription 2023-09-16 13:43:43 -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
Nate Chandler
2637c41e26 [stdlib] Explicitly annotate with releasenone.
Annotated all functions with arguments that are consumed and are
annotated `@_effects(readnone)` or `@_effects(readonly)` with
`@_effects(releasenone)`.
2023-09-05 08:18:06 -07:00
Anthony Latsis
c731089068 Gardening: Migrate stdlib sources to GH issues 2022-09-26 06:30:49 +03:00
Erik Eckstein
a2c29858c3 stdlib: annotate the Array semantics functions with escape effects 2022-05-02 12:00:06 +02:00
Arnold Schwaighofer
9f2b6a4ebb Reuse _ContiguousArrayStorage<AnyObject> metadata for any class or objc generic type
Reduces the number of _ContiguousArrayStorage metadata.

In order to support constant time bridging we do need to set the correct
metadata when we bridge to Objective-C. This is so that the type check
succeeds when bridging back from Objective-C to reuse the storage
instance rather than bridging the elements.

To support dynamically setting the `_ContiguousArrayStorage` element
type i needed to add support for optimizing `alloc_ref_dynamic`
throughout the optimizer.

Possible future improvements:
* Use different metadata such that we can disambiguate native Swift
  classes during destruction -- allowing native release rather then unknown
  release usage.
* Optimize the newly added semantic function
  getContiguousArrayStorageType

rdar://86171143
2022-02-16 07:55:34 -08:00
Kuba (Brecka) Mracek
2fa79689fa Turn build-swift-stdlib-static-print on for freestanding preset (#41260) 2022-02-09 05:41:04 -08:00
Meghana Gupta
410b88ef07 Fix @effects of finalizeUninitializedArray when assertions are enabled (#34101)
When assertions are enabled _endCOWMutation writes to _native.isImmutable.
But finalizeUninitializedArray is marked as @effects(readnone). This
mismatch caused miscompile in the stdlib due to CodeSinking optimization
which relies on SILInstruction::mayReadOrWriteMemory which looks at
@effects.
2020-09-28 15:54:46 -07:00
Erik Eckstein
71a642e51b stdlib, SIL optimizer: use the SIL copy-on-write representation in the Array types.
Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice.
The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array.
The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation".

The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state.

All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer object side-table indicates if the buffer is mutable or not.

Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
2020-06-08 15:02:22 +02:00
Erik Eckstein
1559fe333f SIL: a new library intrinsic to "finalize" array literals
For COW support in SIL it's required to "finalize" array literals.
_finalizeUninitializedArray is a compiler known stdlib function which is called after all elements of an array literal are stored.
This runtime function marks the array literal as finished.

  %uninitialized_result_tuple = apply %_allocateUninitializedArray(%count)
  %mutable_array = tuple_extract %uninitialized_result_tuple, 0
  %elem_base_address = tuple_extract %uninitialized_result_tuple, 1
  ...
  store %elem_0 to %elem_addr_0
  store %elem_1 to %elem_addr_1
  ...
  %final_array = apply %_finalizeUninitializedArray(%mutable_array)

In this commit _finalizeUninitializedArray is still a no-op because the COW support is not used in the Array implementation yet.
2020-06-08 10:24:29 +02:00
Erik Eckstein
ea3b6a02af stdlib: rewrite Array/ContiguousArray logic for reserving capacity and creating a new buffer.
Share more code and avoid the large generic functions of ArrayProtocol.
The result is a significant code size win.
2020-01-09 16:17:38 +01:00
Robert Widmann
b9fe66e0e8 Add documentation to _DependenceToken 2019-11-21 10:48:18 -08: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
Ravi Kandhadai
6c662f7a6c [stdlib][Semantics annotation] Add ".empty" suffix to the semantics attribute of
array.init() and add semantics annotation to the compiler-intrinsic:
Array._allocateUninitializedArray
2019-03-05 17:09:34 -08:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Maxim Moiseev
cbf83ac04f [NFC][stdlib] Add FIXME markers to simplify audit 2018-11-14 11:58:42 -08:00
Slava Pestov
f6c2caf64b stdlib: Add @inlinable to @inline(__always) declarations
These should be audited since some might not actually need to be
@inlinable, but for now:

- Anything public and @inline(__always) is now also @inlinable
- Anything @usableFromInline and @inline(__always) is now @inlinable
2018-11-13 15:15:07 -05:00
Ben Cohen
df995de0d6 [stdlib] Make KeyValuePairs fully inlinable (#19502)
* Move KVP into its own Swift file. Make it fully inlineable.

* Make _makeCollectionDescription an extension. Add KeyValue equivalent.
2018-09-24 17:46:32 -07:00
Karoy Lorentey
546c829491 [stdlib] _makeCollectionDescription: Make internal 2018-09-22 02:04:06 +01:00
Ben Cohen
ae6f5dd604 [stdlib] Add consuming/owned annotations to Collection implementations (#19360)
* Add consuming/owned annotations to Collection implementations

* Update SILOptimizer tests

* Fix access_marker_verify test

* XFAIL reconstruct_type_from_mangled_name
2018-09-21 12:06:56 -07:00
Lance Parker
ff9b80688f made initializeNewElements non-Optional 2018-07-10 11:05:27 -07:00
Lance Parker
4c3bc53a4c put back _sanityCheck 2018-07-09 10:18:17 -07:00
Lance Parker
0ccf21f9f1 remove _PointerFunction 2018-07-06 16:28:26 -07:00
Lance Parker
fd808f3ea7 [stdlib] De-gyb Arrays.swift.gyb (#16230)
De-gyb Array
2018-05-30 14:11:32 -07:00