Commit Graph

54 Commits

Author SHA1 Message Date
Xi Ge
faf91d5cf6 test: disable stdlib/TestData.swift due to rdar://61347106 2020-04-06 10:13:37 -07:00
Karoy Lorentey
1a9f7afdec [Foundation] Fix Data.count’s setter
Data provides a settable `count` property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

```
import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓
```

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by https://github.com/apple/swift/pull/28918.)

rdar://58134026
2019-12-20 23:35:05 -08:00
Philippe Hausler
4315f40d40 TestData.swift fails when backporting to pre-macOS10.15/iOS13 2019-10-19 11:10:48 -07:00
Arnold Schwaighofer
b31b7a9d8e Remove some UNSUPPORTED swift_test_mode_optimize_none_with_implicit_dynamic
rdar://51228899
2019-05-31 08:45:37 -07:00
Philippe Hausler
8a751bd4de Add tests and validate Data and DispatchData as sequences 2019-05-14 17:12:44 -07:00
Arnold Schwaighofer
e113ef8c93 Add a mode to test implicit dynamic with private imports 2019-03-20 14:34:01 -07:00
Itai Ferber
7ce6f840d1 Fix off-by-one when initializing Data with discontiguous, underestimated sequences 2019-03-12 14:26:58 -07:00
Itai Ferber
9fb05979af Add unit tests covering Data.init<T>(buffer: Unsafe{Mutable}BufferPointer<T>) 2019-02-11 15:48:24 -08:00
Itai Ferber
446e89ca9e Typo fixes in tests 2019-01-11 14:40:01 -08:00
Itai Ferber
28993690fd Clarify new append tests 2019-01-11 11:17:43 -08:00
Itai Ferber
076effdf5d Correct buffering in .init<S> and .append<S> and add unit test 2019-01-11 10:14:27 -08:00
Itai Ferber
af626bf03c Remove Data.hashValue==NSData.hashValue test 2019-01-10 10:29:09 -08:00
Philippe Hausler
d030354320 Initial draft of DataProtocol ContiguousCollection and new inline Data 2018-12-11 11:19:36 -08:00
Arnold Schwaighofer
2d8a1dbbfe Codesign test/stdlib 2018-08-10 06:58:40 -07:00
Robert Widmann
1aca4d141d Migrate some stdlib tests to swift 4 2018-06-27 12:38:52 -07:00
Slava Pestov
5d2752f7d2 Run tests with -swift-version 4 by default
Some test now fail, so add an explicit -swift-version 3.
2018-06-19 23:24:19 -07:00
Slava Pestov
694fcddf4e Remove build-script flag to disable resilience 2018-03-16 19:56:17 -07:00
Philippe Hausler
26d4ea18b2 [Foundation] searching in slices should index relative to the slice (#14851) 2018-02-27 14:00:32 -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
Philippe Hausler
beffbc6ce5 [Foundation] Discontiguous data slices should not heap corrupt (#13252)
* [Foundation] Byte access and methods that funnel to byte access for slices of discontiguous data (ala backed by dispatch_data_t) should void heap corruption and walking off the ends of buffers

* add missing parens on test_byte_access_of_discontiguousData

* Use the proper byte count in testing
2017-12-05 09:55:22 -08:00
Alexander Belonogov
bf56b09395 [SR-6361] Fix Data.withUnsafeMutableBytes() for slices with length < range.lowerBound 2017-11-14 09:08:21 +01:00
Philippe Hausler
b78b438897 Ensure that hashing data with zero bytes avoids empty allocations and fix bridged empty data hashes from de-referencing null values (#12509) 2017-10-19 17:53:19 -07:00
Philippe Hausler
c8bbce6ef1 Data slice mutation support (#11939)
* Mutations of slices of data should preserve relative indexing as well as cow semantics of slices

* Ensure hashes of ranges are uniform to the expected hash for Data

* Correct a few mistakes in the slice mutation tests

* Update sequence initializations to avoid directly calling mutableCopy which prevents slice offset mismatches

* Avoid invalid index slices in creating mirrors

* Restore the original Data description

* Resetting a slice region should expand the slice to the maximum of the region (not a out of bounds index of the backing buffer)

* Remove stray comment and use a stack buffer for sequence appending

* Return false when allocations fail in _resizeConditionalAllocationBuffer (not yet in use)

* Enumeration of regions of a slice should be limited to the slice range in the case of custom backing (e.g. dispatch_data_t)

* adjust assertion warnings for data indexes that are negative
2017-09-16 13:22:01 -07:00
Philippe Hausler
5dfa9160f9 [Foundation] replaceSubrange in the cases of immutable and mutable backing stores should recalculate length per the reference backing store change and not the length of the replacement 2017-07-14 18:34:57 -07:00
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
Philippe Hausler
56f509f059 [Foundation] Merge sequence initializer fast paths into one initializer 2017-07-06 19:24:17 -07:00
Philippe Hausler
aeb61e361b [Foundation] Add fast paths for Data initialization for common sequences 2017-07-06 09:45:53 -07:00
practicalswift
d39719ec3f [gardening] Fix typos 2017-06-29 23:09:22 +02:00
Philippe Hausler
e5504cdf15 [Foundation] slices of slices that use range expressions incorrectly calculated relative indexing 2017-06-26 16:35:40 -07:00
Philippe Hausler
d31ffc7d5e [Foundation] Validate indexes and ranges passed into Data so that bounding conditions are respected 2017-06-22 11:25:57 -07:00
Philippe Hausler
3fc134f8bb [Foundation Tests] Add a unit test to validate the behavior of dropFirst 2017-06-21 11:17:39 -07:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Ben Langmuir
354dddd7e0 Disable TestData with reslience temporarily
This test is broken on our resilience bot; disable it until it is fixed.

rdar://problem/32472729
2017-06-01 09:32:33 -07:00
Philippe Hausler
c40ba96328 [Foundation] Correct data subscript indexing to be offset from the base index (#9816) 2017-05-24 09:43:56 -07:00
Philippe Hausler
5b4d913a54 Merge branch 'master' into correct_unconditionally_bridge 2017-05-01 15:17:36 -07:00
swift-ci
1d46e688db Merge pull request #8510 from phausler/data_slice_fixes 2017-04-20 12:12:16 -07:00
Philippe Hausler
138644f1e3 [Foundation] Add unit tests for unconditional bridging and import a few unit tests for Decimal 2017-04-18 10:09:39 -07:00
swift-ci
c158056d1e Merge pull request #8559 from phausler/enumerate_bytes_index 2017-04-17 11:08:14 -07:00
Philippe Hausler
dd83b779ce [Foundation] Address slice regions that incorrectly fetched from the wrong offset of the backing buffers
# Conflicts:
#	stdlib/public/SDK/Foundation/Data.swift
#	test/stdlib/TestData.swift
2017-04-06 14:22:46 -07:00
Philippe Hausler
e422db587d [Foundation] Bridged dispatch_data_t to NSData to Data should enumerate bytes with the offset not the length parameter as the byte index 2017-04-05 10:31:43 -07:00
Philippe Hausler
32e461709e [Foundation] Ensure data can be subscripted with all range types 2017-04-05 08:56:07 -07:00
Jordan Rose
a2ff9340ad Fix cac44b2a33 to disable the correct test.
Tracked by rdar://problem/30560514.
2017-02-27 09:12:46 -08:00
Jordan Rose
cac44b2a33 Disable Foundation.Data test that fails with resilience enabled.
Tracked by rdar://problem/30560514.
2017-02-24 10:39:39 -08:00
Philippe Hausler
1a2687a72e [Foundation] Convert Data’s SubSequence type to be Data
Data can encapsulate it’s own sub-sequence type by housing a range of the slice in the structural type for Data. By doing this it avoids the API explosion of supporting all APIs that take Data would need overloads to take a slice of Data. This does come at a small conceptual cost: any index based iteration should always account for the startIndex and endIndex of the Data (which was an implicit requirement previously by being a Collection). Moreover this prevents the requirement of O(n) copies of Data if it is never mutated while parsing sub sequences; so more than an API amelioration this also could offer a more effecient code-path for applications to use.
2017-02-01 08:50:23 -08:00
Philippe Hausler
45714e6263 [Foundation] Correct sequence initializers for Data when repeating:count: is called and add a memset fast-path 2017-01-06 13:56:08 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Philippe Hausler
b57752a67f [Foundation] Correct case of over-released data contents when specifying .none as a deallocator 2016-12-19 14:37:24 -08:00
Philippe Hausler
4c2d6e24ff Merge pull request #5975 from phausler/data_performance
First draft at a new inlinable version of struct Data
2016-12-02 10:44:51 -08:00
Jordan Rose
1c68744341 [test] Let test output go to stdout.
...so we can see it in failure logs.
2016-12-01 16:06:15 -08:00
Philippe Hausler
bdafb2dac0 Handle no-copy cases and custom deallocators as inline construction of swift Data 2016-12-01 12:27:57 -08:00