Commit Graph

123 Commits

Author SHA1 Message Date
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
Dmitri Gribenko
8e886a3bdd stdlib: ranges: remove range protocols
The RangeProtocol was a very weak and fragile abstraction because it
didn't specify the interpretation of the endpoints.  To write a
non-trivial algorithm, one usually needed to consult that information.
The standard library code only actually worked correctly with half-open
and closed ranges (and didn't handle fully open ranges, for example).

The other two protocols, HalfOpenRangeProtocol and ClosedRangeProtocol,
were only used for code sharing, and present an ABI burden.  We can use
gyb instead.
2016-04-22 18:15:06 -07:00
Dave Abrahams
47a870cc50 [stdlib] Use location/formLocation for all index movement 2016-04-21 17:13:41 -07:00
Dmitri Gribenko
41e94ac655 stdlib: fix a bug in CountableClosedRange._customContainsEquatableElement() and add better tests for range types
The tests are still not thorough enough, but this is a start.
2016-04-21 14:00:18 -07:00
Dmitri Gribenko
6bd5a979e4 stdlib: ranges: remove requirements from RangeProtocol that only have one implementation 2016-04-20 15:08:34 -07:00
Dmitri Gribenko
26b24d000d stdlib: ranges: add @warn_unused_result and propagate documentation from other places 2016-04-20 14:59:10 -07:00
Dmitri Gribenko
14bb1ebf03 stdlib: ranges: move common printing and reflection code to protocols that exist solely for implementation sharing
We usually don't put descriptions and mirrors into default
implementations, but these protocols are special because users are not
allowed to declare conformances to them.
2016-04-20 11:37:39 -07:00
Dmitri Gribenko
94964eccb8 stdlib: ranges: remove duplicate code
These definitions already exist in protocols for ranges.
2016-04-20 11:01:47 -07:00
Dmitri Gribenko
1aeccae6e8 stdlib: ranges: add the cheapest possible implementations of isEmpty
These methods are not protocol extensions because the protocol
extensions would need ambiguity breakers between Collection and range
protocols anyway.
2016-04-20 10:37:01 -07:00
Dave Abrahams
3dec7c1fb8 [stdlib] Improve a doc comment 2016-04-19 11:16:01 -07:00
Dmitri Gribenko
3d4378c86c stdlib: add ABI fixmes 2016-04-18 17:15:09 -07:00
Dmitri Gribenko
10697f939f Merge commit '510f29abf77e202780c11d5f6c7449313c819030' into swift-3-indexing-model 2016-04-14 13:45:27 -07:00
Dave Abrahams
4bbcf34d31 [stdlib] Generic conversion between range types 2016-04-12 17:43:24 -07:00
Dave Abrahams
df81c3e4ca [stdlib] 80-column fixes 2016-04-12 16:57:49 -07:00
Dave Abrahams
ed25c811aa [stdlib] Keep uncheckedBounds out of examples.
We should go out of our way not to encourage its use.
2016-04-12 16:55:07 -07:00
Dave Abrahams
48fbd6b974 [stdlib] Reorder protocol conformances 2016-04-10 11:54:33 -07:00
Dave Abrahams
6e75d97f00 [stdlib] Clean up redundant protocol conformance 2016-04-10 11:50:19 -07:00
Nate Cook
97b048171c [New indexing model] Hide Range/CountableRange subscripts
Prevents the overloads that cause ambiguity conflicts for integer-based
ranges from being included in the stdlib generated header.
2016-04-08 16:32:20 -05:00
Nate Cook
f947c7c81c [New indexing model] Finish documentation revisions
- Replaced RandomAccessIndex mentions from Strideable documentation
  with stronger guarantees if Stride conforms to Integer.
- Other cleanup and revisions.
2016-04-08 14:04:34 -05:00
Nate Cook
afd064a335 [New indexing model] Revisions to range documentation 2016-04-08 00:59:26 -05:00
Nate Cook
d072b23ffa [New indexing model] Revise documentation for ranges 2016-04-07 16:53:56 -05:00
Dave Abrahams
94771b4a39 [stdlib] Update indexing model doc comments
Also fix some diagnostics
2016-04-06 17:34:00 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Dave Abrahams
be46928ceb [stdlib] Make Range == more generic
This enables equality comparison of Range<T> and CountableRange<T>.
2016-04-06 11:03:04 -07:00
Dave Abrahams
94e944ba33 [stdlib] Update Range comments 2016-04-06 11:03:04 -07:00
Dave Abrahams
5864117b1b [stdlib] De-underscore Range.init(uncheckedBounds:) 2016-04-06 09:20:30 -07:00
Dave Abrahams
8e5c9726cc Kill an obsolete FIXME 2016-04-05 16:34:37 -07:00
Dave Abrahams
d417680993 [stdlib] Kill mistakenly committed requirement 2016-04-05 16:33:06 -07:00
Dave Abrahams
db03708a3d [stdlib] De-underscore Range protocols
There's really no excuse for keeping these hidden; they appear in public
APIs.
2016-04-05 16:32:15 -07:00
Slava Pestov
86d4c456f9 Sema: Assert that we don't try to do direct-to-storage access of properties in resilient types
Right now, the rule is that any access of a stored property from a
constructor or destructor through 'self' must go directly to storage,
skipping observers or getter/setter overrides.

This means that in particular, constructors of resilient types cannot
be @_transparent, or defined in an extension in another module.

Previously, this was only caught in IRGen when the @_transparent
function was inlined into a function from another module, which made
debugging difficult.

Now, we hit an assert in Sema in this case. Of course it should be a
diagnostic; we'll get there eventually.

We could partially lift the restriction, allowing convenience
initializers to be defined @_transparent or be added in extensions,
by having accesses of stored properties from convenience inits go
through accessors. This would be safe, because at that point, we must
already have performed a self.init() delegation, however it would
potentially break existing code in subtle ways.

Also, this patch marks the RangeIterator and Range types @_fixed_layout,
since they define @_transparent initializers and this tripped the
new assert. Furthermore, note that the @_transparent initializer
must be versioned because it is inlined into another versioned
@_transparent function.
2016-04-04 21:08:02 -07:00
Slava Pestov
7b91cbd551 stdlib: Add @_versioned attributes needed for resilient build 2016-04-01 13:07:18 -07:00
Slava Pestov
bd8459c433 stdlib: Add some @inline(__always) annotations to make optimizer tests pass when the library is built without -sil-serialize-all 2016-03-28 20:08:12 -07:00
Dave Abrahams
a5c3c63c3d [stdlib] Indexing model: nix RangeOfStrideable
Instead, use CountableRange which is constrained to have a Strideable
Bound whose Stride conforms to Integer.
2016-03-28 17:06:09 -07:00
Dave Abrahams
8d9e62b274 [stdlib] indexing model: rename next/previous
I'm not too satisfied with the names for the updating: versions, but
this is a start.
2016-03-22 17:13:54 -07:00
Dave Abrahams
3b41409bb6 [stdlib] indexing model: Range indexing diagnostics 2016-03-22 09:22:58 -07:00
Dmitri Gribenko
c05afc7739 stdlib: more _stdlibAssert => _debugPrecondition renaming 2016-03-21 15:11:05 -07:00
Dave Abrahams
88a9f2e628 [stdlib] indexing model: Complete Interval/Range merge
Down to 22 failures; only 5 in stdlib tests
2016-03-18 10:04:09 -07:00
Dave Abrahams
c5031aacf2 [stdlib] indexing model: Overload bug workarounds
rdar://25214598
2016-03-17 14:45:15 -07:00
Max Moiseev
03cbb49982 [stdlib] _stdlibAssert => _debugPrecondition 2016-03-17 12:16:19 -07:00
Dave Abrahams
48d33f19b6 [stdlib] indexing model: Internal Naming
"Pos" is no longer a good name for that generic parameter.
2016-03-17 02:59:02 -07:00
Dave Abrahams
68d68114ca [stdlib] indexing model: Drop redundant Range !=
The default is already being generated for us.
2016-03-16 17:13:36 -07:00
Dave Abrahams
3fbf6911dc [stdlib] indexing model: Factor Range some more 2016-03-16 17:04:15 -07:00
Dave Abrahams
f49ea36820 [stdlib] indexing model: Factor Range 2016-03-16 16:46:00 -07:00
Dave Abrahams
ed3c537638 [stdlib] indexing model: Check Range invariants 2016-03-16 15:59:11 -07:00
Dave Abrahams
f493b54e44 [stdlib] indexing model: Interval/Range merge
This is step 1; we still need to introduce ClosedRange.
2016-03-16 15:59:10 -07:00
Dmitri Gribenko
82595aa57b New indexing model: improve migration attributes 2016-03-13 22:05:01 -07:00
Shawn Erickson
fe9482b6bb New indexing model: WIP fixed compile issues in various stdlib tests 2016-03-13 21:00:01 -07:00
Dmitri Gribenko
3cde854287 Merge remote-tracking branch 'origin/master' into swift-3-indexing-model 2016-03-12 01:11:32 -08:00
Dmitri Gribenko
dfedb6d418 New indexing model: make ... return RangeOfStrideable, this seems to match expectations better 2016-03-11 18:40:29 -08:00
Dmitri Gribenko
1430a72c9c New indexing model: add an optimized '!=' function for RangeOfStrideable 2016-03-11 18:07:23 -08:00