Skip to content

Commit cf4bafe

Browse files
author
Max Moiseev
committed
Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines
2 parents 27c4074 + 502c10f commit cf4bafe

File tree

231 files changed

+8372
-3062
lines changed

Some content is hidden

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

231 files changed

+8372
-3062
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ Swift 3
1717
A new argument to swiftc is provided to select the linker used, and the gold linker
1818
is set as the default for arm-based platforms.
1919

20+
* Catch blocks in `rethrows` functions may now `throw` errors. For example:
21+
22+
```swift
23+
func process(f: () throws -> Int) rethrows -> Int {
24+
do {
25+
return try f()
26+
} catch is SomeError {
27+
throw OtherError()
28+
}
29+
}
30+
```
31+
2032
Swift 2.2
2133
---------
2234

CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ set(SWIFT_NATIVE_SWIFT_TOOLS_PATH "" CACHE STRING
125125
option(SWIFT_ENABLE_LTO
126126
"If set to true, build the swift compiler with link time optimization enabled" FALSE)
127127

128+
# The following only works with the Ninja generator in CMake >= 3.0.
129+
set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
130+
"Define the maximum number of linker jobs for swift.")
131+
128132
#
129133
# User-configurable Darwin-specific options.
130134
#
@@ -623,9 +627,19 @@ foreach(sdk ${SWIFT_SDKS})
623627
unset(UNIVERSAL_LIBRARY_NAMES_${SWIFT_SDK_${sdk}_LIB_SUBDIR} CACHE)
624628
endforeach()
625629

630+
if(SWIFT_PARALLEL_LINK_JOBS)
631+
if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
632+
message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
633+
else()
634+
set_property(GLOBAL APPEND PROPERTY JOB_POOLS swift_link_job_pool=${SWIFT_PARALLEL_LINK_JOBS})
635+
set(CMAKE_JOB_POOL_LINK swift_link_job_pool)
636+
endif()
637+
endif()
638+
626639
message(STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} ${SWIFT_HOST_VARIANT_ARCH}")
627640
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
628641
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
642+
message(STATUS " LTO: ${SWIFT_ENABLE_LTO}")
629643
message(STATUS "")
630644

631645
message(STATUS "Building Swift standard library and SDK overlays for SDKs: ${SWIFT_SDKS}")

benchmark/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set(SWIFT_BENCH_MODULES
8585
single-source/SuperChars
8686
single-source/TwoSum
8787
single-source/TypeFlood
88+
single-source/UTF8Decode
8889
single-source/Walsh
8990
single-source/XorLoop
9091
)

benchmark/README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@ To add a new multiple file test:
173173
The generator script looks for functions prefixed with `run_` in order to
174174
populate `utils/main.swift`.
175175

176-
Each iteration of work performed in the for-loop below should run in under a
177-
few milliseconds. The benchmark driver will automatically calculate the
178-
necessary number of iterations to run each benchmark in approximately one
179-
second.
176+
The benchmark driver will measure the time taken for `N = 1` and automatically calculate
177+
the necessary number of iterations `N` to run each benchmark in approximately one second,
178+
so the test should ideally run in a few milliseconds for `N = 1`. If the test contains
179+
any setup code before the loop, ensure the time spent on setup is insignificant compared to
180+
the time spent inside the loop (for `N = 1`) – otherwise the automatic calculation of `N` might be
181+
significantly off and any performance gains/regressions will be masked by the fixed setup time.
182+
If needed you can multiply N by a fixed amount (e.g. `1...100*N`) to achieve this.
183+
180184

181185
**Performance Test Template**
182186

benchmark/scripts/Benchmark_Driver

+25-25
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,31 @@ DRIVER_DIR = os.path.dirname(os.path.realpath(__file__))
3030
def parse_results(res, optset):
3131
# Parse lines like this
3232
# #,TEST,SAMPLES,MIN(μs),MAX(μs),MEAN(μs),SD(μs),MEDIAN(μs),PEAK_MEMORY(B)
33-
SCORERE = re.compile(r"(\d+),[ \t]*(\w+)," +
34-
",".join([r"[ \t]*([\d.]+)"] * 7))
33+
score_re = re.compile(r"(\d+),[ \t]*(\w+)," +
34+
",".join([r"[ \t]*([\d.]+)"] * 7))
3535
# The Totals line would be parsed like this.
36-
TOTALRE = re.compile(r"()(Totals)," +
37-
",".join([r"[ \t]*([\d.]+)"] * 7))
38-
KEYGROUP = 2
39-
VALGROUP = 4
40-
MEMGROUP = 9
36+
total_re = re.compile(r"()(Totals)," +
37+
",".join([r"[ \t]*([\d.]+)"] * 7))
38+
key_group = 2
39+
val_group = 4
40+
mem_group = 9
4141

