Skip to content

Commit aeadc14

Browse files
authored
Merge branch 'master' into additive-arithmetic
2 parents c026851 + 7f02b26 commit aeadc14

File tree

17 files changed

+324
-138
lines changed

17 files changed

+324
-138
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ CHANGELOG
2424
Swift 5.0
2525
---------
2626

27+
* [SE-0216][]:
28+
29+
The `@dynamicCallable` attribute enables nominal types to be "callable" via a
30+
simple syntactic sugar. The primary use case is dynamic language
31+
interoperability.
32+
33+
Toy example:
34+
35+
```swift
36+
@dynamicCallable
37+
struct ToyCallable {
38+
func dynamicallyCall(withArguments: [Int]) {}
39+
func dynamicallyCall(withKeywordArguments: KeyValuePairs<String, Int>) {}
40+
}
41+
let x = ToyCallable()
42+
x(1, 2, 3) // desugars to `x.dynamicallyCall(withArguments: [1, 2, 3])`
43+
x(label: 1, 2) // desugars to `x.dynamicallyCall(withKeywordArguments: ["label": 1, "": 2])`
44+
```
45+
2746
* [SR-7251][]:
2847

2948
In Swift 5 mode, attempting to declare a static property with the same name as a

benchmark/single-source/DataBenchmarks.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,49 @@ public let DataBenchmarks = [
1717
BenchmarkInfo(name: "DataCreateEmpty", runFunction: run_createEmpty, tags: [.validation, .api, .Data]),
1818
BenchmarkInfo(name: "DataCreateSmall", runFunction: run_createSmall, tags: [.validation, .api, .Data]),
1919
BenchmarkInfo(name: "DataCreateMedium", runFunction: run_createMedium, tags: [.validation, .api, .Data]),
20-
BenchmarkInfo(name: "DataCreateLarge", runFunction: run_createLarge, tags: [.validation, .api, .Data]),
20+
BenchmarkInfo(name: "DataCreateLarge", runFunction: run_createLarge, tags: [.validation, .api, .Data, .skip]),
2121
BenchmarkInfo(name: "DataCreateEmptyArray", runFunction: run_createEmptyArray, tags: [.validation, .api, .Data]),
2222
BenchmarkInfo(name: "DataCreateSmallArray", runFunction: run_createSmallArray, tags: [.validation, .api, .Data]),
2323
BenchmarkInfo(name: "DataCreateMediumArray", runFunction: run_createMediumArray, tags: [.validation, .api, .Data]),
2424
BenchmarkInfo(name: "DataSubscriptSmall", runFunction: run_SubscriptSmall, tags: [.validation, .api, .Data]),
2525
BenchmarkInfo(name: "DataSubscriptMedium", runFunction: run_SubscriptMedium, tags: [.validation, .api, .Data]),
26-
BenchmarkInfo(name: "DataSubscriptLarge", runFunction: run_SubscriptLarge, tags: [.validation, .api, .Data]),
26+
BenchmarkInfo(name: "DataSubscriptLarge", runFunction: run_SubscriptLarge, tags: [.validation, .api, .Data, .skip]),
2727
BenchmarkInfo(name: "DataCountSmall", runFunction: run_CountSmall, tags: [.validation, .api, .Data]),
2828
BenchmarkInfo(name: "DataCountMedium", runFunction: run_CountMedium, tags: [.validation, .api, .Data]),
29-
BenchmarkInfo(name: "DataCountLarge", runFunction: run_CountLarge, tags: [.validation, .api, .Data]),
29+
BenchmarkInfo(name: "DataCountLarge", runFunction: run_CountLarge, tags: [.validation, .api, .Data, .skip]),
3030
BenchmarkInfo(name: "DataSetCountSmall", runFunction: run_SetCountSmall, tags: [.validation, .api, .Data]),
3131
BenchmarkInfo(name: "DataSetCountMedium", runFunction: run_SetCountMedium, tags: [.validation, .api, .Data]),
32-
BenchmarkInfo(name: "DataSetCountLarge", runFunction: run_SetCountLarge, tags: [.validation, .api, .Data]),
32+
BenchmarkInfo(name: "DataSetCountLarge", runFunction: run_SetCountLarge, tags: [.validation, .api, .Data, .skip]),
3333
BenchmarkInfo(name: "DataAccessBytesSmall", runFunction: run_AccessBytesSmall, tags: [.validation, .api, .Data]),
3434
BenchmarkInfo(name: "DataAccessBytesMedium", runFunction: run_AccessBytesMedium, tags: [.validation, .api, .Data]),
35-
BenchmarkInfo(name: "DataAccessBytesLarge", runFunction: run_AccessBytesLarge, tags: [.validation, .api, .Data]),
35+
BenchmarkInfo(name: "DataAccessBytesLarge", runFunction: run_AccessBytesLarge, tags: [.validation, .api, .Data, .skip]),
3636
BenchmarkInfo(name: "DataMutateBytesSmall", runFunction: run_MutateBytesSmall, tags: [.validation, .api, .Data]),
3737
BenchmarkInfo(name: "DataMutateBytesMedium", runFunction: run_MutateBytesMedium, tags: [.validation, .api, .Data]),
38-
BenchmarkInfo(name: "DataMutateBytesLarge", runFunction: run_MutateBytesLarge, tags: [.validation, .api, .Data]),
38+
BenchmarkInfo(name: "DataMutateBytesLarge", runFunction: run_MutateBytesLarge, tags: [.validation, .api, .Data, .skip]),
3939
BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: run_CopyBytesSmall, tags: [.validation, .api, .Data]),
4040
BenchmarkInfo(name: "DataCopyBytesMedium", runFunction: run_CopyBytesMedium, tags: [.validation, .api, .Data]),
41-
BenchmarkInfo(name: "DataCopyBytesLarge", runFunction: run_CopyBytesLarge, tags: [.validation, .api, .Data]),
41+
BenchmarkInfo(name: "DataCopyBytesLarge", runFunction: run_CopyBytesLarge, tags: [.validation, .api, .Data, .skip]),
4242
BenchmarkInfo(name: "DataAppendBytesSmall", runFunction: run_AppendBytesSmall, tags: [.validation, .api, .Data]),
4343
BenchmarkInfo(name: "DataAppendBytesMedium", runFunction: run_AppendBytesMedium, tags: [.validation, .api, .Data]),
44-
BenchmarkInfo(name: "DataAppendBytesLarge", runFunction: run_AppendBytesLarge, tags: [.validation, .api, .Data]),
44+
BenchmarkInfo(name: "DataAppendBytesLarge", runFunction: run_AppendBytesLarge, tags: [.validation, .api, .Data, .skip]),
4545
BenchmarkInfo(name: "DataAppendArray", runFunction: run_AppendArray, tags: [.validation, .api, .Data]),
4646
BenchmarkInfo(name: "DataReset", runFunction: run_Reset, tags: [.validation, .api, .Data]),
4747
BenchmarkInfo(name: "DataReplaceSmall", runFunction: run_ReplaceSmall, tags: [.validation, .api, .Data]),
4848
BenchmarkInfo(name: "DataReplaceMedium", runFunction: run_ReplaceMedium, tags: [.validation, .api, .Data]),
4949
BenchmarkInfo(name: "DataReplaceLarge", runFunction: run_ReplaceLarge, tags: [.validation, .api, .Data]),
5050
BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: run_ReplaceSmallBuffer, tags: [.validation, .api, .Data]),
5151
BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: run_ReplaceMediumBuffer, tags: [.validation, .api, .Data]),
52-
BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: run_ReplaceLargeBuffer, tags: [.validation, .api, .Data]),
52+
BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: run_ReplaceLargeBuffer, tags: [.validation, .api, .Data, .skip]),
5353
BenchmarkInfo(name: "DataAppendSequence", runFunction: run_AppendSequence, tags: [.validation, .api, .Data]),
5454
BenchmarkInfo(name: "DataAppendDataSmallToSmall", runFunction: run_AppendDataSmallToSmall, tags: [.validation, .api, .Data]),
5555
BenchmarkInfo(name: "DataAppendDataSmallToMedium", runFunction: run_AppendDataSmallToMedium, tags: [.validation, .api, .Data]),
5656
BenchmarkInfo(name: "DataAppendDataSmallToLarge", runFunction: run_AppendDataSmallToLarge, tags: [.validation, .api, .Data]),
5757
BenchmarkInfo(name: "DataAppendDataMediumToSmall", runFunction: run_AppendDataMediumToSmall, tags: [.validation, .api, .Data]),
5858
BenchmarkInfo(name: "DataAppendDataMediumToMedium", runFunction: run_AppendDataMediumToMedium, tags: [.validation, .api, .Data]),
59-
BenchmarkInfo(name: "DataAppendDataMediumToLarge", runFunction: run_AppendDataMediumToLarge, tags: [.validation, .api, .Data]),
59+
BenchmarkInfo(name: "DataAppendDataMediumToLarge", runFunction: run_AppendDataMediumToLarge, tags: [.validation, .api, .Data, .skip]),
6060
BenchmarkInfo(name: "DataAppendDataLargeToSmall", runFunction: run_AppendDataLargeToSmall, tags: [.validation, .api, .Data]),
6161
BenchmarkInfo(name: "DataAppendDataLargeToMedium", runFunction: run_AppendDataLargeToMedium, tags: [.validation, .api, .Data]),
62-
BenchmarkInfo(name: "DataAppendDataLargeToLarge", runFunction: run_AppendDataLargeToLarge, tags: [.validation, .api, .Data]),
62+
BenchmarkInfo(name: "DataAppendDataLargeToLarge", runFunction: run_AppendDataLargeToLarge, tags: [.validation, .api, .Data, .skip]),
6363
BenchmarkInfo(name: "DataToStringEmpty", runFunction: run_DataToStringEmpty, tags: [.validation, .api, .Data]),
6464
BenchmarkInfo(name: "DataToStringSmall", runFunction: run_DataToStringSmall, tags: [.validation, .api, .Data]),
6565
BenchmarkInfo(name: "DataToStringMedium", runFunction: run_DataToStringMedium, tags: [.validation, .api, .Data]),

