Commit Graph

175 Commits

Author SHA1 Message Date
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
Karoy Lorentey
94a7eeebe5 [stdlib] Document sources of code bloat 2020-12-11 18:31:00 -08:00
Karoy Lorentey
d1ef4c4386 [stdlib] Use [Closed]Range.init(_uncheckedBounds:) in more places
When the stdlib says not to check, it’s a good idea to actually not have any checking, so that we leave existing code paths unchanged. (And because we do trust that the stdlib is responsible about such things.)
2020-12-04 19:27:19 -08:00
Karoy Lorentey
c5c27c7c69 [stdlib] Add a missing debug precondition to [Closed]Range.init(uncheckedBounds:)
Unchecked APIs must still perform checks in debug builds to ensure that invariants aren’t violated.
(I.e., these aren’t a license to perform invalid operations — they just let us get rid of the checks when we know for sure they are unnecessary.)
2020-12-04 02:06:22 -08:00
Stephen Canon
457b9990e9 Add checks that the endpoints of partial ranges are not-NaN. (#33378)
We can't actually check for NaN (because the notion doesn't exist for Comparable), but we can require that the endpoint is non-exceptional by checking if it equals itself.
2020-08-10 14:06:46 -04:00
Gwynne Raskind
3ae3a7b459 Restore documentation for the pattern-matching operator as applied to RangeExpressions
The previous documentation of this operator in `Range` context was lost sometime during 2017. This new version is a simplified version of the original copy, with substantial inspiration taken from the present-day documentation of the same operator on `Optional`.

