Skip to content

Commit 22d0bad

Browse files
authored
---
yaml --- r: 349154 b: refs/heads/master-next c: bacbdb8 h: refs/heads/master
1 parent abe928b commit 22d0bad

File tree

503 files changed

+11992
-5789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

503 files changed

+11992
-5789
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: a37f81880e19247cb177ed73dd4498ad23759f46
3+
refs/heads/master-next: bacbdb81646d53c6514fde1aed989a3df796359f
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/CHANGELOG.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,63 @@ CHANGELOG
2626
Swift Next
2727
----------
2828

29+
* [SR-11298][]:
30+
31+
A class-constrained protocol extension, where the extended protocol does
32+
not impose a class constraint, will now infer the constraint implicitly.
33+
34+
```swift
35+
protocol Foo {}
36+
class Bar: Foo {
37+
var someProperty: Int = 0
38+
}
39+
40+
// Even though 'Foo' does not impose a class constraint, it is automatically
41+
// inferred due to the Self: Bar constraint.
42+
extension Foo where Self: Bar {
43+
var anotherProperty: Int {
44+
get { return someProperty }
45+
// As a result, the setter is now implicitly nonmutating, just like it would
46+
// be if 'Foo' had a class constraint.
47+
set { someProperty = newValue }
48+
}
49+
}
50+
```
51+
52+
As a result, this could lead to code that currently compiles today to throw an error.
53+
54+
```swift
55+
protocol Foo {
56+
var someProperty: Int { get set }
57+
}
58+
59+
class Bar: Foo {
60+
var someProperty = 0
61+
}
62+
63+
extension Foo where Self: Bar {
64+
var anotherProperty1: Int {
65+
get { return someProperty }
66+
// This will now error, because the protocol requirement
67+
// is implicitly mutating and the setter is implicitly
68+
// nonmutating.
69+
set { someProperty = newValue } // Error
70+
}
71+
}
72+
```
73+
74+
**Workaround**: Define a new mutable variable inside the setter that has a reference to `self`:
75+
76+
```swift
77+
var anotherProperty1: Int {
78+
get { return someProperty }
79+
set {
80+
var mutableSelf = self
81+
mutableSelf.someProperty = newValue // Okay
82+
}
83+
}
84+
```
85+
2986
* [SE-0253][]:
3087

3188
Values of types that declare `func callAsFunction` methods can be called
@@ -51,7 +108,7 @@ Swift Next
51108

52109
* [SR-4206][]:
53110

54-
A method override is no longer allowed to have a generic signature with
111+
A method override is no longer allowed to have a generic signature with
55112
requirements not imposed by the base method. For example:
56113

