Commit Graph

2952 Commits

Author SHA1 Message Date
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
Nate Cook
13d1ac5b81 [stdlib] Update partition implementation with feedback 2016-07-21 10:18:20 -05:00
Nate Cook
d7ee56088f [stdlib] Implement partition API change (SE-0120) 2016-07-21 10:16:54 -05:00
Arnold Schwaighofer
b6da135ea0 Add 'bitPattern:' label to '(U)Int.init(ObjectIdentifier)'
SR-2064
rdar://27327186
2016-07-20 19:00:48 -07:00
Alexander Lash
9a4caf6c4b [core] hasPrefix/hasSuffix consider the empty string a prefix/suffix of all strings. 2016-07-20 17:46:47 -07:00
Nate Cook
7e6a1055b7 stdlib: underscore AnyCollectionProtocol 2016-07-20 15:52:10 -05:00
Nate Cook
af224c0566 [stdlib] Various minor documentation edits (#3614)
* [stdlib] Fix UTF8View example code
* [stdlib] Update code sample for SE-0099
* [stdlib] Standardize operator naming
* [stdlib] Minor edits to Error documentation
2016-07-20 13:23:49 -05:00
Nate Cook
34b9b98988 [stdlib] Convert existential collection === operator to method 2016-07-20 10:01:39 -05:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Dave Abrahams
4fa5877f4f [stdlib] Fix some examples in doc comments 2016-07-19 14:44:25 -07:00
John McCall
0c642a8098 Stub out Set/Dictionary casting intrinsics on non-ObjC platforms. 2016-07-19 14:35:03 -07:00
Tony Parker
fe932663a8 Merge pull request #3598 from parkera/se86_rename_process
Rename Process to CommandLine
2016-07-19 13:45:23 -07:00
Tony Parker
3cb4a76fed Merge pull request #3576 from parkera/se86_outputstream
Rename OutputStream to OutputStreamable [SE-0086]
2016-07-19 13:45:01 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00
Dave Abrahams
32db8f7dec Merge pull request #3612 from ddunbar/collection-doc
[stdlib] Update a documentation comment for SE-0118.
2016-07-19 12:06:11 -07:00
Joe
67dccb283e [SE-0095] Code feedback changes; Any is parsed as a keyword
- Any is made into a keyword which is always resolved into a TypeExpr,
allowing the removal of the type system code to find TheAnyType before
an unconstrained lookup.
- Types called `Any` can be declared, they are looked up as any other
identifier is
- Renaming/redefining behaviour of source loc methods on
ProtocolCompositionTypeRepr. Added a createEmptyComposition static
method too.
- Code highlighting treats Any as a type
- simplifyTypeExpr also does not rely on source to get operator name.
- Any is now handled properly in canParseType() which was causing
generic param lists containing ‘Any’ to fail
- The import objc id as Any work has been relying on getting a decl for
the Any type. I fix up the clang importer to use Context.TheAnyType
(instead of getAnyDecl()->getDeclaredType()). When importing the id
typedef, we create a typealias to Any and declare it unavaliable.
2016-07-19 12:01:37 -07:00