Fixes [SR-12842](https://bugs.swift.org/browse/SR-12842).
2020-05-20 03:46:48 -05: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
Patrick Pijnappel
87f02b173b [stdlib] Refactor range overlaps for performance 2019-05-04 09:15:21 +10:00
Max Moiseev
3b6c6cc0a5 Merge pull request #19532 from dlbuckley/SR-8649_ranges_codable
SR-8649: Range types conform to Codable
2019-01-14 14:38:32 -08:00
Dale Buckley
6ef7cca298 Added decodable error handling and changed from operator constructors to uncheckedBounds constructor 2018-12-03 08:44:04 +00:00
Harlan Haskins
615b8be990 [stdlib] Silence warnings related to uninhabited types
PR #20528 was merged yesterday, which inserts an `unreachable` in
functions with uninhabited parameters. Unfortunately this means any
statement in the function body, even ones that themselves are
never-returning or don't have any executable code, cause the warning.

Silence the warnings by deleting the bodies of these functions.
2018-11-30 13:50:16 -08:00
Dale Buckley
15e8fd2b0f Split Range Codable extensions down to Encodable and Decodable extensions 2018-11-12 14:58:11 +00:00
Dale Buckley
36319599ce Changed keyed archive mechanics to unkeyed archive mechanics 2018-10-30 09:57:14 +00:00
Dale Buckley
cca8bfba65 Renamed CodingKey raw names for better consistency 2018-09-25 16:31:27 +01:00
Dale Buckley
ac16b20a08 Codable cleanup 2018-09-25 14:45:23 +01:00
Dale Buckley
c45cdb7b7b Added Codable conformance for Range, ClosedRange, PartialRangeUpTo, PartialRangeThrough and PartialRangeFrom 2018-09-25 13:29:24 +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
412a045f71 [stdlib] JAFIA (#19074)
* Lazy/generic types needing specialization

* Move DictionaryLiteral typealias to compatibility shims file

* Static String is mainly transparent so needs no inlining

* UnboundedRange hack doesn't need inlining

* Unmanaged needs unsafe performance

* Onone enum namespace

* Output stream specialize-never and calls to lock/unlock don't need inlining

* no need for @_frozen on internal enum

* DropWhile needs lazy-performance
2018-09-19 19:41:06 -07:00
Nate Cook
efb0415a61 [stdlib] More documentation revisions (#18263)
- Fix error in `last(where:)` example
- Improve MemoryLayout, UnsafePointer, and integer operator discussions
- Clean up ranges and random APIs
- Revisions to overflow operators and the SignedNumeric requirements
- Standardize on 'nonoptional' in remaining uses
2018-08-08 00:25:09 -05: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
Ben Cohen
422ff83907 Inlineable: trivial implementation 2018-07-06 12:05:30 -07:00
Ben Cohen
c6b41a5ae5 Inlineable: protocol interface only 2018-07-06 12:03:34 -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
Doug Gregor
0f2de235c5 Merge pull request #15917 from DougGregor/evaluator
Introduce a simple request evaluator.
2018-06-12 10:41:08 -07:00
Doug Gregor
03aa3f189e [Standard library] Remove incorrect FIXME. 2018-06-01 08:56:18 -07:00
Karoy Lorentey
07c1b74cc4 [stdlib] Audit inlinability of Hashable implementations
As a general rule, it is safe to mark the implementation of hash(into:) and _rawHashValue(seed:) for @_fixed_layout structs as inlinable.

However, some structs (like String guts, Character, KeyPath-related types) have complicated enough hashing that it seems counterproductive to inline them. Mark these with @effects(releasenone) instead.
2018-05-31 18:24:59 -07:00
Nate Cook
7a4e0a32f6 [stdlib] Revise documentation
This includes various revisions to the APIs landing in Swift 4.2, including:
- Random and other randomness APIs
- Hashable changes
- MemoryLayout.offset(of:)
2018-05-18 11:31:54 -05:00
Ben Cohen
f421ec6082 [stdlib] Undeprecate Countable*Range (#16360)
* Undeprecate Countable*Range

* Remove check for deprecation warnings
2018-05-07 09:52:52 -07:00
Karoy Lorentey
0342ce3b96 [SE-0206][stdlib] Remove obsolete hashValue implementations
These are now synthesized by the compiler.
(Inlinability will be different, but that seems fine.)
2018-04-30 10:17:09 +01:00
Karoy Lorentey
0fb3e88110 [SE-0206][stdlib] De-underscore Hashable.hash(into:) 2018-04-24 17:42:42 +01:00
Karoy Lorentey
45cb8b7123 [SE-0206][stdlib] De-underscore Hasher 2018-04-24 17:42:42 +01:00
Nate Cook
b1ab7d89db [stdlib] Implement sequence/collection methods for searching from the end (#13337)
This implements the new last(where:), and lastIndex(of/where:) methods as
extensions on `BidirectionalCollection`, which partially implements SE-204.
The protocol requirements for `Sequence` and `Collection` as described
in the proposal need to wait until there's a solution for picking up the
specialized versions in types that conditionally conform to `BidirectionalCollection`.
2018-04-23 20:47:26 -05:00
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Karoy Lorentey
ccdc218cbd [stdlib] _Hasher: append => combine 2018-04-18 14:18:44 +01:00
Ben Cohen
ca7aea02e9 [stdlib] Add compatibility typealias for CountablePartialRangeFrom (#15989)
* Add compatibility typealias for CountablePartialRangeFrom
2018-04-17 15:48:54 -07: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
Karoy Lorentey
e485c1506b Merge pull request #15382 from lorentey/conditional-hashable2
[SE-0143][stdlib] Conditionally conform stdlib types to Hashable
2018-03-28 21:45:02 +01:00
Doug Gregor
e0d423a506 Add appropriate bounds to CountableClosedRange and CountableRange.
Previously, both CountableRange and CountableClosedRange required
their bound types to be Strideable with a Stride type that conforms to
SignedInteger. Those constraints were not present on the generic
typealiases that replaced these structs. Add them back now, which
fixes the GRDB source compatibility regression.

Fixes https://bugs.swift.org/browse/SR-6907 / rdar://problem/29066394.
2018-03-26 09:04:08 -07:00
Karoy Lorentey
08c3f8a610 [stdlib] Use _Hasher in conditional Hashable implementations
Implement _hash(into:) rather than hashValue.
2018-03-23 19:09:28 +00:00
Xiaodi Wu
fd0c387ea8 [stdlib] Mix lowerBound a little in Range.hashValue and ClosedRange.hashValue 2018-03-23 19:09:28 +00:00
Karoy Lorentey
6530c8870c [stdlib] Remove unnecessary attributes and clarify comments 2018-03-23 19:09:28 +00:00
Xiaodi Wu
c56882a26c [stdlib] Remove unnecessary doc comments from hashValue implementations
When implementing a protocol requirement, additional doc comments are
unnecessary unless there are additional semantics peculiar to the specific
implementation.

The manually propagated documentation had several problems, including copypasta
and inconsistent terminology.

Therefore, if `T.==` doesn't have any doc comments and the implementation of
`T.hashValue` is unremarkable, remove the unnecessary doc comment.
2018-03-23 19:09:27 +00:00
Karoy Lorentey
94e59a3112 [stdlib] Describe availability of new conformances and members
This assumes these will land in Swift 4.1; the attributes need to be adjusted if that turns out not to be the case.

It seems @available for protocol conformances is not yet functional. I added attributes for those anyway, marked with FIXME(conformance-availability).

# Conflicts:
#	stdlib/public/core/ExistentialCollection.swift.gyb
#	stdlib/public/core/Mirror.swift
2018-03-23 19:09:04 +00:00
Morten Bek Ditlevsen
c9337114d2 [WIP] Conditional conformance to Hashable for Optional, Dictionary and Array types. (#14247)
* Add conditional Hashable conformance to Optional, Dictionary, Array, ArraySlice and ContiguousArray

* Modified hashValue implementations
The hashValues are now calculated similar to the automatically synthesized values when conforming to Hashable.
This entails using _combineHashValues as values of the collections are iterated - as well as calling _mixInt before returning the hash.

* Added FIXMEs as suggested by Max Moiseev

* Use checkHashable to check Hashable conformance

* Use 2 space indentation

* Hashing of Dictionary is now independent of traversal order

* Added a test to proof failure of (previous) wrong implementation of Dictionary hashValue. Unfortunately it does not work.

* Removed '_mixInt' from 'hashValue' implementation of Optional and Array types based on recommendations from lorentey

* Another attempt at detecting bad hashing due to traversal order

* Dictionary Hashable validation tests now detect bad hashing due to dependence on traversal order

* Removed superfluous initial _mixInt call for Dictionary hashValue implementation.

* Add more elements to dictionary in test to increase the number of possible permutations - making it more likely to detect order-dependent hashes

* Added Hashable conformance to CollectionOfOne, EmptyCollection and Range types

* Fix indirect referral to the only member of CollectionOfOne

* Re-added Hashable conformance to Range after merge from master

* Change hashValue based on comment from @lorentey

* Remove tests for conditional Hashable conformance for Range types. This is left for a followup PR

* Added tests for CollectionOfOne and EmptyCollection

* Added conditional conformance fo Equatable and Hashable for DictionaryLiteral. Added tests too.

* Added conditional Equatable and Hashable conformance to Slice

* Use 'elementsEqual' for Slice equality operator

* Fixed documentation comment and indentation

* Fix DictionaryLiteral equality implementation

* Revert "Fix DictionaryLiteral equality implementation"

This reverts commit 7fc1510bc3.

* Fix DictionaryLiteral equality implementation

* Use equalElements(:by:) to compare DictionaryLiteral elements

* Added conditional conformance for Equatable and Hashable to AnyCollection

* Revert "Use 'elementsEqual' for Slice equality operator"

This reverts commit 0ba2278b96.

* Revert "Added conditional Equatable and Hashable conformance to Slice"

This reverts commit 84f9934bb4.

* Added conditional conformance for Equatable and Hashable for ClosedRange
2018-03-23 19:08:38 +00:00
Jordan Rose
9034ba617b Ban @_fixed_layout on enums in favor of @_frozen
In theory there could be a "fixed-layout" enum that's not exhaustive
but promises not to add any more cases with payloads, but we don't
need that distinction today.

(Note that @objc enums are still "fixed-layout" in the actual sense of
"having a compile-time known layout". There's just no special way to
spell that.)
2018-03-20 14:49:10 -07:00