Commit Graph

7628 Commits

Author SHA1 Message Date
Joe Pamer
828eb68e72 Commit DaveA's API changes to 'print', along with the compiler changes necessary to support them.
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.

Swift SVN r30976
2015-08-04 01:57:11 +00:00
David Farler
311baf73cf Index protocol extensions
- Remove free Swift functions for advance and distance and replace
  them with protocol extension methods:
  - advancedBy(n)
  - advancedBy(n, limit:)
  - distanceTo(end)
- Modernize the Index tests
  - Use StdlibUnittest
  - Test for custom implementation dispatch

Perf impact: No significant changes reported in the
Swift Performance Measurement Tool.

rdar://problem/22085119

Swift SVN r30958
2015-08-03 20:06:44 +00:00
Dave Abrahams
cc2643cf3a [stdlib] kill off a missed ".array"
Swift SVN r30915
2015-08-01 14:27:17 +00:00
Slava Pestov
08f1421a5a Import latest compiler crashers from practicalswift
68% are already fixed, including all those marked as beta 4 regressions.

Swift SVN r30914
2015-08-01 08:31:45 +00:00
Chris Lattner
d3b1bcbd73 update validation tests for diagnostics changes.
Swift SVN r30906
2015-08-01 05:01:49 +00:00
Dave Abrahams
ad43a596bd [stdlib] Retire the old lazy subsystem...
...replacing it with the new, after passing API review!

* The lazy free function has become a property.

* Before we could extend protocols, we lacked a means for value types to
  share implementations, and each new lazy algorithm had to be added to
  each of up to four types: LazySequence, LazyForwardCollection,
  LazyBidirectionalCollection, and LazyRandomAccessCollection. These
  generic adapters hid the usual algorithms by defining their own
  versions that returned new lazy generic adapters. Now users can extend
  just one of two protocols to do the same thing: LazySequenceType or
  LazyCollectionType.

* To avoid making the code duplication worse than it already was, the
  generic adapters mentioned above were used to add the lazy generic
  algorithms around simpler adapters such as MapSequence that just
  provided the basic requirements of SequenceType by applying a
  transformation to some base sequence, resulting in deeply nested
  generic types as shown here. Now, MapSequence is an instance of
  LazySequenceType (and is renamed LazyMapSequence), and thus transmits
  laziness to its algorithms automatically.

* Documentation comments have been rewritten.

* The .array property was retired

* various renamings

* A bunch of Gyb files were retired.

Swift SVN r30902
2015-08-01 03:52:13 +00:00
David Farler
91d182154f Explode Algorithm.swift.gyb into separate test files
- Added CollectionType and SequenceType.swift.gyb
- Added Slice.swift.gyb
- Added a template file for shared lazy flatMap code between sequences
  and collections
- Moved some test structs into the respective Check* files in
  StdlibUnittest.
- Slice.swift.gyb is still too slow for Debug-Assert stdlib builds.
  I've added a requirement to use the optimized standard library but
  we should split this file out even further.

rdar://problem/22095015

Swift SVN r30894
2015-08-01 00:34:58 +00:00
Dmitri Hrybenko
d9088afe4b stdlib: add MutableSlice
See doc comments on MutableSlice for more information about what it is.

MutableSlice was one of the reasons to clarify and tighten index
invalidation rules.  After that change, existing MinimalCollection
test types were performing checks that are too strict according to the
model.  Existing algorithms and collections could provide them, but not
MutableSlice.  This commit updates MinimalCollection types to perform
index invalidation checks that correspond to new rules.

Part of rdar://20722366.  This commit adds the type, but does not wire
it up completely yet.

Swift SVN r30839
2015-07-31 03:21:56 +00:00
Dmitri Hrybenko
61b93564e9 Eliminate UnsafeMutableBufferPointer from _withUnsafeMutableBufferPointerIfSupported
The type checker hits a recursion when checking the conformance to
CollectionType in UnsafeMutableBufferPointer, which requires
_withUnsafeMutableBufferPointerIfSupported, which mentions
UnsafeMutableBufferPointer.  The easiest fix for now is to break the
recursion in the library.

Reverting this change is tracked by: <rdar://problem/21933004> Restore
the signature of _withUnsafeMutableBufferPointerIfSupported() that
mentions UnsafeMutableBufferPointer

