Skip to content

Commit 2c2850d

Browse files
authored
Merge branch 'master' into verifier-wording-fix
2 parents 768c438 + ea27bf6 commit 2c2850d

File tree

1,364 files changed

+34226
-13419
lines changed

Some content is hidden

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

1,364 files changed

+34226
-13419
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#==============================================================================#
2323
# Explicit files to ignore (only matches one).
2424
#==============================================================================#
25+
Brewfile.lock.json
2526
cscope.files
2627
cscope.out
2728
.vimrc

Brewfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
brew "cmake"
2+
brew "ninja"

CHANGELOG.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ CHANGELOG
66

77
| Version | Released | Toolchain |
88
| :--------------------- | :--------- | :---------- |
9-
| [Swift 5.2](#swift-52) | | |
9+
| [Swift 5.3](#swift-53) | | |
10+
| [Swift 5.2](#swift-52) | 2020-03-24 | Xcode 11.4 |
1011
| [Swift 5.1](#swift-51) | 2019-09-20 | Xcode 11.0 |
1112
| [Swift 5.0](#swift-50) | 2019-03-25 | Xcode 10.2 |
1213
| [Swift 4.2](#swift-42) | 2018-09-17 | Xcode 10.0 |
@@ -23,9 +24,25 @@ CHANGELOG
2324

2425
</details>
2526

26-
Swift Next
27+
Swift 5.3
2728
----------
2829

30+
* [SE-0280][]:
31+
32+
Enum cases can now satisfy static protocol requirements. A static get-only property of type `Self` can be witnessed by an enum case with no associated values and a static function with arguments and returning `Self` can be witnessed by an enum case with associated values.
33+
34+
```swift
35+
protocol P {
36+
static var foo: Self { get }
37+
static func bar(value: Int) -> Self
38+
}
39+
40+
enum E: P {
41+
case foo // matches 'static var foo'
42+
case bar(value: Int) // matches 'static func bar(value:)'
43+
}
44+
```
45+
2946
* [SE-0267][]:
3047

3148
Non-generic members that support a generic parameter list, including nested type declarations, are now allowed to carry a contextual `where` clause against outer generic parameters. Previously, such declarations could only be expressed by placing the member inside a dedicated constrained extension.
@@ -49,15 +66,15 @@ Swift Next
4966

5067
* [SR-75][]:
5168

52-
Unapplied references to protocol methods methods are now supported. Previously this
69+
Unapplied references to protocol methods are now supported. Previously this
5370
only worked for methods defined in structs, enums and classes.
5471

5572
```swift
5673
protocol Cat {
5774
func play(catToy: Toy)
5875
}
5976

60-
let fn = Cat.play
77+
let fn = Cat.play(catToy:)
6178
fn(myCat)(myToy)
6279
```
6380

@@ -97,9 +114,13 @@ Swift Next
97114
closure's capture list in addition to the existing 'use `self.` explicitly'
98115
fix-it.
99116

117+
**Add new entries to the top of this section, not here!**
118+
100119
Swift 5.2
101120
---------
102121

122+
### 2020-03-24 (Xcode 11.4)
123+
103124
* [SR-11841][]:
104125

105126
When chaining calls to `filter(_:)` on a lazy sequence or collection, the
@@ -292,8 +313,6 @@ Swift 5.2
292313
print(s[0])
293314
```
294315

295-
**Add new entries to the top of this section, not here!**
296-
297316
Swift 5.1
298317
---------
299318

@@ -7951,6 +7970,7 @@ Swift 1.0
79517970
[SE-0266]: <https://github.com/apple/swift-evolution/blob/master/proposals/0266-synthesized-comparable-for-enumerations.md>
79527971
[SE-0267]: <https://github.com/apple/swift-evolution/blob/master/proposals/0267-where-on-contextually-generic.md>
79537972
[SE-0269]: <https://github.com/apple/swift-evolution/blob/master/proposals/0269-implicit-self-explicit-capture.md>
7973+
[SE-0280]: <https://github.com/apple/swift-evolution/blob/master/proposals/0280-enum-cases-as-protocol-witnesses.md>
79547974

79557975
[SR-75]: <https://bugs.swift.org/browse/SR-75>
79567976
[SR-106]: <https://bugs.swift.org/browse/SR-106>

CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,13 +1027,11 @@ if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
10271027
set(SOURCEKIT_RUNTIME_DIR lib)
10281028
endif()
10291029
add_dependencies(sourcekit-inproc BlocksRuntime dispatch)
1030-
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "OSX|WINDOWS")
1031-
swift_install_in_component(FILES
1032-
$<TARGET_FILE:dispatch>
1033-
$<TARGET_FILE:BlocksRuntime>
1034-
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
1035-
COMPONENT sourcekit-inproc)
1036-
endif()
1030+
swift_install_in_component(FILES
1031+
$<TARGET_FILE:dispatch>
1032+
$<TARGET_FILE:BlocksRuntime>
1033+
DESTINATION ${SOURCEKIT_RUNTIME_DIR}
1034+
COMPONENT sourcekit-inproc)
10371035
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
10381036
swift_install_in_component(FILES
10391037
$<TARGET_LINKER_FILE:dispatch>

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Please make sure you use Python 2.x. Python 3.x is not supported currently.
9191

9292
#### macOS
9393

94-
To build for macOS, you need [Xcode 11.3](https://developer.apple.com/xcode/downloads/).
94+
To build for macOS, you need [Xcode 11.4](https://developer.apple.com/xcode/downloads/).
9595
The required version of Xcode changes frequently, and is often a beta release.
9696
Check this document or the host information on <https://ci.swift.org> for the
9797
current required version.
@@ -102,6 +102,12 @@ which can be installed via a package manager:
102102
**[Homebrew](https://brew.sh/)**
103103

104104
brew install cmake ninja
105+
106+
You can also use [homebrew-bundle](https://github.com/Homebrew/homebrew-bundle)
107+
from the root of this repository's working directory to install all of these
108+
dependencies:
109+
110+
brew bundle
105111

106112
**[MacPorts](https://macports.org)**
107113

@@ -359,7 +365,7 @@ expressed today.
359365

360366
### CMake
361367
[CMake](https://cmake.org) is the core infrastructure used to configure builds of
362-
Swift and its companion projects; at least version 3.4.3 is required.
368+
Swift and its companion projects; at least version 3.16.5 is required.
363369

364370
On macOS, you can download the [CMake Binary Distribution](https://cmake.org/download),
365371
bundled as an application, copy it to `/Applications`, and add the embedded

docs/ABI/Mangling.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ Types
517517
FUNCTION-KIND ::= 'C' // C function pointer type
518518
FUNCTION-KIND ::= 'A' // @auto_closure function type (escaping)
519519
FUNCTION-KIND ::= 'E' // function type (noescape)
520+
FUNCTION-KIND ::= 'F' // @differentiable function type
521+
FUNCTION-KIND ::= 'G' // @differentiable function type (escaping)
522+
FUNCTION-KIND ::= 'H' // @differentiable(linear) function type
523+
FUNCTION-KIND ::= 'I' // @differentiable(linear) function type (escaping)
520524

521525
function-signature ::= params-type params-type throws? // results and parameters
522526

@@ -585,14 +589,18 @@ mangled in to disambiguate.
585589
impl-function-type ::= type* 'I' FUNC-ATTRIBUTES '_'
586590
impl-function-type ::= type* generic-signature 'I' FUNC-ATTRIBUTES '_'
587591

588-
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? PARAM-CONVENTION* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION)?
592+
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? PARAM-CONVENTION* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION)?
589593

590594
PATTERN-SUBS ::= 's' // has pattern substitutions
591595
INVOCATION-SUB ::= 'I' // has invocation substitutions
592596
PSEUDO-GENERIC ::= 'P'
593597

594598
CALLEE-ESCAPE ::= 'e' // @escaping (inverse of SIL @noescape)
595599

600+
DIFFERENTIABILITY-KIND ::= DIFFERENTIABLE | LINEAR
601+
DIFFERENTIABLE ::= 'd' // @differentiable
602+
LINEAR ::= 'l' // @differentiable(linear)
603+
596604
CALLEE-CONVENTION ::= 'y' // @callee_unowned
597605
CALLEE-CONVENTION ::= 'g' // @callee_guaranteed
598606
CALLEE-CONVENTION ::= 'x' // @callee_owned

docs/CompilerPerformance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ compilers on hand while you're working.
570570
Total Execution Time: 0.0876 seconds (0.0877 wall clock)
571571
572572
---User Time--- --System Time-- --User+System-- ---Wall Time--- --- Name ---
573-
0.0241 ( 53.9%) 0.0394 ( 92.0%) 0.0635 ( 72.5%) 0.0635 ( 72.5%) Name binding
573+
0.0241 ( 53.9%) 0.0394 ( 92.0%) 0.0635 ( 72.5%) 0.0635 ( 72.5%) Import resolution
574574
0.0170 ( 38.0%) 0.0025 ( 5.8%) 0.0195 ( 22.3%) 0.0195 ( 22.2%) Type checking / Semantic analysis
575575
0.0013 ( 3.0%) 0.0004 ( 0.8%) 0.0017 ( 1.9%) 0.0017 ( 1.9%) LLVM output
576576
0.0010 ( 2.3%) 0.0003 ( 0.7%) 0.0013 ( 1.5%) 0.0013 ( 1.5%) SILGen

docs/CppInteroperabilityManifesto.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ public:
11031103
// C++ header imported in Swift.
11041104
11051105
struct Employee {
1106-
func mutable_name() -> UnsafeMutablePointer<std.string>
1106+
func mutable_company() -> UnsafeMutablePointer<std.string>
11071107
}
11081108
```
11091109

@@ -1536,7 +1536,7 @@ public moveonly struct File {
15361536

15371537
func useArrayOfFiles() {
15381538
var files: [File] = ...
1539-
consumeFile(files[0].move())
1539+
consumeFile(files[0].cxxMove())
15401540
}
15411541
```
15421542

docs/DebuggingTheCompiler.rst

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,66 @@ Debugging on SIL Level
164164
Options for Dumping the SIL
165165
~~~~~~~~~~~~~~~~~~~~~~~~~~~
166166

167-
Often it is not sufficient to dump the SIL at the beginning or end of the
168-
optimization pipeline.
169-
The SILPassManager supports useful options to dump the SIL also between
170-
pass runs.
167+
Often it is not sufficient to dump the SIL at the beginning or end of
168+
the optimization pipeline. The SILPassManager supports useful options
169+
to dump the SIL also between pass runs.
171170

172-
The option ``-Xllvm -sil-print-all`` dumps the whole SIL module after all
173-
passes. Although it prints only functions which were changed by a pass, the
174-
output can get *very* large.
171+
The SILPassManager's SIL dumping options vary along two orthogonal
172+
functional axes:
175173

176-
It is useful if you identified a problem in the final SIL and you want to
177-
check which pass did introduce the wrong SIL.
174+
1. Options that control if functions/modules are printed.
175+
2. Options that filter what is printed at those points.
178176

179-
There are several other options available, e.g. to filter the output by
180-
function names (``-Xllvm -sil-print-only-function``/``s``) or by pass names
181-
(``-Xllvm -sil-print-before``/``after``/``around``).
182-
For details see ``PassManager.cpp``.
177+
One generally always specifies an option of type 1 and optionally adds
178+
an option of type 2 to filter the output.
179+
180+
A short (non-exhaustive) list of type 1 options:
181+
182+
* ``-Xllvm -sil-print-all``: Print functions/modules when ever a
183+
function pass modifies a function and Print the entire module
184+
(modulo filtering) if a module pass modifies a SILModule.
185+
186+
A short (non-exhaustive) list of type 2 options:
187+
188+
* ``-Xllvm -sil-print-around=$PASS_NAME``: Print a function/module
189+
before and after a function pass with name ``$PASS_NAME`` runs on a
190+
function/module or dump a module before a module pass with name
191+
``$PASS_NAME`` runs on a module.
192+
193+
* ``-Xllvm -sil-print-before=$PASS_NAME``: Print a function/module
194+
before a function pass with name ``$PASS_NAME`` runs on a
195+
function/module or dump a module before a module pass with name
196+
``$PASS_NAME`` runs on a module. NOTE: This happens even without
197+
sil-print-all set!
198+
199+
* ``-Xllvm -sil-print-after=$PASS_NAME``: Print a function/module
200+
after a function pass with name ``$PASS_NAME`` runs on a
201+
function/module or dump a module before a module pass with name
202+
``$PASS_NAME`` runs on a module.
203+
204+
* ``-Xllvm '-sil-print-only-function=SWIFT_MANGLED_NAME'``: When ever
205+
one would print a function/module, only print the given function.
206+
207+
These options together allow one to visualize how a
208+
SILFunction/SILModule is optimized by the optimizer as each
209+
optimization pass runs easily via formulations like::
210+
211+
swiftc -Xllvm '-sil-print-only-function=$myMainFunction' -Xllvm -sil-print-all
212+
213+
NOTE: This may emit a lot of text to stderr, so be sure to pipe the
214+
output to a file.
215+
216+
Getting CommandLine for swift stdlib from Ninja
217+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218+
219+
If one builds swift using ninja and wants to dump the SIL of the
220+
stdlib using some of the SIL dumping options from the previous
221+
section, one can use the following one-liner::
222+
223+
ninja -t commands | grep swiftc | grep Swift.o | grep " -c "
224+
225+
This should give one a single command line that one can use for
226+
Swift.o, perfect for applying the previous sections options to.
183227

184228
Dumping the SIL and other Data in LLDB
185229
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -359,6 +403,17 @@ we know to ignore swift_getGenericMetadata 84 times, i.e.::
359403

360404
(lldb) br set -i 84 -n GlobalARCOpts::run
361405

406+
A final trick is that one can use the -R option to stop at a relative assembly
407+
address in lldb. Specifically, lldb resolves the breakpoint normally and then
408+
just adds the argument -R to the address. So for instance, if I want to stop at
409+
the address at +38 in the function with the name 'foo', I would write::
410+
411+
(lldb) br set -R 38 -n foo
412+
413+
Then lldb would add 38 to the offset of foo and break there. This is really
414+
useful in contexts where one wants to set a breakpoint at an assembly address
415+
that is stable across multiple different invocations of lldb.
416+
362417
LLDB Scripts
363418
~~~~~~~~~~~~
364419

docs/Diagnostics.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,34 @@ Most diagnostics have no reason to change behavior under editor mode. An example
9292

9393
### Educational Notes ###
9494

95-
**Note**: This feature is currently experimental. It can be enabled by passing the `-Xfrontend -enable-descriptive-diagnostics` flag.
95+
Educational notes are short-form documentation attached to a diagnostic which explain relevant language concepts. They are intended to further Swift's goal of progressive disclosure by providing a learning resource at the point of use when encountering an error message for the first time. In very limited circumstances, they also allow the main diagnostic message to use precise terminology (e.g. nominal types) which would otherwise be too unfriendly for beginners.
9696

97-
Educational notes are small snippets of documentation attached to a diagnostic which explain relevant language concepts. They are intended to further Swift's goal of progressive disclosure by providing a learning resource at the point of use for users encountering a new error message for the first time. In very limited circumstances, they also allow the main diagnostic message to use more precise and correct terminology (e.g. nominal types) which would otherwise be too unfriendly for beginners.
97+
When outputting diagnostics on the command line, educational notes will be printed after the main diagnostic body if enabled using the `-print-educational-notes` driver option. When presented in an IDE, it's expected they will be collapsed under a disclosure arrow, info button, or similar to avoid cluttering output.
9898

99-
When outputting diagnostics on the command line, educational notes will be printed after the main diagnostic body if descriptive diagnostics are enabled. When presented in an IDE, it's expected they will be collapsed under a disclosure arrow, info button, or similar to avoid cluttering output.
100-
101-
Generally speaking, a diagnostic should try to provide educational notes for any concepts/terminology which is difficult to understand from context or is especially subtle. Educational notes should:
102-
- Explain a single language concept. This makes them easy to reuse across diagnostics and helps keep them clear, concise, and easy to understand.
103-
- Be written in unabbreviated English. These are longer form messages compared to the main diagnostic, so there is no need to omit needless words and punctuation.
104-
- Not generally exceed 3-4 paragraphs. Educational notes should be clear and easily digestible. Messages which are too long also have the potential to create diagnostics UX issues in some contexts.
99+
Educational notes should:
100+
- Explain a single language concept. This makes them easy to reuse across related diagnostics and helps keep them clear, concise, and easy to understand.
101+
- Be written in unabbreviated English. These are longer-form messages compared to the main diagnostic, so there's no need to omit needless words and punctuation.
102+
- Not generally exceed 3-4 paragraphs. Educational notes should be clear and easily digestible. Messages which are too long also have the potential to create UX issues on the command line.
105103
- Be accessible. Educational notes should be beginner friendly and avoid assuming unnecesary prior knowledge. The goal is not only to help users understand what a diagnostic is telling them, but also to turn errors and warnings into "teachable moments".
106-
- Include references to relevant chapters of _The Swift Programming Language_ if applicable.
107-
- Be written in Markdown, but avoid excessive markup to avoid impacting the terminal UX.
104+
- Include references to relevant chapters of _The Swift Programming Language_.
105+
- Be written in Markdown, but avoid excessive markup which negatively impacts the terminal UX.
106+
107+
### Quick-Start Guide for Contributing New Educational Notes ###
108+
109+
Adding new educational notes is a great way to get familiar with the process of contributing to Swift, while also making a big impact!
108110

109111
To add a new educational note:
110-
1. Add a new Markdown file in the `userdocs/diagnostics/` directory containing the contents of the note.
111-
2. Associate the note with one or more diagnostics in EducationalNotes.def.
112+
1. Follow the [directions in the README](https://github.com/apple/swift#getting-sources-for-swift-and-related-projects) to checkout the Swift sources locally. Being able to build the Swift compiler is recommended, but not required, when contributing a new note.
113+
2. Identify a diagnostic to write an educational note for. To associate an educational note with a diagnostic name, you'll need to know its internal identifier. The easiest way to do this is to write a small program which triggers the diagnostic, and run it using the `-debug-diagnostic-names` compiler flag. This flag will cause the internal diagnostic identifier to be printed after the diagnostic message in square brackets.
114+
3. Find any closely related diagnostics. Sometimes, what appears to be one diagnostic from a user's perspective may have multiple variations internally. After determining a diagnostic's internal identifier, run a search for it in the compiler source. You should find:
115+
- An entry in a `Diagnostics*.def` file describing the diagnostic. If there are any closely related diagnostics the note should also be attached to, they can usually be found nearby.
116+
- Each point in the compiler source where the diagnostic is emitted. This can be helpful in determining the exact circumstances which cause it to be emitted.
117+
4. Add a new Markdown file in the `userdocs/diagnostics/` directory in the swift repository containing the contents of the note. When writing a note, keep the writing guidelines from the section above in mind. The existing notes in the directory are another useful guide.
118+
5. Associate the note with the appropriate diagnostics in `EducationalNotes.def`. An entry like `EDUCATIONAL_NOTES(property_wrapper_failable_init, "property-wrapper-requirements.md")` will associate the note with filename `property-wrapper-requirements.md` with the diagnostic having an internal identifier of `property_wrapper_failable_init`.
119+
6. If possible, rebuild the compiler and try recompiling your test program with `-print-educational-notes`. Your new note should appear after the diagnostic in the terminal.
120+
7. That's it! The new note is now ready to be submitted as a pull request on GitHub.
121+
122+
If you run into any issues or have questions while following the steps above, feel free to post a question on the Swift forums or open a work-in-progress pull request on GitHub.
112123

113124
### Format Specifiers ###
114125

0 commit comments

Comments
 (0)