Commit Graph

302 Commits

Author SHA1 Message Date
Andrew Trick
0b75ee975e Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.
2016-07-28 20:42:23 -07:00
Nate Cook
58fb4ef9c5 [stdlib] Clean up various documentation issues (#3804)
* [stdlib] Clean up some documentation formatting

* [stdlib] Update example code for SE-0103

* [stdlib] Fix UnsafeBufferPointer documentation typo

* [stdlib] Collection documentation cleanup

* [stdlib] Fix String.init?(_:UTF16View) description

* [stdlib] Documentation fixes for SE-0091

* [stdlib] Add param info for String(repeating:count:)
2016-07-28 11:25:38 -07:00
Andrew Trick
37c084bbeb Use UnsafeMutableRawPointer in HashedCollection _UnmanagedAnyObjectArray.
In order to conform to the memory model.
2016-07-27 08:05:55 -07:00
Bob Wilson
112451c44a [SE-0127] Remove withUnsafePointers and withUnsafeMutablePointers APIs.
These provide the same functionality as the one-argument versions for both
2 and 3 argument closures. Since these are less common, the same thing can be
achieved by composing the one-argument version. rdar://problem/26529498
2016-07-26 17:43:33 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -07:00
Andrew Trick
0ed9ee8dee Revert "Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)"
This reverts commit ece0951924.

This results in lldb failues on linux that I can't readily debug.
Backing out until they can be resolved.
2016-07-26 02:50:57 -07:00
Andrew Trick
ece0951924 Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3724)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 02:18:21 -07:00
Joe Groff
32b50c624d stdlib: Remove _isBridgedToObjectiveC from _ObjectiveCBridgeable.
All generic bridgeable types can bridge for all their instantiations now. Removing this ferrets out some now-unnecessary traps that check for unbridgeable parameter types.
2016-07-25 06:01:21 -07:00
John McCall
232a314a9f Teach the dynamic-cast machinery how to cast collection element types. 2016-07-23 10:30:10 -07:00
Patrick Pijnappel
79250704fa Merge pull request #3698 from PatrickPijnappel/spacing
[stdlib] Standardize function signature spacing
2016-07-23 15:07:19 +10:00
Patrick Pijnappel
2728bd0145 [stdlib] Standardize function signature spacing 2016-07-23 11:51:32 +10:00
Dave Abrahams
7c7fc160ac Work on Mac again 2016-07-22 16:52:29 -07:00
Dave Abrahams
591a0bd625 Fix a typo 2016-07-22 16:50:07 -07:00
Dave Abrahams
d96e129e71 [stdlib] id-as-Any: hashed collection casts on Linux 2016-07-22 16:17:22 -07:00
Dave Abrahams
bbaabbf16c [stdlib] id-as-Any: hashed collection casting
Relax some preconditions in the cast machinery and write a comprehensive
test suite.

FIXMEs in test/1_stdlib/HashedCollectionCasts.swift.gyb show where the
typechecker doesn't seem to quite work, or the frontend might be
generating the wrong runtime calls.

TODO: Add tests for failing downcasts
2016-07-22 16:12:53 -07:00
Dave Abrahams
e32775b7e2 Revert "[stdlib] id-as-Any: hashed collection casting"
This reverts commit c2642e65e7.
2016-07-21 16:42:25 -07:00
Dave Abrahams
231c80b794 Revert mistaken commit
This reverts commit 70a30c0449.
2016-07-21 16:40:44 -07:00
Dave Abrahams
70a30c0449 **REVERT ME** id-as-Any: add entry-point logging
Add some logging to the stdlib that may help with debugging hashed
collection casting.
2016-07-21 15:38:47 -07:00
Dave Abrahams
c2642e65e7 [stdlib] id-as-Any: hashed collection casting
Relax some preconditions in the cast machinery and write a comprehensive
test suite.

FIXMEs in test/1_stdlib/HashedCollectionCasts.swift.gyb show where the
typechecker doesn't seem to quite work, or the frontend might be
generating the wrong runtime calls.