Swift SVN r30838
2015-07-31 03:21:54 +00:00
Chris Lattner
4718f29742 testcase fixed by recent changes.
Swift SVN r30827
2015-07-31 00:15:43 +00:00
Joe Groff
73b7f89499 Also, don't test for a trap message in release builds that don't trap with messages.
Fixes rdar://problem/22081452.

Swift SVN r30825
2015-07-30 23:47:48 +00:00
Joe Groff
7f86227350 Don't expect crash output if test isn't expected to crash.
Speculative fix for rdar://problem/22081452.

Swift SVN r30822
2015-07-30 23:35:42 +00:00
Joe Groff
4cb34410fc stdlib: Don't reserve capacity for filter result array.
Swift SVN r30802
2015-07-30 17:07:37 +00:00
Joe Groff
0c39db22bc stdlib: Implement strict 'map', 'filter', and 'flatMap' as 'rethrows' operations.
Replace the Lazy-based implementations with open-coded implementations based on the _UnsafePartiallyInitializedContiguousArrayBuffer builder from the previous commit, so that we have control over the early-exit flow when an error interrupts the operation.

Swift SVN r30794
2015-07-30 05:28:34 +00:00
Joe Groff
eec59477ae stdlib: Factor _copy*ToNativeArrayBuffer into a general-purpose "builder" for ContiguousArrayBuffer.
This makes the code for efficiently initializing array buffers in-place more accessible to the rest of the standard library, and should also provide a performance boost for _copySequenceToNativeArrayBuffer, which had been implemented as a naive append loop, by handling reallocating the buffer when necessary when initializing from a sequence that underestimates its count.

Swift SVN r30793
2015-07-30 05:28:30 +00:00
Slava Pestov
29409b45d6 Add testcase for a bug that seems to be fixed
Swift SVN r30774
2015-07-29 18:23:21 +00:00
Slava Pestov
f97f331b6a We shouldn't be using -verify in compiler_crashers
Swift SVN r30773
2015-07-29 18:23:19 +00:00
Slava Pestov
f435510474 Add testcase for a bug that seems to be fixed
Swift SVN r30759
2015-07-29 07:17:21 +00:00
Dmitri Hrybenko
0c88bd93e9 stdlib: more tests for {Set,Dictionary}.removeAtIndex
Swift SVN r30702
2015-07-27 23:12:00 +00:00
Jordan Rose
63b0cf6997 [test] Remove -verify from former compiler_crasher.
(changed in my previous commit)

