Commit Graph

2617 Commits

Author SHA1 Message Date
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
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
swift-ci
c41edb8c94 Merge pull request #3670 from parkera/rename_task_to_process 2016-07-25 20:50:20 -07:00
Joe Groff
10a0eb1c13 Merge pull request #3710 from jckarter/turn-on-id-as-any
Turn on id as any
2016-07-25 18:58:27 -07:00
Andrew Trick
3542ea3e68 Fix AutoreleasingUnsafeMutablePointer assignment. (#3727)
Fix the implementation to obey the memory model by
using `withMemoryRebound`.

Also move toward using `Unsafe` not `Opaque`.
2016-07-25 10:01:41 -07:00
Joe Groff
b1fb1fa3ea Runtime: Handle bridging from ObjC objects to Any or boxed types. 2016-07-25 06:01: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
Joe Groff
9effc047e6 Update standard library for id-as-Any. 2016-07-25 06:01:21 -07:00
swift-ci
395e967875 Merge pull request #3739 from practicalswift/normalize-headers 2016-07-25 04:55:55 -07:00
swift-ci
e657ece02b Merge pull request #3617 from natecook1000/nc-existenz-identity 2016-07-24 23:31:40 -07:00
Dmitri Gribenko
d82682ec6c Merge pull request #3733 from practicalswift/typo-fixes-20160724
[gardening] Fix recently introduced typos.
2016-07-24 15:43:03 -07:00
Dmitri Gribenko
717213c3c6 Merge pull request #3637 from jtbandes/se-0121
[stdlib] Remove optional comparison operators (SE-0121)
2016-07-24 14:22:51 -07:00
swift-ci
00934a74eb Merge pull request #3667 from parkera/rename_nsoutputstream 2016-07-24 13:59:07 -07:00
practicalswift
7e89679404 [gardening] Fix recently introduced typos. 2016-07-24 22:32:40 +02:00
practicalswift
a87d170b81 [gardening] Improve consistency in header formatting. 2016-07-24 21:36:25 +02:00
Andrew Trick
7b2f91aad8 The _decodeCString helper does not need to be public. (#3726) 2016-07-24 10:24:10 -07:00
Dmitri Gribenko
558f2b8591 Merge pull request #3517 from natecook1000/nc-SE-0120
[stdlib] Implement partition API change (SE-0120)
2016-07-24 01:43:02 -07:00
Dmitri Gribenko
e4e9cf5cac Merge pull request #3683 from stephentyrone/totally-ordered-label
Bugfix: argument label of isTotallyOrdered.
2016-07-24 00:05:25 -07:00
Jacob Bandes-Storch
ebabfe6b1c [stdlib] Remove optional comparison operators (SE-0121) 2016-07-23 22:30:09 -07:00
Andrew Trick
6ad0f30f01 Add UnsafeMutableRawPointer.init(mutating:) (#3722)
As proposed in SE-0107: UnsafeRawPointer.

Allow immutable raw pointers to be explicitly cast
into mutable raw pointers.
2016-07-23 21:23:24 -07:00
Andrew Trick
72b8813a64 Restore operator '+' family for UnsafePointer. (#3719)
The reverts part of my previous patch. Removing the operators is too much of a
performance penalty to take. The difference is that the Strideable operators are
not transparent.

I still need to remove the UnsafeRawPointer operators, so -Onone performance
will be bad in some cases until this is fixed:
<rdar://problem/27513184> [perf] Strideable operators are not transparent. This is a huge -Onone performance penalty.
2016-07-23 18:58:55 -07:00
John McCall
232a314a9f Teach the dynamic-cast machinery how to cast collection element types. 2016-07-23 10:30:10 -07:00
Andrew Trick
c7aa8284c9 Add basic CString <-> UTF8 API variants.
As proposed by SE-0107: UnsafeRawPointer:
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md#cstring-conversion
Adds String.init(cString: UnsafePointer<UInt8>)
Adds String.nulTerminatedUTF8CString: ContiguousArray<CChar>

This is necessary for eliminating UnsafePointer conversion.  Such
conversion is extremely common for interoperability between Swift
strings and C strings to bridge the difference between CChar and
UTF8.CodeUnit. The standard library does not provide any convenient
utilities for converting between the differently typed
buffers. These APIs will handle the simplest cases involving C
interoperability. More convenience can be added later.
2016-07-22 23:41:13 -07:00
swift-ci
0f17ab3786 Merge pull request #3691 from atrick/rawptr-operator 2016-07-22 23:05:50 -07:00
Andrew Trick
198173b17b Remove the global operator '+' family from UnsafePointer and UnsafeRawPointer.
Generic versions of these functions are provided by Strideable.

This is required for SE-0107: UnsafeRawPointer. Otherwise, the presence
of non-generic operator overloads will conflict with existing operators
on String.
2016-07-22 22:14:19 -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
Jay Buffington
f17d9a8d67 Stdlib doc fixes (#3684)
* [stdlib] Correct documentation for joined (join -> joined)

* [stdlib] Correct example in documentation for Unmanaged.toOpaque

Fixes <https://bugs.swift.org/browse/SR-1911>.
2016-07-23 00:00:41 -05:00
swift-ci
9a2783f6fe Merge pull request #3671 from apple/stdlib-id-as-any 2016-07-22 20:33:52 -07:00
Patrick Pijnappel
2728bd0145 [stdlib] Standardize function signature spacing 2016-07-23 11:51:32 +10:00
Patrick Pijnappel
dd1445ab13 [stdlib] Fix plural grammar 2016-07-23 10:39:12 +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
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Slava Pestov
4022624dba stdlib: Rename _unimplemented_initializer to _unimplementedInitializer, NFC
This addresses a FIXME.
2016-07-22 14:55:45 -07:00
Slava Pestov
6ff02a9fe2 AST/SIL: Add a new Never type, and a TypeBase::isNever() check
Mostly NFC, this is just plumbing for the next patch.
Note that isNever() returns true for any uninhabited
enum.

It should be generalized so that stuff like (Never, Int)
is also known to be uninhabited, or even to support
generic substitutions that yield uninhabited types,
but for now I really see no reason to go that far, and
the current check for an enum with no cases seems
perfectly adequate.
2016-07-22 14:55:45 -07:00
Andrew Trick
a41484ea2b Add UnsafeRawPointer type and API. (#3677)
* Add UnsafeRawPointer type and API.

As proposed in SE-0107:   UnsafeRawPointer.
https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md

The fundamental difference between Unsafe[Mutable]RawPointer and
Unsafe[Mutable]Pointer<Pointee> is simply that the former is used for "untyped"
memory access, and the later is used for "typed" memory access. Let's refer to
these as "raw pointers" and "typed pointers". Because operations on raw pointers
access untyped memory, the compiler cannot make assumptions about the underlying
type of memory and must be conservative. With operations on typed pointers, the
compiler may make strict assumptions about the type of the underlying memory,
which allows more aggressive optimization.

Memory can only be accessed by a typed pointer when it is currently
bound to the Pointee type. Memory can be bound to type `T` via:
- `UnsafePointer<T>.allocate(capacity: n)`
- `UnsafePointer<Pointee>.withMemoryRebound(to: T.self, capacity: n) {...}`
- `UnsafeMutableRawPointer.initializeMemory(as: T.self, at: i, count: n, to: x)`
- `UnsafeMutableRawPointer.initializeMemory(as: T.self, from: p, count: n)`
- `UnsafeMutableRawPointer.moveInitializeMemory(as: T.self, from: p, count: n)`
- `UnsafeMutableRawPointer.bindMemory(to: T.self, capacity: n)`

Mangle UnsafeRawPointer as predefined substitution 'Sv' for Swift void
pointer ([urp] are taken).

* UnsafeRawPointer minor improvements.

Incorporate Dmitri's feedback.

Properly use a _memmove helper.

Add load/storeBytes alignment precondition checks.

Reword comments.

Demangler tests.

* Fix name mangling test cases.

* Fix bind_memory specialization.
2016-07-22 13:32:08 -07:00
Steve (Numerics) Canon
11baa7a14f Possible fix for label of isTotallyOrdered(below:). 2016-07-22 15:21:21 -04:00
Dmitri Gribenko
f318fe853d Merge pull request #3651 from abl/empty-suffix-prefix
[stdlib/core] hasPrefix/hasSuffix consider the empty string a prefix/suffix of all strings.
2016-07-21 22:33:30 -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
Xin Tong
bbf86865d6 Change unicodescalar to failable
We were using a precondition which crashes the program when invalid input is
provided. We want to provide a way to gracefully check and handle invalid input
or shutdown the program if necessary.

SR-1930
2016-07-21 15:27:13 -07:00
Tony Parker
be316f5035 Rename NSTask to Process 2016-07-21 15:23:12 -07:00
Tony Parker
cecc463bd0 Rename NSOutputStream to OutputStream 2016-07-21 14:06:15 -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
Doug Gregor
42a3e36c15 [SE-0091 Follow-up] Move !, &&, and || onto an extension of Bool.
The diagnostics changes make the compiler more robust in its diagnosis
of uses of operators defined in types.
2016-07-21 12:54:27 -07:00
Doug Gregor
0bf7c005b3 [SE-0091 Follow-up] Move global operators for non-generic concrete types into the type.
In various cases where we had global operators for non-generic
concrete types (such as String + String), move those operators into
the type. This should not affect the sources, but makes the exposition
of the library cleaner.

Plus, it's a good test for the compiler, which uncovered a few issues
where the compiler was coupled with the library.
2016-07-21 12:54:27 -07:00