lib/SILOptimizer/Transforms/AccessEnforcementOpts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ void AccessConflictAndMergeAnalysis::visitBeginAccess(
637637

638638
auto &outerAccessInfo = result.getAccessInfo(outerBeginAccess);
639639
// If there is no potential conflict, leave the outer access mapped.
640-
if (!outerAccessInfo.isDistinctFrom(beginAccessInfo))
640+
if (outerAccessInfo.isDistinctFrom(beginAccessInfo))
641641
continue;
642642

643643
LLVM_DEBUG(beginAccessInfo.dump();

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,19 +1271,14 @@ bool WitnessChecker::checkWitnessAccess(ValueDecl *requirement,
12711271
// That is, if '@testable' allows us to see the witness here, it should
12721272
// allow us to see it anywhere, because any other client could also add
12731273
// their own `@testable import`.
1274+
// Same with @_private(sourceFile:) import.
12741275
if (auto parentFile = dyn_cast<SourceFile>(DC->getModuleScopeContext())) {
12751276
const ModuleDecl *witnessModule = witness->getModuleContext();
12761277
if (parentFile->getParentModule() != witnessModule &&
1277-
parentFile->hasTestableOrPrivateImport(AccessLevel::Internal,
1278-
witnessModule) &&
1278+
parentFile->hasTestableOrPrivateImport(witness->getFormalAccess(),
1279+
witness) &&
12791280
witness->isAccessibleFrom(parentFile)) {
12801281
actualScopeToCheck = parentFile;
1281-
// Same with @_private(sourceFile:) import.
1282-
} else if (parentFile->getParentModule() != witnessModule &&
1283-
parentFile->hasTestableOrPrivateImport(
1284-
witness->getFormalAccess(), witness) &&
1285-
witness->isAccessibleFrom(parentFile)) {
1286-
actualScopeToCheck = parentFile;
12871282
}
12881283
}
12891284

stdlib/public/core/FixedArray.swift.gyb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121

2222
% for N in sizes:
2323

24-
@usableFromInline // FIXME(sil-serialize-all)
25-
@_fixed_layout // FIXME(sil-serialize-all)
2624
internal struct _FixedArray${N}<T> {
2725
// ABI TODO: The has assumptions about tuple layout in the ABI, namely that
2826
// they are laid out contiguously and individually addressable (i.e. strided).
2927
//
30-
@usableFromInline // FIXME(sil-serialize-all)
3128
internal var storage: (
3229
// A ${N}-wide tuple of type T
3330
% for i in range(0, N-1):
@@ -36,44 +33,35 @@ internal struct _FixedArray${N}<T> {
3633
T
3734
)
3835

39-
@usableFromInline // FIXME(sil-serialize-all)
4036
var _count: Int8
4137
}
4238

43-
4439
extension _FixedArray${N} {
45-
@inlinable // FIXME(sil-serialize-all)
4640
internal static var capacity: Int {
4741
@inline(__always) get { return ${N} }
4842
}
4943

50-
@inlinable // FIXME(sil-serialize-all)
5144
internal var capacity: Int {
5245
@inline(__always) get { return ${N} }
5346
}
5447

55-
@inlinable // FIXME(sil-serialize-all)
5648
internal var count: Int {
5749
@inline(__always) get { return Int(truncatingIfNeeded: _count) }
5850
@inline(__always) set { _count = Int8(newValue) }
5951
}
6052
}
6153

6254
extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
63-
@usableFromInline
6455
internal typealias Index = Int
6556

66-
@inlinable // FIXME(sil-serialize-all)
6757
internal var startIndex : Index {
6858
return 0
6959
}
7060

71-
@inlinable // FIXME(sil-serialize-all)
7261
internal var endIndex : Index {
7362
return count
7463
}
7564

76-
@inlinable // FIXME(sil-serialize-all)
7765
internal subscript(i: Index) -> T {
7866
@inline(__always)
7967
get {
@@ -99,21 +87,18 @@ extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
9987
}
10088
}
10189

102-
@inlinable // FIXME(sil-serialize-all)
10390
@inline(__always)
10491
internal func index(after i: Index) -> Index {
10592
return i+1
10693
}
10794

108-
@inlinable // FIXME(sil-serialize-all)
10995
@inline(__always)
11096
internal func index(before i: Index) -> Index {
11197
return i-1
11298
}
11399
}
114100

115101
extension _FixedArray${N} {
116-
@inlinable // FIXME(sil-serialize-all)
117102
internal mutating func append(_ newElement: T) {
118103
_sanityCheck(count < capacity)
119104
_count += 1
@@ -122,7 +107,6 @@ extension _FixedArray${N} {
122107
}
123108

124109
extension _FixedArray${N} where T : ExpressibleByIntegerLiteral {
125-
@inlinable // FIXME(sil-serialize-all)
126110
@inline(__always)
127111
internal init(count: Int) {
128112
_sanityCheck(count >= 0 && count <= _FixedArray${N}.capacity)
@@ -135,21 +119,18 @@ extension _FixedArray${N} where T : ExpressibleByIntegerLiteral {
135119
self._count = Int8(truncatingIfNeeded: count)
136120
}
137121

138-
@inlinable // FIXME(sil-serialize-all)
139122
@inline(__always)
140123
internal init() {
141124
self.init(count: 0)
142125
}
143126

144-
@inlinable // FIXME(sil-serialize-all)
145127
@inline(__always)
146128
internal init(allZeros: ()) {
147129
self.init(count: ${N})
148130
}
149131
}
150132

151133
extension _FixedArray${N} {
152-
@inlinable // FIXME(sil-serialize-all)
153134
internal mutating func withUnsafeMutableBufferPointer<R>(
154135
_ body: (UnsafeMutableBufferPointer<Element>) throws -> R
155136
) rethrows -> R {
@@ -165,7 +146,6 @@ extension _FixedArray${N} {
165146
}
166147
}
167148

168-
@inlinable // FIXME(sil-serialize-all)
169149
internal mutating func withUnsafeBufferPointer<R>(
170150
_ body: (UnsafeBufferPointer<Element>) throws -> R
171151
) rethrows -> R {

stdlib/public/core/StringSwitch.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,9 @@ struct _OpaqueStringSwitchCache {
3939
var b: Builtin.Word
4040
}
4141

42-
@usableFromInline // FIXME(sil-serialize-all)
4342
internal typealias _StringSwitchCache = Dictionary<String, Int>
4443

45-
@_fixed_layout // FIXME(sil-serialize-all)
46-
@usableFromInline // FIXME(sil-serialize-all)
4744
internal struct _StringSwitchContext {
48-
@inlinable // FIXME(sil-serialize-all)
4945
internal init(
5046
cases: [StaticString],
5147
cachePtr: UnsafeMutablePointer<_StringSwitchCache>
@@ -54,9 +50,7 @@ internal struct _StringSwitchContext {
5450
self.cachePtr = cachePtr
5551
}
5652

57-
@usableFromInline // FIXME(sil-serialize-all)
5853
internal let cases: [StaticString]
59-
@usableFromInline // FIXME(sil-serialize-all)
6054
internal let cachePtr: UnsafeMutablePointer<_StringSwitchCache>
6155
}
6256

@@ -94,7 +88,6 @@ func _findStringSwitchCaseWithCache(
9488
}
9589

9690
/// Builds the string switch case.
97-
@inlinable // FIXME(sil-serialize-all)
9891
internal func _createStringTableCache(_ cacheRawPtr: Builtin.RawPointer) {
9992
let context = UnsafePointer<_StringSwitchContext>(cacheRawPtr).pointee
10093
var cache = _StringSwitchCache()

stdlib/public/core/Unicode.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,6 @@ extension Unicode.UTF32 : UnicodeCodec {
477477
@inlinable // FIXME(sil-serialize-all)
478478
public mutating func decode<I : IteratorProtocol>(
479479
_ input: inout I
480-
) -> UnicodeDecodingResult where I.Element == CodeUnit {
481-
return UTF32._decode(&input)
482-
}
483-
484-
@inlinable // FIXME(sil-serialize-all)
485-
internal static func _decode<I : IteratorProtocol>(
486-
_ input: inout I
487480
) -> UnicodeDecodingResult where I.Element == CodeUnit {
488481
var parser = ForwardParser()
489482

stdlib/public/core/UnicodeParser.swift

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -57,79 +57,6 @@ public protocol _UnicodeParser {
5757
where I.Element == Encoding.CodeUnit
5858
}
5959

60-
extension _UnicodeParser {
61-
@inlinable // FIXME(sil-serialize-all)
62-
@inline(__always)
63-
@discardableResult
64-
internal static func _parse<I: IteratorProtocol>(
65-
_ input: inout I,
66-
repairingIllFormedSequences makeRepairs: Bool = true,
67-
into output: (Encoding.EncodedScalar)->Void
68-
) -> Int
69-
where I.Element == Encoding.CodeUnit
70-
{
71-
var errorCount = 0
72-
var d = Self()
73-
while true {
74-
switch d.parseScalar(from: &input) {
75-
case let .valid(scalarContent):
76-
output(scalarContent)
77-
case .error:
78-
if _slowPath(!makeRepairs) { return 1 }
79-
errorCount += 1
80-
output(Encoding.encodedReplacementCharacter)
81-
case .emptyInput:
82-
return errorCount
83-
}
84-
}
85-
}
86-
87-
@inlinable // FIXME(sil-serialize-all)
88-
@inline(__always)
89-
@discardableResult
90-
public static func _decode<I: IteratorProtocol>(
91-
_ input: inout I,
92-
repairingIllFormedSequences makeRepairs: Bool,
93-
into output: (Unicode.Scalar)->Void
94-
) -> Int
95-
where I.Element == Encoding.CodeUnit
96-
{
97-
return _parse(&input, repairingIllFormedSequences: makeRepairs) {
98-
output(Encoding.decode($0))
99-
}
100-
}
101-
}
102-
10360
extension Unicode {
10461
public typealias Parser = _UnicodeParser
10562
}
106-
107-
extension Unicode {
108-
@_fixed_layout
109-
public // @testable
110-
struct _ParsingIterator<
111-
CodeUnitIterator : IteratorProtocol,
112-
Parser: Unicode.Parser
113-
> where Parser.Encoding.CodeUnit == CodeUnitIterator.Element {
114-
@inline(__always)
115-
@inlinable
116-
public init(codeUnits: CodeUnitIterator, parser: Parser) {
117-
self.codeUnits = codeUnits
118-
self.parser = parser
119-
}
120-
public var codeUnits: CodeUnitIterator
121-
public var parser: Parser
122-
}
123-
}
124-
125-
extension Unicode._ParsingIterator : IteratorProtocol, Sequence {
126-
@inline(__always)
127-
@inlinable
128-
public mutating func next() -> Parser.Encoding.EncodedScalar? {
129-
switch parser.parseScalar(from: &codeUnits) {
130-
case let .valid(scalarContent): return scalarContent
131-
case .error: return Parser.Encoding.encodedReplacementCharacter
132-
case .emptyInput: return nil
133-
}
134-
}
135-
}

0 commit comments

Comments
 (0)