57114
```
@@ -88,6 +145,8 @@ Swift Next
88145
Swift 5.1
89146
---------
90147

148+
### 2019-09-20 (Xcode 11.0)
149+
91150
* [SR-8974][]:
92151

93152
Duplicate tuple element labels are no longer allowed, because it leads
@@ -7765,3 +7824,4 @@ Swift 1.0
77657824
[SR-8974]: <https://bugs.swift.org/browse/SR-8974>
77667825
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>
77677826
[SR-9827]: <https://bugs.swift.org/browse/SR-9827>
7827+
[SR-11298]: <https://bugs.swift.org/browse/SR-11298>

branches/master-next/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_ubuntu_16.04.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-aarch64)|
1919
|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | ARMv7 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android)|
2020
|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64)|
21-
|**[Ubuntu 16.04 (TensorFlow)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow)|
22-
|**[macOS 10.13 (TensorFlow)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_macos_high_sierra_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow)|
23-
|**[Ubuntu 16.04 (TensorFlow with GPU)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow_gpu.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu)|
24-
|**[Debian 9.5](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_debian_9.5.json)** | x86_64 | [![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-debian-9_5/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-debian-9_5)|
2521
|**[Windows 2019](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_windows_2019.json)** | x86_64 | [![Build Status](https://ci-external.swift.org/job/oss-swift-windows-x86_64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-windows-x86_64)|
2622

23+
**Swift TensorFlow Community-Hosted CI Platforms**
24+
25+
| **OS** | **Architecture** | **Build** |
26+
|---|:---:|:---:|
27+
|**[Ubuntu 16.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow)|
28+
|**[macOS 10.13](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_macos_high_sierra_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow)|
29+
|**[Ubuntu 16.04 (GPU)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_tensorflow_gpu.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-tensorflow-gpu)|
2730

2831
## Welcome to Swift
2932

branches/master-next/cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,13 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
118118
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/AttributeNodes.py"
119119
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/AvailabilityNodes.py"
120120
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/CommonNodes.py"
121+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/CompletionOnlyNodes.py"
121122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
122123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
123124
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
125+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/NodeSerializationCodes.py"
124126
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
127+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/SILOnlyNodes.py"
125128
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
126129
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"
127130
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Token.py"

branches/master-next/cmake/modules/SwiftSource.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,13 @@ function(_compile_swift_files
310310
set(module_base "${module_dir}/${SWIFTFILE_MODULE_NAME}")
311311
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
312312
set(specific_module_dir "${module_base}.swiftmodule")
313+
set(specific_module_private_dir "${specific_module_dir}/Private")
314+
set(source_info_file "${specific_module_private_dir}/${SWIFTFILE_ARCHITECTURE}.swiftsourceinfo")
313315
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
314316
else()
315317
set(specific_module_dir)
318+
set(specific_module_private_dir)
319+
set(source_info_file "${module_base}.swiftsourceinfo")
316320
endif()
317321
set(module_file "${module_base}.swiftmodule")
318322
set(module_doc_file "${module_base}.swiftdoc")
@@ -322,6 +326,8 @@ function(_compile_swift_files
322326
set(sib_file "${module_base}.Onone.sib")
323327
set(sibopt_file "${module_base}.O.sib")
324328
set(sibgen_file "${module_base}.sibgen")
329+
list(APPEND swift_module_flags
330+
"-emit-module-source-info-path" "${source_info_file}")
325331

326332
if(SWIFT_ENABLE_MODULE_INTERFACES)
327333
set(interface_file "${module_base}.swiftinterface")
@@ -349,7 +355,8 @@ function(_compile_swift_files
349355
swift_install_in_component(DIRECTORY "${specific_module_dir}"
350356
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
351357
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}"
352-
OPTIONAL)
358+
OPTIONAL
359+
PATTERN "Private" EXCLUDE)
353360
else()
354361
swift_install_in_component(FILES ${module_outputs}
355362
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
@@ -490,6 +497,7 @@ function(_compile_swift_files
490497
COMMAND
491498
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
492499
${specific_module_dir}
500+
${specific_module_private_dir}
493501
COMMAND
494502
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
495503
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"

branches/master-next/docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Entities
290290
entity-spec ::= type 'fu' INDEX // implicit anonymous closure
291291
entity-spec ::= 'fA' INDEX // default argument N+1 generator
292292
entity-spec ::= 'fi' // non-local variable initializer
293+
entity-spec ::= 'fP' // property wrapper backing initializer
293294
entity-spec ::= 'fD' // deallocating destructor; untyped
294295
entity-spec ::= 'fd' // non-deallocating destructor; untyped
295296
entity-spec ::= 'fE' // ivar destroyer; untyped

branches/master-next/docs/CToSwiftNameTranslation.md

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Name Translation from C to Swift
22

3-
This document gives a high-level description of how C and Objective-C declarations are translated to Swift, with particular focus on how names are adjusted. It is not attempting to be a *complete* description of everything the compiler does except with regards to how *names* are transformed; even there, some special cases that only apply to Apple's SDKs have been omitted.
3+
This document gives a high-level description of how C and Objective-C declarations are translated to Swift, with particular focus on how names are adjusted. It is not attempting to be a *complete* description of everything the compiler does except with regards to how *names* are transformed; even there, some special cases that only apply to Apple's SDKs have been omitted. The example code shown is for illustrative purposes and does not always include all parts of an imported API's interface.
44

55
## Word boundaries
66

@@ -239,4 +239,208 @@ _The original intent of the `swift_private` attribute was additionally to limit
239239
_For "historical reasons", the `swift_private` attribute is ignored on factory methods with no arguments imported as initializers. This is essentially matching the behavior of older Swift compilers for source compatibility in case someone has marked such a factory method as `swift_private`._
240240

241241

242+
## Custom names
243+
244+
The `swift_name` Clang attribute can be used to control how a declaration imports into Swift. If it's valid, the value of the `swift_name` attribute always overrides any other name transformation rules (prefix-stripping, underscore-prepending, etc.)
245+
246+
### Types and globals
247+
248+
The `swift_name` attribute can be used to give a type or a global a custom name. In the simplest form, the value of the attribute must be a valid Swift identifier.
249+
250+
```objc
251+
__attribute__((swift_name("SpacecraftCoordinates")))
252+
struct SPKSpacecraftCoordinates {
253+
double x, y, z, t; // space and time, of course
254+
};
255+
```
256+
257+
```swift
258+
struct SpacecraftCoordinates {
259+
var x, y, z, t: Double
260+
}
261+
```
262+
263+
### Import-as-member
264+
265+
A custom name that starts with an identifier followed by a period is taken to be a member name. The identifier should be the imported Swift name of a C/Objective-C type in the same module. In this case, the type or global will be imported as a static member of the named type.
266+
267+
```objc
268+
__attribute__((swift_name("SpacecraftCoordinates.earth")))
269+
extern const struct SPKSpacecraftCoordinates SPKSpacecraftCoordinatesEarth;
270+
```
271+
272+
```swift
273+
extension SpacecraftCoordinates {
274+
static var earth: SpacecraftCoordinates { get }
275+
}
276+
```
277+
278+
Note that types cannot be imported as members of protocols.
279+
280+
_The "in the same module" restriction is considered a technical limitation; a forward declaration of the base type will work around it._
281+
282+
283+
### C functions with custom names
284+
285+
The `swift_name` attribute can be used to give a C function a custom name. The value of the attribute must be a full Swift function name, including parameter labels.
286+
287+
```objc
288+
__attribute__((swift_name("doSomething(to:bar:)")))
289+
void doSomethingToFoo(Foo *foo, int bar);
290+
291+
// Usually seen as NS_SWIFT_NAME.
292+
```
293+
294+
```swift
295+
func doSomething(foo: UnsafeMutablePointer<Foo>, bar: Int32)
296+
```
297+
298+
An underscore can be used in place of an empty parameter label, as in Swift.
299+
300+
A C function with zero arguments and a non-`void` return type can also be imported as a computed variable by using the `getter:` prefix on the name. A function with one argument and a `void` return type can optionally serve as the setter for that variable using `setter:`.
301+
302+
```objc
303+
__attribute__((swift_name("getter:globalCounter()")))
304+
int getGlobalCounter(void);
305+
__attribute__((swift_name("setter:globalCounter(_:)")))
306+
void setGlobalCounter(int newValue);
307+
```
308+
309+
```swift
310+
var globalCounter: Int32 { get set }
311+
```
312+
313+
Note that the argument lists must still be present even though the name used is the name of the variable. (Also note the `void` parameter list to specify a C function with zero arguments. This is required!)
314+
315+
Variables with setters and no getters are not supported.
316+
317+
318+
#### Import-as-member
319+
320+
Like types and globals, functions can be imported as static members of types.
321+
322+
```objc
323+
__attribute__((swift_name("NSSound.beep()")))
324+
void NSBeep(void);
325+
```
326+
327+
```swift
328+
extension NSSound {
329+
static func beep()
330+
}
331+
```
332+
333+
However, by giving a parameter the label `self`, a function can also be imported as an instance member of a type __T__. In this case, the parameter labeled `self` must either have the type __T__ itself, or be a pointer to __T__. The latter is only valid if __T__ is imported as a value type; if the pointer is non-`const`, the resulting method will be `mutating`. If __T__ is a class, the function will be `final`.
334+
335+
```objc
336+
typedef struct {
337+
int value;
338+
} Counter;
339+
340+
__attribute__((swift_name("Counter.printValue(self:)")))
341+
void CounterPrintValue(Counter c);
342+
__attribute__((swift_name("Counter.printValue2(self:)")))
343+
void CounterPrintValue2(const Counter *c);
344+
__attribute__((swift_name("Counter.resetValue(self:)")))
345+
void CounterResetValue(Counter *c);
346+
```
347+
348+
```swift
349+
struct Counter {
350+
var value: Int32 { get set }
351+
}
352+
353+
extension Counter {
354+
func printValue()
355+
func printValue2()
356+
mutating func resetValue()
357+
}
358+
```
359+
360+
This also applies to getters and setters, to be imported as instance properties.
361+
362+
```objc
363+
__attribute__((swift_name("getter:Counter.absoluteValue(self:)")))
364+
int CounterGetAbsoluteValue(Counter c);
365+
```
366+
367+
```swift
368+
extension Counter {
369+
var absoluteValue: Int32 { get }
370+
}
371+
```
372+
373+
The getter/setter syntax also allows for subscripts by using the base name `subscript`.
374+
375+
```objc
376+
__attribute__((swift_name("getter:LinkedListOfInts.subscript(self:_:)")))
377+
int LinkedListGetAtIndex(const LinkedListOfInts *head, int index);
378+
```
379+
380+
```swift
381+
extension LinkedListOfInts {
382+
subscript(_ index: Int32) -> Int32 { get }
383+
}
384+
```
385+
386+
Finally, functions can be imported as initializers as well by using the base name `init`. These are considered "factory" initializers and are never inherited or overridable. They must not have a `self` parameter.
387+
388+
```objc
389+
__attribute__((swift_name("Counter.init(initialValue:)")))
390+
Counter CounterCreateWithInitialValue(int value);
391+
```
392+
393+
```swift
394+
extension Counter {
395+
/* non-inherited */ init(initialValue value: Int32)
396+
}
397+
```
398+
399+
400+
### Enumerators (enum cases)
401+
402+
The `swift_name` attribute can be used to rename enumerators. As mentioned above, not only does no further prefix-stripping occur on the resulting name, but the presence of a custom name removes the enum case from the computation of a prefix for the other cases.
403+
404+
```
405+
// Actual example from Apple's SDKs; in fact, the first shipping example of
406+
// swift_name on an enumerator at all!
407+
typedef NS_ENUM(NSUInteger, NSXMLNodeKind) {
408+
NSXMLInvalidKind = 0,
409+
NSXMLDocumentKind,
410+
NSXMLElementKind,
411+
NSXMLAttributeKind,
412+
NSXMLNamespaceKind,
413+
NSXMLProcessingInstructionKind,
414+
NSXMLCommentKind,
415+
NSXMLTextKind,
416+
NSXMLDTDKind NS_SWIFT_NAME(DTDKind),
417+
NSXMLEntityDeclarationKind,
418+
NSXMLAttributeDeclarationKind,
419+
NSXMLElementDeclarationKind,
420+
NSXMLNotationDeclarationKind
421+
};
422+
```
423+
424+
```
425+
public enum Kind : UInt {
426+
case invalid
427+
case document
428+
case element
429+
case attribute
430+
case namespace
431+
case processingInstruction
432+
case comment
433+
case text
434+
case DTDKind
435+
case entityDeclaration
436+
case attributeDeclaration
437+
case elementDeclaration
438+
case notationDeclaration
439+
}
440+
```
441+
442+
Although enumerators always have global scope in C, they are often imported as members in Swift, and thus the `swift_name` attribute cannot be used to import them as members of another type unless the enum type is anonymous.
443+
444+
_Currently, `swift_name` does not even allow importing an enum case as a member of the enum type itself, even if the enum is not recognized as an `@objc` enum, error code enum, or option set (i.e. the situation where a case is imported as a global constant)._
445+
242446
## More to come...

0 commit comments

Comments
 (0)