Skip to content

Commit 81896e0

Browse files
---
yaml --- r: 343406 b: refs/heads/master-rebranch c: f055791 h: refs/heads/master
1 parent d60862b commit 81896e0

File tree

185 files changed

+4450
-5895
lines changed

Some content is hidden

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

185 files changed

+4450
-5895
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: e4f0f78020243786a2574875c191966c4abe4920
1458+
refs/heads/master-rebranch: f055791b9a5e2c4e9bed09baa4d752f2bfcda1fe
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,29 @@ CHANGELOG
2626
Swift Next
2727
----------
2828

29+
* [SE-0253][]:
30+
31+
Values of types that declare `func callAsFunction` methods can be called
32+
like functions. The call syntax is shorthand for applying
33+
`func callAsFunction` methods.
34+
35+
```swift
36+
struct Adder {
37+
var base: Int
38+
func callAsFunction(_ x: Int) -> Int {
39+
return x + base
40+
}
41+
}
42+
var adder = Adder(base: 3)
43+
adder(10) // returns 13, same as `adder.callAsFunction(10)`
44+
```
45+
46+
* `func callAsFunction` argument labels are required at call sites.
47+
* Multiple `func callAsFunction` methods on a single type are supported.
48+
* `mutating func callAsFunction` is supported.
49+
* `func callAsFunction` works with `throws` and `rethrows`.
50+
* `func callAsFunction` works with trailing closures.
51+
2952
* [SR-4206][]:
3053

3154
A method override is no longer allowed to have a generic signature with
@@ -7711,6 +7734,7 @@ Swift 1.0
77117734
[SE-0244]: <https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md>
77127735
[SE-0245]: <https://github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
77137736
[SE-0252]: <https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md>
7737+
[SE-0253]: <https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md>
77147738
[SE-0254]: <https://github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md>
77157739

77167740
[SR-106]: <https://bugs.swift.org/browse/SR-106>