4242
tests = []
4343
for line in res.split():
44-
m = SCORERE.match(line)
44+
m = score_re.match(line)
4545
if not m:
46-
m = TOTALRE.match(line)
46+
m = total_re.match(line)
4747
if not m:
4848
continue
49-
testresult = int(m.group(VALGROUP))
50-
testname = m.group(KEYGROUP)
49+
testresult = int(m.group(val_group))
50+
testname = m.group(key_group)
5151
test = {}
5252
test['Data'] = [testresult]
5353
test['Info'] = {}
5454
test['Name'] = "nts.swift/" + optset + "." + testname + ".exec"
5555
tests.append(test)
5656
if testname != 'Totals':
57-
mem_testresult = int(m.group(MEMGROUP))
57+
mem_testresult = int(m.group(mem_group))
5858
mem_test = {}
5959
mem_test['Data'] = [mem_testresult]
6060
mem_test['Info'] = {}
@@ -89,26 +89,26 @@ def instrument_test(driver_path, test, num_samples):
8989
[peak_memory])
9090

9191
# Average sample results
92-
NUM_SAMPLES_INDEX = 2
93-
MIN_INDEX = 3
94-
MAX_INDEX = 4
95-
AVG_START_INDEX = 5
92+
num_samples_index = 2
93+
min_index = 3
94+
max_index = 4
95+
avg_start_index = 5
9696

9797
# TODO: Correctly take stdev
9898
avg_test_output = test_outputs[0]
99-
avg_test_output[AVG_START_INDEX:] = map(int,
100-
avg_test_output[AVG_START_INDEX:])
99+
avg_test_output[avg_start_index:] = map(int,
100+
avg_test_output[avg_start_index:])
101101
for test_output in test_outputs[1:]:
102-
for i in range(AVG_START_INDEX, len(test_output)):
102+
for i in range(avg_start_index, len(test_output)):
103103
avg_test_output[i] += int(test_output[i])
104-
for i in range(AVG_START_INDEX, len(avg_test_output)):
104+
for i in range(avg_start_index, len(avg_test_output)):
105105
avg_test_output[i] = int(round(avg_test_output[i] /
106106
float(len(test_outputs))))
107-
avg_test_output[NUM_SAMPLES_INDEX] = num_samples
108-
avg_test_output[MIN_INDEX] = min(test_outputs,
109-
key=lambda x: x[MIN_INDEX])[MIN_INDEX]
110-
avg_test_output[MAX_INDEX] = max(test_outputs,
111-
key=lambda x: x[MAX_INDEX])[MAX_INDEX]
107+
avg_test_output[num_samples_index] = num_samples
108+
avg_test_output[min_index] = min(test_outputs,
109+
key=lambda x: x[min_index])[min_index]
110+
avg_test_output[max_index] = max(test_outputs,
111+
key=lambda x: x[max_index])[max_index]
112112
avg_test_output = map(str, avg_test_output)
113113

114114
return avg_test_output
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===--- UTF8Decode.swift -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
@inline(never)
16+
public func run_UTF8Decode(N: Int) {
17+
// 1-byte sequences
18+
// This test case is the longest as it's the most perfomance sensitive.
19+
let ascii = "Swift is a multi-paradigm, compiled programming language created for iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products. Swift is intended to be more resilient to erroneous code (\"safer\") than Objective-C and also more concise. It is built with the LLVM compiler framework included in Xcode 6 and later and uses the Objective-C runtime, which allows C, Objective-C, C++ and Swift code to run within a single program."
20+
// 2-byte sequences
21+
let russian = "Ру́сский язы́к один из восточнославянских языков, национальный язык русского народа."
22+
// 3-byte sequences
23+
let japanese = "日本語(にほんご、にっぽんご)は、主に日本国内や日本人同士の間で使われている言語である。"
24+
// 4-byte sequences
25+
// Most commonly emoji, which are usually mixed with other text.
26+
let emoji = "Panda 🐼, Dog 🐶, Cat 🐱, Mouse 🐭."
27+
28+
let strings = [ ascii, russian, japanese, emoji ].map { Array($0.utf8) }
29+
30+
func isEmpty(result: UnicodeDecodingResult) -> Bool {
31+
switch result {
32+
case .emptyInput:
33+
return true
34+
default:
35+
return false
36+
}
37+
}
38+
39+
for _ in 1...200*N {
40+
for string in strings {
41+
var it = string.makeIterator()
42+
var utf8 = UTF8()
43+
while !isEmpty(utf8.decode(&it)) { }
44+
}
45+
}
46+
}

