Skip to content

Commit ffacf43

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents 6c39b60 + 78bf97c commit ffacf43

File tree

4 files changed

+54
-45
lines changed

4 files changed

+54
-45
lines changed

docs/WindowsBuild.md

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,16 @@ the other hand, `clang-cl` is able to build the runtime, which makes it
1717
possible to build and run all the components required for Swift natively on
1818
Windows.
1919

20+
clang should be 7.0 or newer. Visual Studio 2017 is needed in all cases as
21+
it provides some of the needed headers and libraries.
22+
2023
## `clang-cl`
21-
- Windows doesn't currently have a build script. You'll need to run commands
22-
manually to build Swift on Windows.
23-
- Windows support for Swift is a work in progress and may not work on your
24-
system, but it has been tested.
25-
- Using the latest Visual Studio version is recommended (tested with Visual
26-
Studio 2017 - Version 15.5.5). Swift may fail to build with older C++
27-
compilers.
28-
- Note that the release version of Swift on Windows may crash when you try to compile a
29-
Swift program. See bug report [SR-7867](https://bugs.swift.org/browse/SR-7867).
3024

3125
### 1. Install dependencies
32-
1. Latest version (2.7.12 tested) of [Python
33-
2](https://www.python.org/downloads/)
34-
1. Latest version (3.7.0-rc3 tested) of [CMake](https://cmake.org/download/)
35-
1. Latest version (1.7.1 tested) of
36-
[Ninja](https://github.com/ninja-build/ninja/releases/latest)
37-
1. Latest version (2015 Update 3 tested) of [Visual
38-
Studio](https://www.visualstudio.com/downloads/)
26+
1. Latest version of [Visual Studio](https://www.visualstudio.com/downloads/)
3927
- Make sure to include "Programming Languages|Visual C++" and "Windows and Web
4028
Development|Universal Windows App Development|Windows SDK" in your
4129
installation.
42-
- Make sure to add Python, CMake and Ninja to your `Path` environment variable
4330

4431
### 2. Clone the repositories
4532
1. Create a folder to contain all the Swift repositories
@@ -48,6 +35,7 @@ Windows.
4835
1. Clone `apple/swift-llvm` into a folder named `llvm`
4936
1. Clone `apple/swift-compiler-rt` into a folder named `compiler-rt`
5037
1. Clone `apple/swift` into a folder named `swift`
38+
1. Clone `apple/swift-corelibs-libdispatch` into a folder named `swift-corelibs-libdispatch`
5139
- Currently, other repositories in the Swift project have not been tested and
5240
may not be supported.
5341

@@ -89,11 +77,9 @@ set swift_source_dir=path-to-directory-containing-all-cloned-repositories
8977
(`Debug`, `RelWithDebInfoAssert` or `Release`) to avoid conflicts between the debug and
9078
non-debug version of the MSCRT library.
9179

92-
- Set up the `visualc` and `ucrt` modules by copying `ucrt.modulemap` located at
80+
- Set up the `ucrt`, `visualc`, and `WinSDK` modules by copying `ucrt.modulemap` located at
9381
`swift/stdlib/public/Platform/ucrt.modulemap` into
94-
`${UniversalCRTSdkDir}/Include/${UCRTVersion}/ucrt` as `module.modulemap` and copying `visualc.modulemap` located at `swift/stdlib/public/Platform/visualc.modulemap` into `${VCToolsInstallDir}/include` as `module.modulemap`
95-
96-
82+
`${UniversalCRTSdkDir}/Include/${UCRTVersion}/ucrt` as `module.modulemap`, copying `visualc.modulemap` located at `swift/stdlib/public/Platform/visualc.modulemap` into `${VCToolsInstallDir}/include` as `module.modulemap`, and copying `winsdk.modulemap` located at `swift/stdlib/public/Platform/winsdk.modulemap` into `${UniversalCRTSdkDir}/Include/10.0.107663/um`
9783

9884
### 5. Build CMark
9985
- This must be done from within a developer command prompt. CMark is a fairly
@@ -143,7 +129,7 @@ set llvm_bin_dir="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64/
143129
```cmd
144130
mkdir "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
145131
pushd "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
146-
cmake -G "Ninja" "%swift_source_dir%/swift"^
132+
cmake -G "Ninja"^
147133
-DCMAKE_BUILD_TYPE=Debug^
148134
-DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
149135
-DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64"^
@@ -152,24 +138,22 @@ cmake -G "Ninja" "%swift_source_dir%/swift"^
152138
-DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
153139
-DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^
154140
-DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
155-
-DICU_UC_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
156-
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
157-
-DICU_I18N_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
158-
-DICU_I18N_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
159-
-DICU_UC_LIB_NAME="icuuc"^
160-
-DICU_I18N_LIB_NAME="icuin"^
141+
-DICU_WINDOWS_x86_64_UC_INCLUDE="%swift_source_dir%/icu/include"^
142+
-DICU_WINDOWS_x86_64_UC_LIBRARY="%swift_source_dir%/icu/lib64/icuuc.lib"^
143+
-DICU_WINDOWS_x86_64_I18N_INCLUDE="%swift_source_dir%/icu/include"^
144+
-DICU_WINDOWS_x86_64_I18N_LIBRARY="%swift_source_dir%/icu/lib64/icuin.lib"^
161145
-DSWIFT_INCLUDE_DOCS=FALSE^
162146
-DSWIFT_INCLUDE_TESTS=FALSE^
163147
-DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
164148
-DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
165-
-DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^
166-
-DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 -Z7"^
149+
-DCMAKE_C_FLAGS="/Z7"^
150+
-DCMAKE_CXX_FLAGS="/Z7 -Wno-c++98-compat -Wno-c++98-compat-pedantic"^
167151
-DCMAKE_EXE_LINKER_FLAGS:STRING="/INCREMENTAL:NO"^
168152
-DCMAKE_MODULE_LINKER_FLAGS="/INCREMENTAL:NO"^
169153
-DCMAKE_SHARED_LINKER_FLAGS="/INCREMENTAL:NO"^
170154
-DCMAKE_STATIC_LINKER_FLAGS="/INCREMENTAL:NO"^
171155
-DCMAKE_INSTALL_PREFIX="C:/Program Files (x86)/Swift"^
172-
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE
156+
"%swift_source_dir%/swift"
173157
popd
174158
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
175159
```
@@ -182,7 +166,7 @@ cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
182166
a file.
183167

184168
```cmd
185-
cmake -G "Visual Studio 15" "%swift_source_dir%/swift"^
169+
cmake -G "Visual Studio 2017" "%swift_source_dir%/swift"^
186170
-DCMAKE_GENERATOR_PLATFORM="x64"^
187171
...
188172
```
@@ -205,8 +189,8 @@ cmake -G "Ninja" "%swift_source_dir%/lldb"^
205189
-DLLDB_PATH_TO_SWIFT_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"^
206190
-DCMAKE_C_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
207191
-DCMAKE_CXX_COMPILER="%llvm_bin_dir%/clang-cl.exe"^
208-
-DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 /Z7"^
209-
-DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 -Z7 -Wno-c++98-compat"^
192+
-DCMAKE_C_FLAGS="/Z7"^
193+
-DCMAKE_CXX_FLAGS="/Z7 -Wno-c++98-compat"^
210194
-DLLVM_ENABLE_ASSERTIONS=YES
211195
popd
212196
cmake --build "%swift_source_dir%/build/Ninja-RelWithDebInfoAssert/lldb-windows-amd64"
@@ -232,7 +216,7 @@ Follow instructions 1-6 for `clang-cl`, but run the following instead to build S
232216
```cmd
233217
mkdir "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
234218
pushd "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
235-
cmake -G "Ninja" "%swift_source_dir%/swift"^
219+
cmake -G "Ninja"^
236220
-DCMAKE_BUILD_TYPE=Debug^
237221
-DSWIFT_PATH_TO_CMARK_SOURCE="%swift_source_dir%/cmark"^
238222
-DSWIFT_PATH_TO_CMARK_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/cmark-windows-amd64"^
@@ -241,16 +225,15 @@ cmake -G "Ninja" "%swift_source_dir%/swift"^
241225
-DSWIFT_PATH_TO_LLVM_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
242226
-DSWIFT_PATH_TO_CLANG_SOURCE="%swift_source_dir%/llvm/tools/clang"^
243227
-DSWIFT_PATH_TO_CLANG_BUILD="%swift_source_dir%/build/Ninja-DebugAssert/llvm-windows-amd64"^
244-
-DICU_UC_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
245-
-DICU_UC_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
246-
-DICU_I18N_INCLUDE_DIRS="%swift_source_dir%/icu/include"^
247-
-DICU_I18N_LIBRARY_DIRS="%swift_source_dir%/icu/lib64"^
248-
-DICU_UC_LIB_NAME="icuuc"^
249-
-DICU_I18N_LIB_NAME="icuin"^
228+
-DICU_WINDOWS_x86_64_UC_INCLUDE="%swift_source_dir%/icu/include"^
229+
-DICU_WINDOWS_x86_64_UC_LIBRARY="%swift_source_dir%/icu/lib64/icuuc.lib"^
230+
-DICU_WINDOWS_x86_64_I18N_INCLUDE="%swift_source_dir%/icu/include"^
231+
-DICU_WINDOWS_x86_64_I18N_LIBRARY="%swift_source_dir%/icu/lib64/icuin.lib"^
250232
-DSWIFT_INCLUDE_DOCS=FALSE^
251233
-DSWIFT_INCLUDE_TESTS=FALSE^
252234
-DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY=FALSE^
253-
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE
235+
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER=FALSE^
236+
"%swift_source_dir%/swift"
254237
popd
255238
cmake --build "%swift_source_dir%/build/Ninja-DebugAssert/swift-windows-amd64"
256239
```

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2944,8 +2944,11 @@ ERROR(closure_implicit_capture_without_noescape,none,
29442944
"escaping closures can only capture inout parameters explicitly by value",
29452945
())
29462946
ERROR(closure_implicit_capture_mutating_self,none,
2947-
"closure cannot implicitly capture a mutating self parameter",
2947+
"escaping closure cannot capture a mutating self parameter",
29482948
())
2949+
NOTE(create_mutating_copy_or_capture_self,none,
2950+
"create a mutating copy of self, or explicitly capture self for immutability",
2951+
())
29492952
ERROR(nested_function_with_implicit_capture_argument,none,
29502953
"nested function with %select{an |}0implicitly captured inout "
29512954
"parameter%select{|s}0 can only be used as a non-escaping argument", (bool))

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ class FindCapturedVars : public ASTWalker {
402402
if (isInOut && !AFR.isKnownNoEscape() && !isNested) {
403403
if (D->getBaseName() == D->getASTContext().Id_self) {
404404
TC.diagnose(DRE->getLoc(),
405-
diag::closure_implicit_capture_mutating_self);
405+
diag::closure_implicit_capture_mutating_self);
406+
TC.diagnose(DRE->getLoc(),
407+
diag::create_mutating_copy_or_capture_self);
406408
} else {
407409
TC.diagnose(DRE->getLoc(),
408410
diag::closure_implicit_capture_without_noescape);

test/Sema/diag_invalid_inout_captures.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ func do_escape(_ not_a_price_you_are_willing_to_pay: @escaping () -> ()) {}
66
struct you_cry_in_your_tea {
77
mutating func which_you_hurl_in_the_sea_when_you_see_me_go_by() {
88
no_escape { _ = self } // OK
9-
do_escape { _ = self } // expected-error {{closure cannot implicitly capture a mutating self parameter}}
9+
do_escape { _ = self } // expected-error {{escaping closure cannot capture a mutating self parameter}}
10+
// expected-note@-1 {{create a mutating copy of self, or explicitly capture self for immutability}}
1011
do_escape {
1112
[self] in
1213
_ = self // OK
@@ -40,3 +41,23 @@ func remember(line: inout String) -> () -> Void {
4041
func its_complicated(condition: inout Int) {
4142
no_escape(condition == 0 ? { condition = 1 } : { condition = 2}) // expected-error 2 {{escaping closures can only capture inout parameters explicitly by value}}
4243
}
44+
45+
// rdar://problem/46322943 - Improve error message about mutating self capture in escaping closures
46+
func rdar46322943() {
47+
struct S {
48+
var bar = 1
49+
50+
func foo(_ fn: () -> Void) {
51+
fn()
52+
}
53+
54+
mutating func main() {
55+
let fn = {
56+
self.bar += 1
57+
// expected-error@-1 {{escaping closure cannot capture a mutating self parameter}}
58+
// expected-note@-2 {{create a mutating copy of self, or explicitly capture self for immutability}}
59+
}
60+
self.foo(fn)
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)