branches/master-rebranch/benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ set(SWIFT_BENCH_MODULES
8787
single-source/Exclusivity
8888
single-source/ExistentialPerformance
8989
single-source/Fibonacci
90+
single-source/FindStringNaive
9091
single-source/FlattenList
9192
single-source/FloatingPointParsing
9293
single-source/FloatingPointPrinting
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
//===--- FindStringNaive.swift --------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
// Mini benchmark implementing a naive String search algorithm that
16+
// at the moment shows a lot of ARC traffic.
17+
let t: [BenchmarkCategory] = [.String, .refcount]
18+
let N = 100
19+
20+
var longStringFoFoFoFox: String?
21+
var longArrayFoFoFoFox: [UInt8]?
22+
23+
public let FindStringNaive = [
24+
BenchmarkInfo(
25+
name: "FindString.Loop1.Substring",
26+
runFunction: runBenchLoop1Substring,
27+
tags: t,
28+
setUpFunction: {
29+
longStringFoFoFoFox = String(repeating: "fo", count: 5_000) + "fox <-- needle"
30+
}),
31+
BenchmarkInfo(
32+
name: "FindString.Rec3.String",
33+
runFunction: runBenchRecursive3String,
34+
tags: t,
35+
setUpFunction: {
36+
longStringFoFoFoFox = String(repeating: "fo", count: 500) + "fox <-- needle"
37+
}),
38+
BenchmarkInfo(
39+
name: "FindString.Rec3.Substring",
40+
runFunction: runBenchRecursive3Substring,
41+
tags: t,
42+
setUpFunction: {
43+
longStringFoFoFoFox = String(repeating: "fo", count: 500) + "fox <-- needle"
44+
}),
45+
BenchmarkInfo(
46+
name: "FindString.Loop1.Array",
47+
runFunction: runBenchLoop1Array,
48+
tags: t,
49+
setUpFunction: {
50+
longArrayFoFoFoFox = []
51+
longArrayFoFoFoFox!.reserveCapacity(1_100_000)
52+
for _ in 0 ..< 500_000 {
53+
longArrayFoFoFoFox!.append(contentsOf: "fo".utf8)
54+
}
55+
longArrayFoFoFoFox!.append(contentsOf: "fox <-- needle".utf8)
56+
}),
57+
BenchmarkInfo(
58+
name: "FindString.Rec3.Array",
59+
runFunction: runBenchRecursive3ArrayOfUTF8,
60+
tags: t,
61+
setUpFunction: {
62+
longArrayFoFoFoFox = []
63+
longArrayFoFoFoFox!.reserveCapacity(11_000)
64+
for _ in 0 ..< 5_000 {
65+
longArrayFoFoFoFox!.append(contentsOf: "fo".utf8)
66+
}
67+
longArrayFoFoFoFox!.append(contentsOf: "fox <-- needle".utf8)
68+
}),
69+
]
70+
71+
func findOne<S: StringProtocol>(
72+
_ string: S,
73+
needle: Character
74+
) -> String.Index? {
75+
var index = string.startIndex
76+
while index < string.endIndex {
77+
let nextIndex = string.index(after: index)
78+
if string[index] == needle {
79+
return index
80+
}
81+
index = nextIndex
82+
}
83+
return nil
84+
}
85+
86+
func findThreeRecursive<S: StringProtocol>(
87+
_ string: S,
88+
needle1: Character,
89+
needle2: Character?,
90+
needle3: Character?
91+
) -> String.Index? {
92+
var index = string.startIndex
93+
while index < string.endIndex {
94+
let nextIndex = string.index(after: index)
95+
if string[index] == needle1 {
96+
// Check subsequent needles recursively (if applicable)
97+
guard let needle2 = needle2 else { return index }
98+
99+
if findThreeRecursive(
100+
string[nextIndex...].prefix(2), needle1: needle2, needle2: needle3, needle3: nil
101+
) == nextIndex {
102+
return index
103+
}
104+
}
105+
index = nextIndex
106+
}
107+
return nil
108+
}
109+
110+
func findOneOnUTF8Collection<Bytes: Collection>(
111+
_ string: Bytes,
112+
needle: UInt8
113+
) -> Bytes.Index? where Bytes.Element == UInt8 {
114+
var index = string.startIndex
115+
while index < string.endIndex {
116+
let nextIndex = string.index(after: index)
117+
if string[index] == needle {
118+
return index
119+
}
120+
index = nextIndex
121+
}
122+
return nil
123+
}
124+
125+
func findThreeOnUTF8Collection<Bytes: Collection>(
126+
_ string: Bytes,
127+
needle1: UInt8,
128+
needle2: UInt8?,
129+
needle3: UInt8?
130+
) -> Bytes.Index? where Bytes.Element == UInt8 {
131+
var index = string.startIndex
132+
while index < string.endIndex {
133+
let nextIndex = string.index(after: index)
134+
if string[index] == needle1 {
135+
// Check subsequent needles recursively (if applicable)
136+
guard let needle2 = needle2 else { return index }
137+
138+
if findThreeOnUTF8Collection(
139+
string[nextIndex...].prefix(2), needle1: needle2, needle2: needle3, needle3: nil
140+
) == nextIndex {
141+
return index
142+
}
143+
}
144+
index = nextIndex
145+
}
146+
return nil
147+
}
148+
149+
@inline(never)
150+
func runBenchLoop1Substring(iterations: Int) {
151+
for _ in 0 ..< iterations {
152+
precondition(findOne(longStringFoFoFoFox![...], needle: "x") != nil)
153+
}
154+
}
155+
156+
@inline(never)
157+
func runBenchLoop1Array(iterations: Int) {
158+
for _ in 0 ..< iterations {
159+
precondition(findOneOnUTF8Collection(longArrayFoFoFoFox!, needle: UInt8(ascii: "x")) != nil)
160+
}
161+
}
162+
163+
@inline(never)
164+
func runBenchRecursive3Substring(iterations: Int) {
165+
for _ in 0 ..< iterations {
166+
precondition(findThreeRecursive(longStringFoFoFoFox![...], needle1: "f", needle2: "o", needle3: "x") != nil)
167+
}
168+
}
169+
170+
@inline(never)
171+
func runBenchRecursive3String(iterations: Int) {
172+
for _ in 0 ..< iterations {
173+
precondition(findThreeRecursive(longStringFoFoFoFox!, needle1: "f", needle2: "o", needle3: "x") != nil)
174+
}
175+
}
176+
177+
@inline(never)
178+
func runBenchRecursive3ArrayOfUTF8(iterations: Int) {
179+
for _ in 0 ..< iterations {
180+
precondition(findThreeOnUTF8Collection(longArrayFoFoFoFox!,
181+
needle1: UInt8(ascii: "f"),
182+
needle2: UInt8(ascii: "o"),
183+
needle3: UInt8(ascii: "x")) != nil)
184+
}
185+
}

branches/master-rebranch/benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import ErrorHandling
7575
import Exclusivity
7676
import ExistentialPerformance
7777
import Fibonacci
78+
import FindStringNaive
7879
import FlattenList
7980
import FloatingPointParsing
8081
import FloatingPointPrinting
@@ -253,6 +254,7 @@ registerBenchmark(ErrorHandling)
253254
registerBenchmark(Exclusivity)
254255
registerBenchmark(ExistentialPerformance)
255256
registerBenchmark(Fibonacci)
257+
registerBenchmark(FindStringNaive)
256258
registerBenchmark(FlattenListLoop)
257259
registerBenchmark(FlattenListFlatMap)
258260
registerBenchmark(FloatingPointParsing)

branches/master-rebranch/cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ function(_add_swift_executable_single name)
23702370
# NOTE(compnerd) use the C linker language to invoke `clang` rather than
23712371
# `clang++` as we explicitly link against the C++ runtime. We were previously
23722372
# actually passing `-nostdlib++` to avoid the C++ runtime linkage.
2373-
if(SWIFTEXE_SINGLE_SDK STREQUAL ANDROID)
2373+
if(${SWIFTEXE_SINGLE_SDK} STREQUAL ANDROID)
23742374
set_property(TARGET "${name}" PROPERTY
23752375
LINKER_LANGUAGE "C")
23762376
else()

branches/master-rebranch/include/swift/AST/ASTContext.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ namespace swift {
6969
class LazyGenericContextData;
7070
class LazyIterableDeclContextData;
7171
class LazyMemberLoader;
72-
class LazyMemberParser;
7372
class LazyResolver;
7473
class PatternBindingDecl;
7574
class PatternBindingInitializer;
@@ -112,6 +111,10 @@ namespace swift {
112111

113112
enum class KnownProtocolKind : uint8_t;
114113

114+
namespace namelookup {
115+
class ImportCache;
116+
}
117+
115118
namespace syntax {
116119
class SyntaxArena;
117120
}
@@ -421,12 +424,6 @@ class ASTContext final {
421424
void setLazyResolver(LazyResolver *resolver);
422425

423426
public:
424-
/// Add a lazy parser for resolving members later.
425-
void addLazyParser(LazyMemberParser *parser);
426-
427-
/// Remove a lazy parser.
428-
void removeLazyParser(LazyMemberParser *parser);
429-
430427
/// getIdentifier - Return the uniqued and AST-Context-owned version of the
431428
/// specified string.
432429
Identifier getIdentifier(StringRef Str) const;
@@ -683,7 +680,9 @@ class ASTContext final {
683680
/// If there is no Clang module loader, returns a null pointer.
684681
/// The loader is owned by the AST context.
685682
ClangModuleLoader *getDWARFModuleLoader() const;
686-
683+
684+
namelookup::ImportCache &getImportCache() const;
685+
687686
/// Asks every module loader to verify the ASTs it has loaded.
688687
///
689688
/// Does nothing in non-asserts (NDEBUG) builds.
@@ -816,12 +815,6 @@ class ASTContext final {
816815
LazyContextData *getOrCreateLazyContextData(const DeclContext *decl,
817816
LazyMemberLoader *lazyLoader);
818817

819-
/// Use the lazy parsers associated with the context to populate the members
820-
/// of the given decl context.
821-
///
822-
/// \param IDC The context whose member decls should be lazily parsed.
823-
void parseMembers(IterableDeclContext *IDC);
824-
825818
/// Get the lazy function data for the given generic context.
826819
///
827820
/// \param lazyLoader If non-null, the lazy loader to use when creating the

branches/master-rebranch/include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ SWIFT_TYPEID(AncestryFlags)
3333
SWIFT_TYPEID_NAMED(GenericSignature *, GenericSignature)
3434
SWIFT_TYPEID_NAMED(GenericTypeParamType *, GenericTypeParamType)
3535
SWIFT_TYPEID(Requirement)
36+
SWIFT_TYPEID_NAMED(IterableDeclContext *, IterableDeclContext)

branches/master-rebranch/include/swift/AST/ASTTypeIDs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@
1717
#ifndef SWIFT_AST_ASTTYPEIDS_H
1818
#define SWIFT_AST_ASTTYPEIDS_H
1919

20+
#include "swift/Basic/LLVM.h"
2021
#include "swift/Basic/TypeID.h"
2122
namespace swift {
2223

2324
class CustomAttr;
25+
class Decl;
2426
class GenericSignature;
2527
class GenericTypeParamType;
28+
class IterableDeclContext;
2629
class NominalTypeDecl;
30+
class OperatorDecl;
2731
struct PropertyWrapperBackingPropertyInfo;
2832
struct PropertyWrapperTypeInfo;
2933
enum class CtorInitializerKind;
3034
struct PropertyWrapperMutability;
35+
class ProtocolDecl;
3136
class Requirement;
37+
enum class ResilienceExpansion : unsigned;
3238
class Type;
39+
class ValueDecl;
3340
class VarDecl;
3441
class TypeAliasDecl;
3542
class Type;

branches/master-rebranch/include/swift/AST/Attr.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ SIMPLE_DECL_ATTR(_weakLinked, WeakLinked,
362362
OnSubscript | OnConstructor | OnEnumElement | OnExtension | UserInaccessible,
363363
75)
364364
SIMPLE_DECL_ATTR(frozen, Frozen,
365-
OnEnum | OnStruct |
366-
UserInaccessible,
365+
OnEnum | OnStruct,
367366
76)
368367
DECL_ATTR_ALIAS(_frozen, Frozen)
369368
SIMPLE_DECL_ATTR(_forbidSerializingReference, ForbidSerializingReference,

branches/master-rebranch/include/swift/AST/Builtins.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,14 @@ BUILTIN_MISC_OPERATION(Strideof, "strideof", "n", Special)
418418
/// IsPOD has type T.Type -> Bool
419419
BUILTIN_MISC_OPERATION(IsPOD, "ispod", "n", Special)
420420

421+
/// IsConcrete has type (T.Type) -> Bool
422+
///
423+
/// If the meta type T is concrete, we can always transform this to `true` at
424+
/// any time in SIL. If it's generic, then we lower it to `false` right before
425+
/// IRGen in IRGenPrepare. This allows for the optimizer to specialize this at
426+
/// -O and eliminate conditional code.
427+
BUILTIN_MISC_OPERATION(IsConcrete, "isConcrete", "n", Special)
428+
421429
/// IsBitwiseTakable has type T.Type -> Bool
422430
BUILTIN_MISC_OPERATION(IsBitwiseTakable, "isbitwisetakable", "n", Special)
423431

0 commit comments

Comments
 (0)