benchmark/utils/main.swift

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import StringWalk
9090
import SuperChars
9191
import TwoSum
9292
import TypeFlood
93+
import UTF8Decode
9394
import Walsh
9495
import XorLoop
9596

@@ -171,6 +172,7 @@ precommitTests = [
171172
"SuperChars": run_SuperChars,
172173
"TwoSum": run_TwoSum,
173174
"TypeFlood": run_TypeFlood,
175+
"UTF8Decode": run_UTF8Decode,
174176
"Walsh": run_Walsh,
175177
"XorLoop": run_XorLoop,
176178
]

cmake/modules/AddSwift.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,9 @@ function(_add_swift_executable_single name)
18141814
COMPILE_FLAGS " ${c_compile_flags}")
18151815
set_property(TARGET ${name} APPEND_STRING PROPERTY
18161816
LINK_FLAGS " ${link_flags}")
1817-
1817+
if (SWIFT_PARALLEL_LINK_JOBS)
1818+
set_property(TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool)
1819+
endif()
18181820
set_output_directory(${name}
18191821
BINARY_DIR ${SWIFT_RUNTIME_OUTPUT_INTDIR}
18201822
LIBRARY_DIR ${SWIFT_LIBRARY_OUTPUT_INTDIR})

include/swift/ABI/MetadataValues.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,27 @@
2626

