Skip to content

Commit d04663a

Browse files
committed
Merge branch 'master' into warn-on-empty-optionset-static-constants
2 parents 9cc2d65 + 6d178e8 commit d04663a

File tree

585 files changed

+14398
-12317
lines changed

Some content is hidden

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

585 files changed

+14398
-12317
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
33

44
<!-- If this pull request resolves any bugs in the Swift bug tracker, provide a link: -->
5-
Resolves [SR-NNNN](https://bugs.swift.org/browse/SR-NNNN).
5+
Resolves SR-NNNN.
66

77
<!--
88
Before merging this pull request, you must run the Swift continuous integration tests.

CHANGELOG.md

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ CHANGELOG
2626
Swift 5.2
2727
---------
2828

29+
* [SR-2189][]:
30+
31+
The compiler now supports local functions whose default arguments capture
32+
values from outer scopes.
33+
34+
```swift
35+
func outer(x: Int) -> (Int, Int) {
36+
func inner(y: Int = x) -> Int {
37+
return y
38+
}
39+
40+
return (inner(), inner(y: 0))
41+
}
42+
```
43+
2944
* [SR-11429][]:
3045

3146
The compiler will now correctly strip argument labels from function references
@@ -80,40 +95,6 @@ Swift 5.2
8095
}
8196
}
8297
```
83-
84-
As a result, this could lead to code that currently compiles today to throw an error.
85-
86-
```swift
87-
protocol Foo {
88-
var someProperty: Int { get set }
89-
}
90-
91-
class Bar: Foo {
92-
var someProperty = 0
93-
}
94-
95-
extension Foo where Self: Bar {
96-
var anotherProperty1: Int {
97-
get { return someProperty }
98-
// This will now error, because the protocol requirement
99-
// is implicitly mutating and the setter is implicitly
100-
// nonmutating.
101-
set { someProperty = newValue } // Error
102-
}
103-
}
104-
```
105-
106-
**Workaround**: Define a new mutable variable inside the setter that has a reference to `self`:
107-
108-
```swift
109-
var anotherProperty1: Int {
110-
get { return someProperty }
111-
set {
112-
var mutableSelf = self
113-
mutableSelf.someProperty = newValue // Okay
114-
}
115-
}
116-
```
11798

11899
* [SE-0253][]:
119100

@@ -7837,6 +7818,7 @@ Swift 1.0
78377818
[SR-1529]: <https://bugs.swift.org/browse/SR-1529>
78387819
[SR-2131]: <https://bugs.swift.org/browse/SR-2131>
78397820
[SR-2176]: <https://bugs.swift.org/browse/SR-2176>
7821+
[SR-2189]: <https://bugs.swift.org/browse/SR-2189>
78407822
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
78417823
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
78427824
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>

CMakeLists.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ endif()
1111
list(APPEND CMAKE_MODULE_PATH
1212
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
1313

14+
set(CMAKE_DISABLE_IN_SOURCE_BUILD YES)
15+
1416
if(DEFINED CMAKE_JOB_POOLS)
1517
# CMake < 3.11 doesn't support CMAKE_JOB_POOLS. Manually set the property.
1618
set_property(GLOBAL PROPERTY JOB_POOLS "${CMAKE_JOB_POOLS}")
@@ -375,6 +377,10 @@ option(SWIFT_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING
375377
"Build stdlibCore with exclusivity checking enabled"
376378
FALSE)
377379

380+
option(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING
381+
"Enable experimental Swift differentiable programming features"
382+
FALSE)
383+
378384
#
379385
# End of user-configurable options.
380386
#
@@ -449,6 +455,10 @@ if(MSVC OR "${CMAKE_SIMULATE_ID}" STREQUAL MSVC)
449455
include(ClangClCompileRules)
450456
endif()
451457

458+
if(CMAKE_C_COMPILER_ID STREQUAL Clang)
459+
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-Werror=gnu>)
460+
endif()
461+
452462
if(CMAKE_SYSTEM_NAME STREQUAL Darwin OR
453463
EXISTS "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}")
454464
set(SWIFT_BUILD_SYNTAXPARSERLIB_default TRUE)
@@ -962,17 +972,14 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
962972
set(SWIFT_LIBDISPATCH_C_COMPILER ${CMAKE_C_COMPILER})
963973
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CMAKE_CXX_COMPILER})
964974
elseif(${CMAKE_SYSTEM_NAME} STREQUAL ${CMAKE_HOST_SYSTEM_NAME})
965-
get_target_property(CLANG_LOCATION clang LOCATION)
966-
get_filename_component(CLANG_LOCATION ${CLANG_LOCATION} DIRECTORY)
967-
968975
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
969976
set(SWIFT_LIBDISPATCH_C_COMPILER
970-
${CLANG_LOCATION}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
977+
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
971978
set(SWIFT_LIBDISPATCH_CXX_COMPILER
972-
${CLANG_LOCATION}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
979+
$<TARGET_FILE_DIR:clang>/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
973980
else()
974-
set(SWIFT_LIBDISPATCH_C_COMPILER ${CLANG_LOCATION}/clang)
975-
set(SWIFT_LIBDISPATCH_CXX_COMPILER ${CLANG_LOCATION}/clang++)
981+
set(SWIFT_LIBDISPATCH_C_COMPILER $<TARGET_FILE_DIR:clang>/clang)
982+
set(SWIFT_LIBDISPATCH_CXX_COMPILER $<TARGET_FILE_DIR:clang>/clang++)
976983
endif()
977984
else()
978985
message(SEND_ERROR "libdispatch requires a newer clang compiler (${CMAKE_C_COMPILER_VERSION} < 3.9)")

benchmark/scripts/run_smoke_bench

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def main():
9393
argparser.add_argument(
9494
'-num-samples', type=int,
9595
help='The (minimum) number of samples to run', default=3)
96+
argparser.add_argument(
97+
'-num-reruns', type=int,
98+
help="The number of re-runs until it's assumed to be a real change",
99+
default=8)
96100
argparser.add_argument(
97101
'-platform', type=str,
98102
help='The benchmark build platform', default='macosx')
@@ -120,7 +124,7 @@ def test_opt_levels(args):
120124
if test_performance(opt_level, args.oldbuilddir[0],
121125
args.newbuilddir[0],
122126
float(args.threshold) / 100, args.num_samples,
123-
output_file):
127+
args.num_reruns, output_file):
124128
changes = True
125129

126130
# There is no point in reporting code size for Onone.
@@ -171,7 +175,7 @@ def merge(results, other_results):
171175

172176

173177
def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
174-
output_file):
178+
num_reruns, output_file):
175179
"""Detect performance changes in benchmarks.
176180
177181
Start fast with few samples per benchmark and gradually spend more time
@@ -185,7 +189,7 @@ def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
185189
tests = TestComparator(results[0], results[1], threshold)
186190
changed = tests.decreased + tests.increased
187191

188-
while len(changed) > 0 and unchanged_length_count < 10:
192+
while len(changed) > 0 and unchanged_length_count < num_reruns:
189193
i += 1
190194
if VERBOSE:
191195
log(' test again: ' + str([test.name for test in changed]))

benchmark/single-source/ObjectiveCBridging.swift

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ public let ObjectiveCBridging = [
7979
BenchmarkInfo(name: "UnicodeStringFromCodable",
8080
runFunction: run_UnicodeStringFromCodable, tags: ts,
8181
setUpFunction: setup_UnicodeStringFromCodable),
82+
BenchmarkInfo(name: "NSArray.bridged.objectAtIndex",
83+
runFunction: run_BridgedNSArrayObjectAtIndex, tags: t,
84+
setUpFunction: setup_bridgedArrays),
85+
BenchmarkInfo(name: "NSArray.bridged.mutableCopy.objectAtIndex",
86+
runFunction: run_BridgedNSArrayMutableCopyObjectAtIndex, tags: t,
87+
setUpFunction: setup_bridgedArrays),
88+
BenchmarkInfo(name: "NSArray.nonbridged.objectAtIndex",
89+
runFunction: run_RealNSArrayObjectAtIndex, tags: t,
90+
setUpFunction: setup_bridgedArrays),
91+
BenchmarkInfo(name: "NSArray.nonbridged.mutableCopy.objectAtIndex",
92+
runFunction: run_RealNSArrayMutableCopyObjectAtIndex, tags: t,
93+
setUpFunction: setup_bridgedArrays),
8294
]
8395

8496
#if _runtime(_ObjC)
@@ -773,3 +785,65 @@ public func run_UnicodeStringFromCodable(_ N: Int) {
773785
}
774786
#endif
775787
}
788+
789+
#if _runtime(_ObjC)
790+
var bridgedArray:NSArray! = nil
791+
var bridgedArrayMutableCopy:NSMutableArray! = nil
792+
var nsArray:NSArray! = nil
793+
var nsArrayMutableCopy:NSMutableArray! = nil
794+
#endif
795+
796+
public func setup_bridgedArrays() {
797+
#if _runtime(_ObjC)
798+
var arr = Array(repeating: NSObject(), count: 100) as [AnyObject]
799+
bridgedArray = arr as NSArray
800+
bridgedArrayMutableCopy = (bridgedArray.mutableCopy() as! NSMutableArray)
801+
nsArray = NSArray(objects: &arr, count: 100)
802+
nsArrayMutableCopy = (nsArray.mutableCopy() as! NSMutableArray)
803+
#endif
804+
}
805+
806+
@inline(never)
807+
public func run_BridgedNSArrayObjectAtIndex(_ N: Int) {
808+
#if _runtime(_ObjC)
809+
for _ in 0 ..< N * 50 {
810+
for i in 0..<100 {
811+
blackHole(bridgedArray[i])
812+
}
813+
}
814+
#endif
815+
}
816+
817+
@inline(never)
818+
public func run_BridgedNSArrayMutableCopyObjectAtIndex(_ N: Int) {
819+
#if _runtime(_ObjC)
820+
for _ in 0 ..< N * 100 {
821+
for i in 0..<100 {
822+
blackHole(bridgedArrayMutableCopy[i])
823+
}
824+
}
825+
#endif
826+
}
827+
828+
@inline(never)
829+
public func run_RealNSArrayObjectAtIndex(_ N: Int) {
830+
#if _runtime(_ObjC)
831+
for _ in 0 ..< N * 100 {
832+
for i in 0..<100 {
833+
blackHole(nsArray[i])
834+
}
835+
}
836+
#endif
837+
}
838+
839+
@inline(never)
840+
public func run_RealNSArrayMutableCopyObjectAtIndex(_ N: Int) {
841+
#if _runtime(_ObjC)
842+
for _ in 0 ..< N * 100 {
843+
for i in 0..<100 {
844+
blackHole(nsArrayMutableCopy[i])
845+
}
846+
}
847+
#endif
848+
}
849+

benchmark/single-source/UTF8Decode.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public let UTF8Decode = [
4242
name: "UTF8Decode_InitFromBytes_ascii",
4343
runFunction: run_UTF8Decode_InitFromBytes_ascii,
4444
tags: [.validation, .api, .String]),
45+
BenchmarkInfo(
46+
name: "UTF8Decode_InitFromData_ascii_as_ascii",
47+
runFunction: run_UTF8Decode_InitFromData_ascii_as_ascii,
48+
tags: [.validation, .api, .String]),
49+
BenchmarkInfo(
50+
name: "UTF8Decode_InitDecoding_ascii_as_ascii",
51+
runFunction: run_UTF8Decode_InitDecoding_ascii_as_ascii,
52+
tags: [.validation, .api, .String]),
53+
BenchmarkInfo(
54+
name: "UTF8Decode_InitFromBytes_ascii_as_ascii",
55+
runFunction: run_UTF8Decode_InitFromBytes_ascii_as_ascii,
56+
tags: [.validation, .api, .String]),
4557
]
4658

4759
// 1-byte sequences
@@ -129,4 +141,26 @@ public func run_UTF8Decode_InitFromBytes_ascii(_ N: Int) {
129141
}
130142
}
131143

144+
@inline(never)
145+
public func run_UTF8Decode_InitFromData_ascii_as_ascii(_ N: Int) {
146+
let input = asciiData
147+
for _ in 0..<1_000*N {
148+
blackHole(String(data: input, encoding: .ascii))
149+
}
150+
}
151+
@inline(never)
152+
public func run_UTF8Decode_InitDecoding_ascii_as_ascii(_ N: Int) {
153+
let input = asciiBytes
154+
for _ in 0..<1_000*N {
155+
blackHole(String(decoding: input, as: Unicode.ASCII.self))
156+
}
157+
}
158+
@inline(never)
159+
public func run_UTF8Decode_InitFromBytes_ascii_as_ascii(_ N: Int) {
160+
let input = asciiBytes
161+
for _ in 0..<1_000*N {
162+
blackHole(String(bytes: input, encoding: .ascii))
163+
}
164+
}
165+
132166

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ function(_add_variant_swift_compile_flags
422422
list(APPEND result "-D" "SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS")
423423
endif()
424424

425+
if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
426+
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING")
427+
endif()
428+
425429
set("${result_var_name}" "${result}" PARENT_SCOPE)
426430
endfunction()
427431

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,11 @@ 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"
122121
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
123122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
124123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
125124
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/NodeSerializationCodes.py"
126125
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
127-
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/SILOnlyNodes.py"
128126
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
129127
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"
130128
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Token.py"

cmake/modules/SwiftSource.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ 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")
313+
set(specific_module_project_dir "${specific_module_dir}/Project")
314+
set(source_info_file "${specific_module_project_dir}/${SWIFTFILE_ARCHITECTURE}.swiftsourceinfo")
315315
set(module_base "${module_base}.swiftmodule/${SWIFTFILE_ARCHITECTURE}")
316316
else()
317317
set(specific_module_dir)
318-
set(specific_module_private_dir)
318+
set(specific_module_project_dir)
319319
set(source_info_file "${module_base}.swiftsourceinfo")
320320
endif()
321321
set(module_file "${module_base}.swiftmodule")
@@ -359,7 +359,7 @@ function(_compile_swift_files
359359
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
360360
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT}"
361361
OPTIONAL
362-
PATTERN "Private" EXCLUDE)
362+
PATTERN "Project" EXCLUDE)
363363
else()
364364
swift_install_in_component(FILES ${module_outputs}
365365
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/${library_subdir}"
@@ -500,7 +500,7 @@ function(_compile_swift_files
500500
COMMAND
501501
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
502502
${specific_module_dir}
503-
${specific_module_private_dir}
503+
${specific_module_project_dir}
504504
COMMAND
505505
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
506506
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}"

cmake/modules/SwiftWindowsSupport.cmake

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,19 @@ endfunction()
8484
macro(swift_swap_compiler_if_needed target)
8585
if(NOT CMAKE_C_COMPILER_ID MATCHES Clang)
8686
if(CMAKE_SYSTEM_NAME STREQUAL CMAKE_HOST_SYSTEM_NAME)
87-
get_target_property(CLANG_LOCATION clang LOCATION)
88-
get_filename_component(CLANG_LOCATION ${CLANG_LOCATION} DIRECTORY)
89-
90-
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR
91-
"${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
92-
set(CMAKE_C_COMPILER
93-
${CLANG_LOCATION}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
94-
set(CMAKE_CXX_COMPILER
95-
${CLANG_LOCATION}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
87+
if(SWIFT_BUILT_STANDALONE)
88+
get_target_property(CLANG_LOCATION clang LOCATION)
89+
get_filename_component(CLANG_LOCATION ${CLANG_LOCATION} DIRECTORY)
9690
else()
97-
set(CMAKE_C_COMPILER
98-
${CLANG_LOCATION}/clang${CMAKE_EXECUTABLE_SUFFIX})
99-
set(CMAKE_CXX_COMPILER
100-
${CLANG_LOCATION}/clang++${CMAKE_EXECUTABLE_SUFFIX})
91+
set(CLANG_LOCATION ${LLVM_RUNTIME_OUTPUT_INTDIR})
92+
endif()
93+
94+
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
95+
set(CMAKE_C_COMPILER ${CLANG_LOCATION}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
96+
set(CMAKE_CXX_COMPILER ${CLANG_LOCATION}/clang-cl${CMAKE_EXECUTABLE_SUFFIX})
97+
else()
98+
set(CMAKE_C_COMPILER ${CLANG_LOCATION}/clang${CMAKE_EXECUTABLE_SUFFIX})
99+
set(CMAKE_CXX_COMPILER ${CLANG_LOCATION}/clang++${CMAKE_EXECUTABLE_SUFFIX})
101100
endif()
102101
else()
103102
message(SEND_ERROR "${target} requires a clang based compiler")

0 commit comments

Comments
 (0)