Commit Graph

53 Commits

Author SHA1 Message Date
Nate Cook
2c244b9698 Fix precondition in UMRBP.initialize(as:fromContentsOf:)
This precondition checks to make sure that the content-providing
collection isn't larger than the allocated buffer, but was preventing
using a buffer that is the exact same size as the collection.
2023-10-25 17:17:36 -05:00
Guillaume Lessard
56c688777d [test] test overflow preconditions in collection copies 2022-09-09 18:02:43 -06:00
Guillaume Lessard
3bacc7c08f [test] check availability for before running test
- resolves rdar://91181948
2022-04-01 15:37:07 -06:00
Guillaume Lessard
cc60db78e1 [test] validate behaviour when copying from an empty buffer 2022-03-16 10:06:20 -06:00
Guillaume Lessard
4e3c1ea3ee [test] return early when test cannot succeed
- test requires Swift 5.7
- resolves rdar://89052037
2022-02-21 17:01:49 -07:00
Guillaume Lessard
85250c7d26 [test] withContiguousStorage methods on raw buffer types 2022-02-08 18:05:02 -07:00
Guillaume Lessard
eb56bf3a79 [gardening] deallocate buffer after use 2022-02-08 18:05:02 -07:00
Guillaume Lessard
cec7b4b44b [gardening] silence unused variable warning 2022-02-08 18:05:02 -07:00
Guillaume Lessard
72f4e65eba [test] assumingMemoryBound on raw memory buffers 2022-02-03 20:02:33 -07:00
Guillaume Lessard
9f2c4b5959 [test] rebinding raw memory 2022-02-03 20:02:33 -07:00
Guillaume Lessard
69aa3c36bc [test] rebinding typed memory to wider and narrower types 2022-02-03 20:02:33 -07:00
Karoy Lorentey
e2cfab4f28 [stdlib][test] Adopt availability macros in tests 2021-10-31 15:00:58 -07:00
Guillaume Lessard
23bed3118b [test] test UnsafeMutableBufferPointer.initialize(from: Slice<_>) 2021-07-28 14:32:57 -06:00
Saleem Abdulrasool
4cd81213c0 validation: make UnsafeBufferPointer Python3 friendly
The `<>` operator does not work in Python 3.  Switch it out for `!=`.
2020-07-13 15:56:07 +00:00
Mishal Shah
272c466e47 Update master to build with Xcode 12 beta 2020-06-22 15:43:20 -07:00
Karoy Lorentey
b7e08accb1 [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable (#28883)
* [stdlib] Slice: customize withContiguous[Mutable]StorageIfAvailable

We can easily make an UnsafeBufferPointer that slices another UnsafeBufferPointer, so let’s allow Slice to vend a slice of the base collection’s contiguous storage, if it provides access to one.

We need to do some index distance calculations to implement this, but those will be constant-time in the usual case where the base collection is a RAC.

https://bugs.swift.org/browse/SR-11957
rdar://58090587

* [test] UnsafeBufferPointer: fix some warnings

* [stdlib] Slice: don’t calculate index distances unless the base provides contiguous mutable storage
2020-01-06 12:32:30 -05:00
Andrew Trick
28a529ceed Fix crashes in Unsafe[Raw]BufferPointer with nil baseAddress.
This fix updates various initializers to handle incoming empty buffers
that happen to have a nil base. They should simply create another
buffer with nil base rather than crashing!

It is valid for an Unsafe[Raw]BufferPointer can have a nil base
address. This allows round-tripping with C code that takes a
pointer/length pair and uses `0` as the pointer value.

The original design wrongly assumed that we would use a sentinel value
for empty buffers and was never updated for or tested with the current
design.

Fixes <rdar://problem/47946984> Regression in Foundation.Data's
UnsafeBufferPointer constructor.
2019-02-11 13:38:48 -08:00
Ben Cohen
11769d2494 Add tests for withContiguousStorageIfAvailable 2018-12-07 17:30:13 -08:00
Ben Cohen
ad50a39b12 [stdlib] Add withContiguous{Mutable}StorageIfAvailable (#21092)
* Add MutableCollection.withContiguousMutableStorageIfAvailable

* Add withContiguousMutableStorageIfAvailable impls

* Add tests on concrete types

* Add Sequence.withContiguousStorageIfAvailable

* Implement withContiguousStorageIfAvailable in concrete types
2018-12-07 10:01:18 -08:00
Nate Cook
e5c1567957 [stdlib] Switch to a stable sort algorithm (#19717)
This switches the standard library's sort algorithm from an in-place
introsort to use a modified timsort, a stable, adaptive sort that
merges runs using a temporary buffer. This implementation performs
straight merges instead of adopting timsort's galloping strategy.

In addition to maintaining the relative order of equal/non-comparable
elements, this algorithm outperforms the introsort on data with any
intrinsic structure, such as runs of ascending or descending elements
or a significant number of equality collisions.
2018-11-07 00:05:04 -06:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Andrew Trick
afbcbfdfa7 Merge pull request #13071 from glessard/umbp-nonmutating-swapat
nonmutating swapAt implementations for UnsafeMutable(Raw)BufferPointer
2018-03-15 16:35:47 -07:00
swift-ci
9bda1e5c55 Merge pull request #13340 from glessard/umbp-failearlyrangecheck 2018-03-08 05:38:39 -08:00
Guillaume Lessard
0c95f902f0 restore debug-mode bounds checking to *BufferPointer.swapAt 2018-03-06 09:04:17 -07:00
Guillaume Lessard
116de2b3b2 non-mutating swapAt implementations for UnsafeMutable(Raw)BufferPointer 2018-03-06 09:04:16 -07:00
swift-ci
abbaa47614 Merge pull request #12504 from glessard/umbp-nonmutating-setter 2018-03-06 06:37:58 -08: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
Guillaume Lessard
d777f2068a [test] read/modify UnsafeBufferPointer through Slice 2017-12-15 16:48:36 -07:00
Guillaume Lessard
4683effc8b test non-mutating and overlap behaviour of slice assignments 2017-12-08 14:14:53 -07:00
Ben Cohen
4ddac3fbbd [stdlib] Eradicate IndexDistance associated type (#12641)
* Eradicate IndexDistance associated type, replacing with Int everywhere

* Consistently use Int for ExistentialCollection’s IndexDistance type.

* Fix test for IndexDistance removal

* Remove a handful of no-longer-needed explicit types

* Add compatibility shims for non-Int index distances

* Test compatibility shim

* Move IndexDistance typealias into the Collection protocol
2017-12-08 12:00:23 -08:00
taylor swift
c85880899d implement SE 184: add allocation methods to Unsafe buffer pointers, drop all parameters from deallocation, adjust namings, and add repeated-value assignment methods 2017-11-17 21:28:03 -08:00
Andrew Trick
b73352af7a Disable Unsafe[Raw]BufferPointer testing in optimized mode.
The optimized-build behavior of UnsafeBufferPointer bounds/overflow
checking cannot be tested. The standard library always compiles with debug
checking enabled, so the behavior of the optimized test depends on whether
the inlining heuristics decide to inline these methods. To fix this, we need
a way to force @_inlineable UnsafeBufferPointer methods to be emitted inside
the client code, and thereby subject the stdlib implementation to the test
case's compile options.
2017-10-19 21:12:09 -07:00
Greg Parker
f1fda3cd0d [test] Temporarily XFAIL two UnsafeBufferPointer tests pending rdar://35052802. 2017-10-18 10:02:54 -07:00
Ben Cohen
5494424b9a Correct UnsafeBufferPointer's Collection.makeIterator, add _copyContents (#8902) 2017-04-21 15:53:51 -07:00
Andrew Trick
8668f9bd72 Add init(rebasing:) to UnsafeBufferPointer.
This is required for consistency with UnsafeRawBufferPointer.
2017-04-06 17:12:18 -07:00
Andrew Trick
3782925a29 Give UnsafeRawBufferPointer a distinct slice type.
SubSequence = RandomAccessSlice<Self>
2017-04-06 17:12:18 -07:00
Andrew Trick
42e43f7ea0 Add sliceability tests for Unsafe(Raw)BufferPointer.
Improve the generic sliceability tests to verify that SubSequence indices are
compatible with their parents indices.
2017-04-06 17:12:18 -07:00
Andrew Trick
da0c4db530 Fix and enable testing stdlib Collection instances.
Top-level entry points fully testing a collection instance:
check${Traversal}Collection

One level of recursion into all slices of the collection instance
O(n^2). (Not combinatorial).

Previously, checkCollection() did nothing. So much of the testing infrastructure was inactive. Now it runs all forward collection tests.

Fixes a bug in subscriptRangeTests.

The UnsafeRawBufferPointer and Data collection testing is disabled and
will be fixed in the following commit.
2017-04-06 17:12:18 -07:00
Andrew Trick
849421799a Revert "SE-0138: Proposed amendment to SE-0138: Normalize UnsafeRawBufferPointer Slices (#8222)"
This reverts commit 1d32586d28.
2017-04-06 10:38:52 -07:00
Andrew Trick
1d32586d28 SE-0138: Proposed amendment to SE-0138: Normalize UnsafeRawBufferPointer Slices (#8222)
* Add sliceability tests for Unsafe(Raw)BufferPointer.

Improve the generic sliceability tests to verify that SubSequence indices are
compatible with their parents indices.

* Fix and enable testing stdlib Collection instances.

Top-level entry points fully testing a collection instance:
check${Traversal}Collection

One level of recursion into all slices of the collection instance
O(n^2). (Not combinatorial).

Previously, checkCollection() did nothing. So much of the testing infrastructure was inactive. Now it runs all forward collection tests.

Fixes a bug in subscriptRangeTests.

The UnsafeRawBufferPointer and Data collection testing is disabled and
will be fixed in the following commit.

* Give UnsafeRawBufferPointer a distinct slice type.

SubSequence = RandomAccessSlice<Self>

* Fix raw buffer pointer tests after changing the API

* Add UnsafeRawBuffer(rebasing:) initializers.

Allows converting a raw slice into a zero-based raw buffer,
which is a common operation on flat memory.

Add and update UnsafeRawBufferPointer unit tests.

* Do not run recursive O(n^2) collection slice testing on large collections.

Now, even with collection unit testing wired up, the validation tests
take the same amount of time to execute.

* Add init(rebasing:) to UnsafeBufferPointer.

This is required for consistency with UnsafeRawBufferPointer.

* Update CHANGELOG.md for SE-0138 amendment: UnsafeRawBufferPointer slice type.
2017-04-06 10:08:09 -07:00
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Andrew Trick
894be3703f Fix UnsafeBufferPointer validation test. (#5021)
There are several checks related to accessing a slice of an
UnsafeBufferPointer. Which tests are active depend on the level of
optimization. A raw buffer's checks are also stricter in some cases.

This test was originally designed to either crash or not for each input range
without regard to the nuances of when bounds checks are enabled. When an input
range was marked as crashing, that forced the test case to crash which was
self-fullfilling--nothing was really being tested in that case.

In my previous checkin, I enabled crash checking to be effective but missed some
of the nuances of different bounds checking modes. This commit adds logic to the test
to account for these nuances.
2016-09-26 17:31:09 -07:00
Andrew Trick
9c729e4c0c SE-0138: UnsafeRawBufferPointer revision.
The withUnsafeMutableBytes closure argument should not be `inout`.

Improve testing, fix comments.

Addresses DaveA's review.
2016-09-25 19:56:21 -07:00
Andrew Trick
945cfc9342 Generalize UnsafeBufferPointer-as-a-Collection testing.
Fix some badly written tests with false positives.
Generalize the testing to cover raw buffer pointers.
2016-09-25 13:16:13 -07:00
Dmitri Gribenko
243a35cd65 Migrate callsites from 'expectEmpty()' to 'expectNil()' 2016-09-10 20:05:42 -07:00
Andrew Trick
5a8271c621 Rename UnsafePointer allocate & deallocate. (#3608)
As proposed in SE-0107: UnsafeRawPointer:
Rename 'init(allocatingCapacity:)' to 'UnsafeMutablePointer.allocate(capacity:)'
Rename 'deallocateCapacity' to 'deallocate(capacity:)'

`allocate` should not be an initializer. It's primary function is to allocate
memory, not initialize a pointer.
2016-07-19 11:48:18 -07:00
Andrew Trick
73106dd7c3 Rename initialize(with:count:) to initialize(to:count:). (#3601)
As proposed in SE-0107: UnsafeRawPointer.

"with" is considered a vacuous preposition. "to" implies direction.
2016-07-18 23:37:45 -07:00
Austin Zheng
aec2d8ea0b [stdlib] Add tests for UnsafeMutableBufferPointer subscript setter 2016-06-29 14:59:16 -07:00
Austin Zheng
26ade958c3 [stdlib] Fix UnsafeBufferPointer range subscript getter tests (#3233)
All four of the Unsafe*BufferPointer range subscript getter tests (one for each range) were using the same test name string. This caused only one of the four tests to actually be registered to the test suite. This change fixes that issue, and adds a couple more tests for better coverage.
2016-06-29 13:56:57 -07:00
Austin Zheng
dfcc13dc69 [stdlib] Bounds checks and tests for Unsafe*BufferPointer
Changes:
- Added bounds checks to Unsafe*BufferPointer's subscript getter and setter
- Added tests for Unsafe*BufferPointer's subscript getter for all four range types
2016-06-20 21:41:20 -07:00