2727
namespace swift {
2828

29-
struct Metadata;
29+
struct InProcess;
30+
template <typename Runtime> struct TargetMetadata;
31+
using Metadata = TargetMetadata<InProcess>;
3032

3133
/// Kinds of Swift metadata records. Some of these are types, some
3234
/// aren't.
33-
enum class MetadataKind : uintptr_t {
35+
enum class MetadataKind : uint32_t {
3436
#define METADATAKIND(name, value) name = value,
3537
#define ABSTRACTMETADATAKIND(name, start, end) \
3638
name##_Start = start, name##_End = end,
3739
#include "MetadataKind.def"
3840
};
3941

42+
template <typename StoredPointer>
43+
bool metadataKindIsClass(StoredPointer Kind) {
44+
return Kind > static_cast<StoredPointer>(MetadataKind::NonIsaMetadata_End) ||
45+
Kind < static_cast<StoredPointer>(MetadataKind::NonIsaMetadata_Start);
46+
}
47+
4048
/// Kinds of Swift nominal type descriptor records.
41-
enum class NominalTypeKind : uintptr_t {
49+
enum class NominalTypeKind : uint32_t {
4250
#define NOMINALTYPEMETADATAKIND(name, value) name = value,
4351
#include "MetadataKind.def"
4452
};

include/swift/AST/ASTPrinter.h

+22
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace swift {
3535
enum class PrintNameContext {
3636
/// Normal context
3737
Normal,
38+
/// Keyword context, where no keywords are escaped.
39+
Keyword,
3840
/// Generic parameter context, where 'Self' is not escaped.
3941
GenericParameter,
4042
/// Function parameter context, where keywords other than let/var/inout are
@@ -43,6 +45,15 @@ enum class PrintNameContext {
4345
FunctionParameterLocal,
4446
};
4547

48+
/// Describes the kind of parameter-like entity being printed.
49+
/// E.g.
50+
/// \code
51+
/// func foo(<FunctionParameter>x: Int = 2</FunctionParameter>, ...)
52+
/// \endcode
53+
enum class PrintParameterKind {
54+
FunctionParameter,
55+
};
56+
4657
/// An abstract class used to print an AST.
4758
class ASTPrinter {
4859
unsigned CurrentIndentation = 0;
@@ -106,6 +117,11 @@ class ASTPrinter {
106117
virtual void printSynthesizedExtensionPost(const ExtensionDecl *ED,
107118
const NominalTypeDecl *NTD) {}
108119

120+
/// Called before printing a parameter-like entity.
121+
virtual void printParameterPre(PrintParameterKind Kind) {}
122+
/// Called after printing a parameter-like entity.
123+
virtual void printParameterPost(PrintParameterKind Kind) {}
124+
109125
/// Called before printing a name in the given context.
110126
virtual void printNamePre(PrintNameContext Context) {}
111127
/// Called after printing a name in the given context.
@@ -131,6 +147,12 @@ class ASTPrinter {
131147

132148
ASTPrinter &operator<<(DeclName name);
133149

150+
void printKeyword(StringRef Name) {
151+
callPrintNamePre(PrintNameContext::Keyword);
152+
*this << Name;
153+
printNamePost(PrintNameContext::Keyword);
154+
}
155+
134156
void printName(Identifier Name,
135157
PrintNameContext Context = PrintNameContext::Normal);
136158

include/swift/AST/Decl.h

+20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/AST/TypeAlignments.h"
2828
#include "swift/Basic/OptionalEnum.h"
2929
#include "swift/Basic/Range.h"
30+
#include "llvm/ADT/DenseMap.h"
3031
#include "llvm/ADT/DenseSet.h"
3132
#include "llvm/ADT/SmallPtrSet.h"
3233
#include "llvm/Support/TrailingObjects.h"
@@ -3350,6 +3351,8 @@ class ProtocolDecl : public NominalTypeDecl {
33503351

33513352
ArrayRef<ProtocolDecl *> InheritedProtocols;
33523353

3354+
llvm::DenseMap<ValueDecl *, ConcreteDeclRef> DefaultWitnesses;
3355+
33533356
/// True if the protocol has requirements that cannot be satisfied (e.g.
33543357
/// because they could not be imported from Objective-C).
33553358
unsigned HasMissingRequirements : 1;
@@ -3494,6 +3497,23 @@ class ProtocolDecl : public NominalTypeDecl {
34943497
HasMissingRequirements = newValue;
34953498
}
34963499

3500+
/// Returns the default witness for a requirement, or nullptr if there is
3501+
/// no default.
3502+
ConcreteDeclRef getDefaultWitness(ValueDecl *requirement) {
3503+
auto found = DefaultWitnesses.find(requirement);
3504+
if (found == DefaultWitnesses.end())
3505+
return nullptr;
3506+
return found->second;
3507+
}
3508+
3509+
/// Record the default witness for a requirement.
3510+
void setDefaultWitness(ValueDecl *requirement, ConcreteDeclRef witness) {
3511+
assert(witness);
3512+
auto pair = DefaultWitnesses.insert(std::make_pair(requirement, witness));
3513+
assert(pair.second && "Already have a default witness!");
3514+
(void) pair;
3515+
}
3516+
34973517
/// Set the list of inherited protocols.
34983518
void setInheritedProtocols(ArrayRef<ProtocolDecl *> protocols) {
34993519
assert(!InheritedProtocolsSet && "protocols already set");

include/swift/AST/DiagnosticsParse.def

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ NOTE(note_in_decl_extension,none,
148148
WARNING(inout_as_attr_deprecated,none,
149149
"'inout' before a parameter name is deprecated, place it before the parameter type instead",
150150
())
151+
WARNING(line_directive_style_deprecated,none,
152+
"#line directive is deprecated, please use #setline instead",
153+
())
151154

152155
ERROR(declaration_same_line_without_semi,none,
153156
"consecutive declarations on a line must be separated by ';'", ())
@@ -343,6 +346,8 @@ ERROR(subscript_static,none,
343346
"subscript cannot be marked %0", (StaticSpellingKind))
344347

345348
// initializer
349+
ERROR(invalid_nested_init,none,
350+
"missing '%select{super.|self.}0' at initializer invocation", (bool))
346351
ERROR(initializer_decl_wrong_scope,none,
347352
"initializers may only be declared within a type", ())
348353
ERROR(expected_lparen_initializer,PointsToFirstBadToken,

0 commit comments

Comments
 (0)