Swift SVN r30699
2015-07-27 21:59:22 +00:00
Jordan Rose
9e5631c50b [test] More type annotations for faster builds.
Swift SVN r30697
2015-07-27 20:32:59 +00:00
Jordan Rose
b378a5043f [stdlib] Dictionary and Set's removeAtIndex should return the element.
For Dictionary, that's a (KeyType, ValueType) pair. For Set, that's just
the set element type. This is more consistent with the removeAtIndex on
RangeReplaceableCollectionType (which Dictionary and Set don't conform to).

rdar://problem/20299881

Swift SVN r30696
2015-07-27 20:32:55 +00:00
Dave Abrahams
f37d607a13 Revert "stdlib: remove FlattenCollection -- it does not model CollectionType properly."
Actually we hadn't nailed down the indexing model sufficiently; now we
have.

This reverts r30617.

Swift SVN r30694
2015-07-27 19:33:15 +00:00
Slava Pestov
ccf21ff90a Revert "Sema: Fix infinite recursion when associated type default references itself"
This reverts revision r30688. The patch needs more work, because it flags a
valid case as circular, see r15054, "Relax restriction on indirectly-self-
recursive protocol conformances.  (rdar://problem/16306715)".

Swift SVN r30690
2015-07-27 06:41:10 +00:00
Slava Pestov
29d3f8f400 Sema: Fix infinite recursion when associated type default references itself
Fixes <rdar://problem/20985232>.

Swift SVN r30688
2015-07-27 05:05:05 +00:00
Dmitri Hrybenko
6ec144738e stdlib: Add more APIs to _stdlib_AtomicInt
Requested in rdar://17171396

Swift SVN r30687
2015-07-27 04:18:13 +00:00
Dmitri Hrybenko
49adc5b362 Allow running iOS tests that don't require a device without a device attached
Swift SVN r30679
2015-07-27 00:42:46 +00:00
Slava Pestov
65b317fa36 Sema: Fix infinite recursion when checking if class with circular inheritance has failable initializer
Fixes <rdar://problem/19919421>.

Swift SVN r30677
2015-07-27 00:40:45 +00:00
Slava Pestov
1a34667419 AST: Fix a couple of crashes with nested generic types
- When we walk up through parent types of 'this', we also have to walk up
  the parent contexts of 'gpContext', otherwise an assertion fires.

- getSuperclass() needs to map generic type parameters of the parent
  type even if the superclass is not generic.

Swift SVN r30676
2015-07-27 00:40:43 +00:00
Slava Pestov
7dd472686a Sema: When recursively visiting a BoundGenericType, it may not have a generic signature yet
Let the original call diagnose any problems and just return successfully
without crashing.

Swift SVN r30675
2015-07-27 00:40:41 +00:00
Slava Pestov
7bca00afc1 Sema: When adding implicit constructors, bail out if superclass is invalid
Swift SVN r30674
2015-07-27 00:40:38 +00:00
Slava Pestov
5cc4f2b93d Sema: Use isTypeChecking() to avoid recursively validating EnumElementDecls
Validating the argument type might validate the enum decl in malformed (or
maybe even some valid?) code. We would call computeTwice() in this case,
leading to a crash.

Also clean up some test cases.

Swift SVN r30673
2015-07-27 00:40:37 +00:00
Chris Lattner
afe762c882 remove diagnostic messages from expected- markers that change. If the specifics
being tested are important, they should be tested in the main testsuite.  Leave
the 'word' validation messages.


Swift SVN r30667
2015-07-26 22:26:59 +00:00
Chris Lattner
eff5cb3d48 remove a -verify line from a validation test.
Swift SVN r30663
2015-07-26 21:47:27 +00:00
Dmitri Hrybenko
69531fd8f8 Restore FixedPointDiagnostics.swift.gyb, it is a useful test
1. We have complex logic in stdlib/public/core/FixedPoint.swift.gyb that emits
or hides certain initializers on integer types based on the bit width
combination.  We check that those APIs are indeed present or absent in cases we
expect.

All of [U]Int{8,16,32,64,} initializers, labelled and unlabelled.

(swift) UInt16(-10 as Int32)
<REPL Input>:1:1: error: integer overflows when converted from 'Int32' to 'UInt16'
UInt16(-10 as Int32)

(swift) UInt16(truncatingBitPattern: -10 as Int32)
// r3 : UInt16 = 65526

(swift) UInt16(truncatingBitPattern: -10 as Int16)
<REPL Input>:1:1: error: cannot invoke initializer for type 'UInt16' with an argument list of type '(truncatingBitPattern: Int16)'
UInt16(truncatingBitPattern: -10 as Int16)
<REPL Input>:1:1: note: overloads for 'UInt16' exist with these partially matching parameter lists: (Int16), (bitPattern: Int16)

A slight change in the type combination dramatically changes the available
overload set.  You can’t check this with one or two tests and be confident that
every source/destination combination is correct.

2. We check that the APIs above are present or absent regardless of the target
platform so that the code is portable (for example, because Int64 -> Int is a
truncating operation on at least one platform, the corresponding “truncating”
initializer is available for portability on 64-bit platforms, even though it is
not actually truncating there.)

3. We rely on ambiguity in the overload set of “+“ and “-“ for certain
combinations of arguments to disallow mixed-sign arithmetic.  Again, these
ambiguities rely on a tricky combination of protocols, associated types, the
way those associated types are defined by our integer types, and overload
resolution rules in the type checker.

4. The test also checks migration facilities for Word and UWord.

Swift SVN r30655
2015-07-26 06:56:47 +00:00
Chris Lattner
b1f77b5b18 the default args recovery change fixed this crasher.
Swift SVN r30646
2015-07-26 02:29:16 +00:00
Slava Pestov
0af2b4709f Sema: Fix crash with protocol erroneously nested inside generic class
The protocol Self parameter is the last generic parameter in the signature,
not the first. While we don't allow protocols nested inside generic classes,
we would still crash in member type lookup from this.

Fixes <rdar://problem/21287703>.

Swift SVN r30635
2015-07-25 19:55:12 +00:00
Slava Pestov
e373a559c6 Sema: Fix type member lookup if generic signature validation fails
When validateGenericFuncSignature() returns true, finalizeGenericParamList()
is never called. Name lookup, via PartialGenericTypeToArchetypeResolver would
return a dependent member type of the generic type parameter type, not an
archetype as expected in this case. This would later on lead to a crash in
ReplaceDependentTypes if the function body contained a reference to such a
member type.

Fix this by marking the GenericTypeParamDecls as invalid in this case, and
returning an ErrorType from PartialGenericTypeToArchetypeResolver if given
an invalid GenericTypeParamDecl.

While we're at it, there was an unused isInvalid local variable in
TypeCheckDecl::visitFuncDecl(). It was written to but never read. Replace
the writes with calls to setInvalid().

Fixes <rdar://problem/19620340>.

Swift SVN r30632
2015-07-25 19:55:07 +00:00
Chris Lattner
746e5aac49 remove this test, it isn't a good test.
Swift SVN r30627
2015-07-25 15:22:34 +00:00
Dmitri Hrybenko
7d61186d85 Revert "fix the validation test failure due to producing 'aka' more often."
... and actually fix the test.

Swift SVN r30625
2015-07-25 07:26:21 +00:00
Chris Lattner
649e5f937d generalize the existing ? and + constraints on expected diagnostics to
a simpler and more general * constraint.  This paves the way for other improvements.



Swift SVN r30622
2015-07-25 05:23:30 +00:00
Chris Lattner
57634fe8b9 fix the validation test failure due to producing 'aka' more often.
Swift SVN r30619
2015-07-25 03:59:18 +00:00
Dmitri Hrybenko
78222237e0 stdlib: remove FlattenCollection -- it does not model CollectionType properly.
An index of a FlattenCollection is composed of two: an index to the
current chunk and an index within that chunk.  So you take the
startIndex, and advance it to the second chunk; call the result idx1.
You take startIndex again, and advance it the same number of steps; call
the result idx2:

let idx1 = flatMapCollection.startIndex.advancedBy(10)
let idx2 = flatMapCollection.startIndex.advancedBy(10)

idx1 and idx2 have to compare equal according to collection and index
axioms.  But this can't be cheaply implemented.  Every index contains an
index into the inner collection.  So indices into two collections with
the same elements have to compare equal even though the collections
don't have any common history, they were merely created using the same
sequence of steps.

What currently happens is that you get random results depending on the
underlying collection kind.

rdar://21989896

Swift SVN r30617
2015-07-25 02:18:13 +00:00
Dmitri Hrybenko
739cceba3d stdlib: lazy FlattenCollection: don't invoke the closure as frequently
FlattenCollection used to evaluate the closure three times per element.
That's acceptable from the technical standpoint, given its lazy
semantics, but not acceptable in practice.  This commit fixes it to only
evaluate it two times when it is converted into an array.

This commit also improves tests.  The new checks used to fail before the
standard library was fixed.

But there are larger issues with FlattenCollection -- it does not model
CollectionType properly.  See next commit.

Swift SVN r30616
2015-07-25 02:18:12 +00:00
Dmitri Hrybenko
4b008e6f31 stdlib: rename RangeReplaceableCollectionType.splice() to insertContentsOf()
rdar://21972324

Swift SVN r30608
2015-07-25 00:36:39 +00:00
Dmitri Hrybenko
d97ac3e64c stdlib: rename RangeReplaceableCollectionType.extend() to appendContentsOf()
rdar://21972324

Swift SVN r30607
2015-07-25 00:36:37 +00:00
Doug Gregor
902f486c16 Don't allow superclass constraints to involve type parameters.
Fixes the crash in rdar://problem/21268222; eventually, we can support
this.

Swift SVN r30585
2015-07-24 18:45:06 +00:00
Dmitri Hrybenko
f5de8757e4 stdlib: remove Word and UWord
These types are leftovers from the early pre-1.0 times when Int and UInt
were always 64-bit on all platforms.  They serve no useful purpose
today.  Int and UInt are defined to be word-sized and should be used
instead.

rdar://18693488

Swift SVN r30564
2015-07-24 05:01:32 +00:00
Dmitri Hrybenko
1dbe75366b stdlib: add more tests for flatMap
These tests trigger a bug in a lazy flatMap() that I will fix in a later
commit, but I want to commit tests separately to show that they pass
with the eager flatMap().

Swift SVN r30559
2015-07-24 02:49:29 +00:00
Dmitri Hrybenko
0e299cd285 CoreMedia: add a test for CMTimeRange(start:duration:)
Patch by Adam Sonnanstine.

Swift SVN r30540
2015-07-23 16:23:51 +00:00