TODO: Add tests for failing downcasts
2016-07-21 15:38:23 -07:00
Doug Gregor
778e76e158 [SE-0091 Follow-up] Move more operators into types, now for generic operators. 2016-07-21 12:54:27 -07:00
John McCall
0c642a8098 Stub out Set/Dictionary casting intrinsics on non-ObjC platforms. 2016-07-19 14:35:03 -07:00
Dave Abrahams
b2bbd4c599 reduce(_ initial:combine:) => reduce(_ initialResult:_ nextPartialResult) 2016-07-19 07:12:59 -06:00
Dave Abrahams
014b6972cf isOrderedBefore: => by areInIncreasingOrder: 2016-07-19 07:05:54 -06: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
Michael Gottesman
fc37603c5f Revert "Implement SE-0118" 2016-07-18 16:44:58 -07:00
Dave Abrahams
b0044948df reduce(_ initial:combine:) => reduce(_ initialResult:_ nextPartialResult) 2016-07-18 14:30:46 -06:00
Dave Abrahams
f3ccc956c6 isOrderedBefore: => by areInIncreasingOrder: 2016-07-18 14:29:09 -06:00
Michael Gottesman
40e1991e12 Revert "Name and label changes for closure parameters (for review only) (#2981)"
This reverts commit 18406900ba.
2016-07-15 19:45:26 -07:00
Dave Abrahams
18406900ba Name and label changes for closure parameters (for review only) (#2981)
Implement SE-0118 Name and label changes for closure parameters

[SE-0118](https://github.com/apple/swift-evolution/blob/master/proposals/0118-closure-parameter-names-and-labels.md)
2016-07-15 15:31:48 -07:00
Robert Widmann
c39da37525 Merge pull request #3474 from CodaFi/postminimalist-abstract-expressionism
[SE-0115] Rename *LiteralConvertible protocols to ExpressibleBy*…
2016-07-12 21:08:52 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Dave Abrahams
125823d16c [stdlib] ManagedBuffer: rename Value => Header
This implements SE-0114 Updating Buffer "Value" Names to "Header" Names
https://github.com/apple/swift-evolution/blob/master/proposals/0114-buffer-naming.md
2016-07-06 17:45:17 -07:00
Rintaro Ishizaki
6ef62f3c73 [stdlib] Better diagnosis for unavailable APIs
Added tests for expected-error and fix-its.

- Add arguments signature regardless that is the same as before.
  Because the error message looks more natural.
  e.g. "makeIterator" => "makeIterator()",
  "replaceSubrange" => "replaceSubrange(_:with:)"
- Any${ExistentialCollection}.underestimateCount() was a method, not
  computed property.
- 'LazySequenceType' has been renamed to 'LazySequenceProtocol', but not
  'LazyCollectionProtocol'
- Streamable.writeTo(_:) had no argument label.
- Fixed typo in print() debugPrint() error message (not working for now)
- Repeated.init(): changed `renamed` to `message` because the arugment
  order has changed.
- Marked `public` for some unavailable method on `Sequence`
- Sequence.split(_:maxSplit:allowEmptySlices) was replaced with
  split(separator:maxSplits:omittingEmptySubsequences:),
  not split(separator:omittingEmptySubsequences:isSeparator:)
- Sequence.split(_:allowEmptySlices:isSeparator) was replaced with
  split(maxSplits:omittingEmptySubsequences:isSeparator:),
  not split(_:omittingEmptySubsequences:isSeparator:)
- Sequence.startsWith(_:isEquivalent:) or startsWith(_:) had no label on
  the first argument.
- transcode(_:_:_:_:stopOnError), not transcode(_:_:_:_:stoppingOnError)
- Removed mutating methods from UnsafePointer.
  alloc(_:), dealloc(_:), setter:memory, initialize(_:), destroy(),
  and destroy(_:)
2016-07-01 14:52:09 +09:00
Dmitri Gribenko
6f502fae0b stdlib: make some internal Dictionary APIs safer by sinking the _fixLifetime() call deeper into implementation details 2016-06-22 14:10:10 -07:00
Doug Gregor
2807a17eb8 [Type checker SR-899] Warning on missing ".self" for single-parameter functions.
Due to a modeling error in the type checker's folding of type
references into type expressions, code such as "strideof(Int)" would
be accepted without the required ".self". Commit
4a60b6cbf4 fixes the modeling issue but
left the historical accepts-invalid; now, diagnose these cases with a
warning + Fix-It to ease the transition.

Fixes SR-899.
2016-06-12 22:31:59 -07:00
Rintaro Ishizaki
668b9dbc64 [stdlib] Apply tail style "where" clause to stdlib/public/core 2016-06-02 12:00:55 +09:00
Patrick Pijnappel
daec2dae00 Resolve conflicts with master 2016-05-24 19:21:04 +02:00
Dmitri Gribenko
0b4162bef0 stdlib: make the argument label in _UnsafeBitMap.sizeInWords more clear to avoid bits vs. bytes vs. words confusion 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
b811f929ef stdlib: rename _BitMap to _UnsafeBitMap
_BitMap is nothing more than a convenience wrapper around an
UnsafeMutablePointer.
2016-05-23 18:41:39 -07:00
Dmitri Gribenko
389fa5fc69 stdlib: move _BitMap to its own file 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
ea07472556 stdlib: Dictionary: rename the wordsFor() function to conform to API guidelines 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
f78613758a stdlib: Dictionary: use the two-argument version of UnsafeMutablePointer.initialize() instead of a loop 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
f7d110d4ea stdlib: Dictionary: abstract away some of the address calculations in _roundUp() 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
78b60fb431 stdlib: Dictionary: simplify code and fix coding style 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
0da6efdc1b stdlib: Dictionary: use strideof() to calculate the array size
Since sizeof(UInt) == strideof(UInt) there is no bug here, but
strideof() is the correct API to use for this purpose.
2016-05-23 18:41:39 -07:00
Dmitri Gribenko
e424982497 stdlib: Dictionary: attach a comment directly to the method 2016-05-23 18:41:39 -07:00
Dmitri Gribenko
1c09782396 stdlib: Dictionary: contain the unsigned division optimization in a getter method, expose a clean API to the outside 2016-05-23 18:41:39 -07:00
Nate Cook
44b2d56a7f [stdlib] Revise documentation for string-related types
This documentation revision covers a large number of types & protocols:
String, its views and their indices, the Unicode codec types and protocol,
as well as Character, UnicodeScalar, and StaticString, among others.

This also includes a few small changes across the standard library for
consistency.
2016-05-22 03:04:22 -05:00
practicalswift
61e4cde148 [gardening] Fix inconsistent formatting. 2016-05-20 21:26:16 +02:00
Dmitri Gribenko
d591f9cf7a stdlib: remove most uses of @warn_unused_result, which does nothing now
I kept the one on sorted(), because that one requires a less trivial
change.
2016-05-19 18:39:39 -07:00