Commit Graph

105 Commits

Author SHA1 Message Date
Guillaume Lessard
e5c7dfc430 [temporary] disable spans over inline elements
unblocks building a debug-mode standard library
2025-03-25 08:55:53 -07:00
Guillaume Lessard
7b035936e4 [temporary] disable spans over inline elements 2025-03-21 17:26:29 -07:00
Guillaume Lessard
940628a23a [stdlib] add newly-required unsafe annotations 2025-03-10 15:20:51 -07:00
Guillaume Lessard
264747ac77 [stdlib] add span property to CollectionOfOne 2025-03-10 08:51:56 -07:00
Kuba Mracek
92b075b518 [embedded] Drop several #ifs and fatalError()s by adding an unavailable ExpressibleByStringInterpolation String conformance 2023-09-16 13:40:25 -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
Kuba (Brecka) Mracek
404badb49a Introduce SWIFT_ENABLE_REFLECTION to turn on/off the support for Mirrors and reflection (#33617) 2021-09-08 13:08:13 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01: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
John McCall
8be4ec32e6 Protocol requirement overrides must match in mutating-ness.
Without this change, SILGen will crash when compiling a use of the
derived protocol's requirement: it will instead attempt to use
the base protocol's requirement, but the code will have been
type-checked incorrectly for that.

This has a potential for source-compatibility impact if anyone's
using explicit override checking for their protocol requirements:
reasonable idioms like overriding a mutating requirement with a
non-mutating one will no longer count as an override.  However,
this is arguably a bug-fix, because the current designed intent
of protocol override checking is to not allow any differences in
type, even "covariant" changes like making a mutating requirement
non-mutating.  Moreover, we believe explicit override checking in
protocols is quite uncommon, so the overall compatibility impact
will be low.

This also has a potential for ABI impact whenever something that
was once an override becomes a non-override and thus requires a
new entry.  It might require a contrived test case to demonstrate
that while using the derived entry, but it's quite possible to
imagine a situation where the derived entry is not used directly
but nonetheless has ABI impact.

Furthermore, as part of developing this patch (earlier versions of
which used stricter rules in places), I discovered a number of
places where the standard library was unintentionally introducing
a new requirement in a derived protocol when it intended only to
guide associated type deduction.  Fixing that (as I have in this
patch) *definitely* has ABI impact.
2019-01-30 01:33:09 -05:00
Karoy Lorentey
aedf2b91ad [stdlib] CollectionOfOne.subscript: Replace setter with _modify 2018-10-19 11:32:43 +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
Ben Cohen
dd2f3b4386 [stdlib] More inalienable auditing (#18925)
* Removing FIXME from methods also marked always/never

* Unavailable/deprecated things don't need inlining

* Trivial implementations

* Enum namespaces

* Unsafe performance of opaque/raw pointer

* Dump doesn't need to be fast

* Error paths shouldn't require inlining

* Consistency with surrounding code

* Lazy performance needs specialization
2018-08-23 18:52:21 -07:00
Ben Cohen
422ff83907 Inlineable: trivial implementation 2018-07-06 12:05:30 -07:00
Ben Cohen
a4230ab2ad [stdlib] Update stdlib to 4.0 and reorganize compatibility shims (#17580)
* Update stdlib to 4.0 and move all compatibility shims into a dedicated source file
2018-06-29 06:26:52 -07:00
Ben Cohen
92b6d8cb8f Remove inlineability from mirrors (#17476) 2018-06-25 19:54:13 -07:00
Ben Cohen
2eec236f13 Move two more Iterators into nested types 2018-06-21 16:28:20 -07:00
Nate Cook
61c79f33c0 [stdlib] Address feedback from @airspeedswift and @CodaFi 2018-04-11 13:03:36 -05:00
Nate Cook
b6a0d9ed26 [stdlib] Documentation revisions
- Make RawRepresentable Codable abstracts distinguishable
- Make the UnboundedRange example a little more user friendly
- Correct the RangeReplaceableCollection example description
- Revise CaseIterable discussion
2018-04-11 11:34:51 -05:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Ben Cohen
9ee856f386 [stdlib][WIP] Eliminate (Closed)CountableRange using conditional conformance (#13342)
* Make Range conditionally a Collection

* Convert ClosedRange to conditionally a collection

* De-gyb Range/ClosedRange, refactoring some methods.

* Remove use of Countable{Closed}Range from stdlib

* Remove Countable use from Foundation

* Fix test errors and warnings resulting from Range/CountableRange collapse

* fix prespecialize test for new mangling

* Update CoreAudio use of CountableRange

* Update SwiftSyntax use of CountableRange

* Restore ClosedRange.Index: Hashable conformance

* Move fixed typechecker slowness test for array-of-ranges from slow to fast, yay

* Apply Doug's patch to loosen test to just check for error
2018-02-01 20:59:28 -08:00
ben-cohen
6d22ded529 Part the first 2017-11-30 20:11:18 -08:00
Ben Cohen
c4f0b5fe94 [stdlib] Adopt conditional conformance for Indices, Slice, ReversedCollection (#12913)
* Refactor Indices and Slice to use conditional conformance

* Replace ReversedRandomAccessCollection with a conditional extension

* Refactor some types into struct+extensions

* Revise Slice documentation

* Fix test cases for adoption of conditional conformances.

* [RangeReplaceableCollection] Eliminate unnecessary slicing subscript operator.

* Add -enable-experimental-conditional-conformances to test.

* Gruesome workaround for crasher in MutableSlice tests
2017-11-30 09:10:22 -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
ef6b5c4795 Add missing @_inlineable attributes and deinits 2017-09-29 11:26:56 -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
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Nate Cook
559092bbf2 [stdlib] Revise stdlib documentation comments
- Expand pre-example explanations
- Update documentation for SE-0118
- Removing remaining 'iff' usage
- Revise Array discussion
- Fix formIndex(_:offsetBy) parameter formatting
- Improve index/formIndex(_:offsetBy:(limitedBy:)?) discussion
- Update Quick Look discussions
- Fixes grammar inconsistencies
- Adds parameter / return documentation
- Adds and expands on examples
- Revises AnyObject discussion for new `id` bridging rules
- Revise readLine, print, and assertion functions
- Add missing docs to String index-moving methods
2016-08-05 16:07:46 -05:00
Rintaro Ishizaki
6ef62f3c73 [stdlib] Better diagnosis for unavailable APIs
Added tests for expected-error and fix-its.

- Add arguments signature regardless that is the same as before.
  Because the error message looks more natural.
  e.g. "makeIterator" => "makeIterator()",
  "replaceSubrange" => "replaceSubrange(_:with:)"
- Any${ExistentialCollection}.underestimateCount() was a method, not
  computed property.
- 'LazySequenceType' has been renamed to 'LazySequenceProtocol', but not
  'LazyCollectionProtocol'
- Streamable.writeTo(_:) had no argument label.
- Fixed typo in print() debugPrint() error message (not working for now)
- Repeated.init(): changed `renamed` to `message` because the arugment
  order has changed.
- Marked `public` for some unavailable method on `Sequence`
- Sequence.split(_:maxSplit:allowEmptySlices) was replaced with
  split(separator:maxSplits:omittingEmptySubsequences:),
  not split(separator:omittingEmptySubsequences:isSeparator:)
- Sequence.split(_:allowEmptySlices:isSeparator) was replaced with
  split(maxSplits:omittingEmptySubsequences:isSeparator:),
  not split(_:omittingEmptySubsequences:isSeparator:)
- Sequence.startsWith(_:isEquivalent:) or startsWith(_:) had no label on
  the first argument.
- transcode(_:_:_:_:stopOnError), not transcode(_:_:_:_:stoppingOnError)
- Removed mutating methods from UnsafePointer.
  alloc(_:), dealloc(_:), setter:memory, initialize(_:), destroy(),
  and destroy(_:)
2016-07-01 14:52:09 +09:00
Patrick Pijnappel
daec2dae00 Resolve conflicts with master 2016-05-24 19:21:04 +02:00
Nate Cook
44b2d56a7f [stdlib] Revise documentation for string-related types
This documentation revision covers a large number of types & protocols:
String, its views and their indices, the Unicode codec types and protocol,
as well as Character, UnicodeScalar, and StaticString, among others.

This also includes a few small changes across the standard library for
consistency.
2016-05-22 03:04:22 -05:00
Dmitri Gribenko
d591f9cf7a stdlib: remove most uses of @warn_unused_result, which does nothing now
I kept the one on sorted(), because that one requires a less trivial
change.
2016-05-19 18:39:39 -07:00
Dmitri Gribenko
a8f076d7f0 stdlib: use _precondition(), not precondition()
precondition(), when used in the standard library, does not respect the
debug/release build setting of the module or application importing the
standard library.
2016-05-12 16:13:41 -07:00
Patrick Pijnappel
4419614be4 Move post-nil guarantee to separate line for Iterators' next() 2016-05-08 21:36:39 +02:00
Patrick Pijnappel
ab9e74cba3 Resolve conflicts with upstream 2016-05-05 08:55:34 +02:00
Nate Cook
62955b0d3b [stdlib] Fix copypasto 2016-05-04 10:19:12 -05:00
Dmitri Gribenko
f82ca83a68 stdlib: CollectionOfOne: fixes for index movement and tests 2016-05-03 18:44:34 -07:00
Mark Lacey
e03d334b68 Use Builtin.unreachable() in unavailable functions.
Saves a bit of code size in the standard library by eliminating some
static strings and function calls.

rdar://problem/25767016
2016-05-02 21:30:25 -07:00
Dave Abrahams
0d68b3a4af [stdlib] Generate RandomAccessCollection defaults
The defaults we were generating for Collection and
BidirectionalCollection didn't make any sense, because if you could do
that strideable arithmetic then you essentially had random access.
Instead we constrain the defaults to apply to RandomAccessCollection
where the Indices are a CountableRange.
2016-05-02 11:35:32 -07:00
Dave Abrahams
8d809993be [stdlib] Use CountableRange for Indices more
This will be much more efficient than the default, when it applies,
because it doesn't need to carry a reference to underlying collection
storage.
2016-05-01 19:42:40 -07:00
Dave Abrahams
9bee5d182f [stdlib] location/formLocation => index/formIndex 2016-04-26 17:46:16 -07:00
Dave Abrahams
47a870cc50 [stdlib] Use location/formLocation for all index movement 2016-04-21 17:13:41 -07:00
Max Moiseev
590f62f3bd [stdlib][swift-3-indexing-model] introducing new LazyCollections
- Instead of just one there are now three:
  - LazyCollection
  - LazyBidirectionalCollection
  - LazyRandomAccessCollection
- ReversedCollection now conforms to BidirectionalCollection
- Lazy tests compile and run (#if'ed pieces that don't typecheck)
2016-04-08 11:06:05 -07:00
Nate Cook
6b77c6a979 [New indexing model] Update documentation comments with new APIs
Most of these were successor() -> successor(of:).
2016-04-08 01:01:58 -05:00
Max Moiseev
b7a1b1d1e0 Revert "[stdlib][swift-3-indexing-model] introducing new LazyCollections"
This reverts commit 5ad441f35a.
2016-04-06 13:07:31 -07:00
Max Moiseev
5ad441f35a [stdlib][swift-3-indexing-model] introducing new LazyCollections
- Instead of just one there are now three:
  - LazyCollection
  - LazyBidirectionalCollection
  - LazyRandomAccessCollection
- ReversedCollection now conforms to BidirectionalCollection
- Lazy tests compile and run (#if'ed pieces that don't typecheck)
2016-04-06 10:11:30 -07:00