Skip to content

Commit afa1471

Browse files
authored
Merge branch 'master' into fix/SR-11074
2 parents 1a1bff4 + 9ff887b commit afa1471

Some content is hidden

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

50 files changed

+1350
-731
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ set(SWIFT_BENCH_MODULES
7979
single-source/DictionarySubscriptDefault
8080
single-source/DictionarySwap
8181
single-source/Diffing
82+
single-source/DiffingMyers
8283
single-source/DropFirst
8384
single-source/DropLast
8485
single-source/DropWhile
@@ -105,7 +106,6 @@ set(SWIFT_BENCH_MODULES
105106
single-source/Memset
106107
single-source/MonteCarloE
107108
single-source/MonteCarloPi
108-
single-source/Myers
109109
single-source/NSDictionaryCastToSwift
110110
single-source/NSError
111111
single-source/NSStringConversion

benchmark/single-source/Diffing.swift

Lines changed: 25 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,111 +15,55 @@ import TestsUtils
1515
let t: [BenchmarkCategory] = [.api]
1616
public let Diffing = [
1717
BenchmarkInfo(
18-
name: "DiffSame",
19-
runFunction: run_DiffSame,
18+
name: "Diffing.Same",
19+
runFunction: { diff($0, from: longPangram, to: longPangram) },
2020
tags: t,
21-
legacyFactor: 10),
21+
setUpFunction: { blackHole(longPangram) }),
2222
BenchmarkInfo(
23-
name: "DiffPangramToAlphabet",
24-
runFunction: run_DiffPangramToAlphabet,
23+
name: "Diffing.PangramToAlphabet",
24+
runFunction: { diff($0, from: longPangram, to: alphabets) },
2525
tags: t,
26-
legacyFactor: 10),
26+
setUpFunction: { blackHole((longPangram, alphabets)) }),
2727
BenchmarkInfo(
28-
name: "DiffPangrams",
29-
runFunction: run_DiffPangrams,
28+
name: "Diffing.Pangrams",
29+
runFunction: { diff($0, from:typingPangram, to: longPangram) },
3030
tags: t,
31-
legacyFactor: 10),
31+
setUpFunction: { blackHole((longPangram, typingPangram)) }),
3232
BenchmarkInfo(
33-
name: "DiffReversedAlphabets",
34-
runFunction: run_DiffReversedAlphabets,
33+
name: "Diffing.ReversedAlphabets",
34+
runFunction: { diff($0, from:alphabets, to: alphabetsReversed) },
3535
tags: t,
36-
legacyFactor: 10),
36+
setUpFunction: { blackHole((alphabets, alphabetsReversed)) }),
3737
BenchmarkInfo(
38-
name: "DiffReversedLorem",
39-
runFunction: run_DiffReversedLorem,
38+
name: "Diffing.ReversedLorem",
39+
runFunction: { diff($0, from: loremIpsum, to: loremReversed) },
4040
tags: t,
41-
legacyFactor: 10),
41+
setUpFunction: { blackHole((loremIpsum, loremReversed)) }),
4242
BenchmarkInfo(
43-
name: "DiffDisparate",
44-
runFunction: run_DiffDisparate,
43+
name: "Diffing.Disparate",
44+
runFunction: { diff($0, from: numbersAndSymbols, to: alphabets) },
4545
tags: t,
46-
legacyFactor: 10),
46+
setUpFunction: { blackHole((numbersAndSymbols, alphabets)) }),
4747
BenchmarkInfo(
48-
name: "DiffSimilar",
49-
runFunction: run_DiffSimilar,
48+
name: "Diffing.Similar",
49+
runFunction: { diff($0, from: unabridgedLorem, to: loremIpsum) },
5050
tags: t,
51-
legacyFactor: 10),
51+
setUpFunction: { blackHole((unabridgedLorem, loremIpsum)) }),
5252
]
5353

5454
let numbersAndSymbols = Array("0123456789`~!@#$%^&*()+=_-\"'?/<,>.\\{}'")
5555
let alphabets = Array("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
56-
let alphabetsReversed = Array("ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba")
56+
let alphabetsReversed = Array(alphabets.reversed())
5757
let longPangram = Array("This pangram contains four As, one B, two Cs, one D, thirty Es, six Fs, five Gs, seven Hs, eleven Is, one J, one K, two Ls, two Ms, eighteen Ns, fifteen Os, two Ps, one Q, five Rs, twenty-seven Ss, eighteen Ts, two Us, seven Vs, eight Ws, two Xs, three Ys, & one Z")
5858
let typingPangram = Array("The quick brown fox jumps over the lazy dog")
5959
let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
6060
let unabridgedLorem = Array("Lorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliqua.")
61-
let loremReverse = Array(".auqila angam erolod te erobal tu tnudidicni ropmet domsuie od des ,tile gnicsipida rutetcesnoc ,tema tis rolod muspi meroL")
61+
let loremReversed = Array(loremIpsum.reversed())
6262

63-
64-
@inline(never)
65-
public func run_DiffSame(_ N: Int) {
66-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
67-
for _ in 1...N {
68-
let _ = longPangram.difference(from: longPangram)
69-
}
70-
}
71-
}
72-
73-
@inline(never)
74-
public func run_DiffPangramToAlphabet(_ N: Int) {
75-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
76-
for _ in 1...N {
77-
let _ = longPangram.difference(from: alphabets)
78-
}
79-
}
80-
}
81-
82-
@inline(never)
83-
public func run_DiffPangrams(_ N: Int) {
84-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
85-
for _ in 1...N {
86-
let _ = longPangram.difference(from: typingPangram)
87-
}
88-
}
89-
}
90-
91-
@inline(never)
92-
public func run_DiffReversedAlphabets(_ N: Int) {
93-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
94-
for _ in 1...N {
95-
let _ = alphabets.difference(from: alphabetsReversed)
96-
}
97-
}
98-
}
99-
100-
@inline(never)
101-
public func run_DiffReversedLorem(_ N: Int) {
102-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
103-
for _ in 1...N {
104-
let _ = loremIpsum.difference(from: loremReverse)
105-
}
106-
}
107-
}
108-
109-
@inline(never)
110-
public func run_DiffDisparate(_ N: Int) {
111-
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
112-
for _ in 1...N {
113-
let _ = alphabets.difference(from: numbersAndSymbols)
114-
}
115-
}
116-
}
117-
118-
@inline(never)
119-
public func run_DiffSimilar(_ N: Int) {
63+
@inline(never) func diff(_ N: Int, from older: [Character], to newer: [Character]) {
12064
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
12165
for _ in 1...N {
122-
let _ = loremIpsum.difference(from: unabridgedLorem)
66+
blackHole(newer.difference(from: older))
12367
}
12468
}
12569
}

benchmark/single-source/Myers.swift renamed to benchmark/single-source/DiffingMyers.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Myers.swift -------------------------------------------===//
1+
//===--- DiffingMyers.swift -----------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -12,18 +12,25 @@
1212

1313
import TestsUtils
1414

15-
public let Myers = [
16-
BenchmarkInfo(name: "Myers", runFunction: run_Myers, tags: [.algorithm]),
17-
]
15+
// The DiffingMyers test benchmarks Swift's performance running the algorithm
16+
// described in Myers (1986). The Diffing benchmark tracks the performance
17+
// of `Collection.difference(from:to:)`.
1818

19-
let loremShort = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
20-
let loremLong = Array("Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum[d] exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?")
19+
public let DiffingMyers = BenchmarkInfo(
20+
name: "Diffing.Myers.Similar",
21+
runFunction: run_Myers,
22+
tags: [.algorithm],
23+
setUpFunction: { blackHole((loremIpsum, unabridgedLorem)) })
24+
25+
26+
let loremIpsum = Array("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
27+
let unabridgedLorem = Array("Lorem ipsum, quia dolor sit amet consectetur adipisci[ng] velit, sed quia non-numquam [do] eius modi tempora inci[di]dunt, ut labore et dolore magnam aliqua.")
2128

2229
@inline(never)
2330
public func run_Myers(N: Int) {
2431
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
2532
for _ in 1...N {
26-
let _ = myers(from: loremShort, to: loremLong, using: ==)
33+
blackHole(myers(from: unabridgedLorem, to: loremIpsum, using: ==))
2734
}
2835
}
2936
}
@@ -193,4 +200,4 @@ fileprivate func myers<C,D>(
193200
return CollectionDifference(_formChanges(from: a, to: b, using:_descent(from: a, to: b)))!
194201
}
195202
}
196-
}
203+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import DictionaryRemove
6767
import DictionarySubscriptDefault
6868
import DictionarySwap
6969
import Diffing
70+
import DiffingMyers
7071
import DropFirst
7172
import DropLast
7273
import DropWhile
@@ -93,7 +94,6 @@ import MapReduce
9394
import Memset
9495
import MonteCarloE
9596
import MonteCarloPi
96-
import Myers
9797
import NibbleSort
9898
import NIOChannelPipeline
9999
import NSDictionaryCastToSwift
@@ -243,6 +243,7 @@ registerBenchmark(DictionaryRemove)
243243
registerBenchmark(DictionarySubscriptDefault)
244244
registerBenchmark(DictionarySwap)
245245
registerBenchmark(Diffing)
246+
registerBenchmark(DiffingMyers)
246247
registerBenchmark(DropFirst)
247248
registerBenchmark(DropLast)
248249
registerBenchmark(DropWhile)
@@ -270,7 +271,6 @@ registerBenchmark(MapReduce)
270271
registerBenchmark(Memset)
271272
registerBenchmark(MonteCarloE)
272273
registerBenchmark(MonteCarloPi)
273-
registerBenchmark(Myers)
274274
registerBenchmark(NSDictionaryCastToSwift)
275275
registerBenchmark(NSErrorTest)
276276
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,9 +3395,12 @@ ERROR(closure_tuple_parameter_destructuring_implicit,none,
33953395
ERROR(nested_tuple_parameter_destructuring,none,
33963396
"nested tuple parameter %0 of function %1 "
33973397
"does not support destructuring", (Type, Type))
3398-
ERROR(single_tuple_parameter_mismatch,none,
3399-
"%0 %select{|%1 }3expects a single parameter of type %2",
3400-
(DescriptiveDeclKind, Identifier, Type, bool))
3398+
ERROR(single_tuple_parameter_mismatch_special,none,
3399+
"%0 expects a single parameter of type %1%2",
3400+
(DescriptiveDeclKind, Type, StringRef))
3401+
ERROR(single_tuple_parameter_mismatch_normal,none,
3402+
"%0 %1 expects a single parameter of type %2%3",
3403+
(DescriptiveDeclKind, DeclBaseName, Type, StringRef))
34013404
ERROR(unknown_single_tuple_parameter_mismatch,none,
34023405
"single parameter of type %0 is expected in call", (Type))
34033406

include/swift/Basic/Statistics.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
227227
#include "swift/AST/AccessTypeIDZone.def"
228228
#include "swift/AST/NameLookupTypeIDZone.def"
229229
#include "swift/AST/TypeCheckerTypeIDZone.def"
230+
#include "swift/IDE/IDERequestIDZone.def"
230231
#undef SWIFT_TYPEID
231232

232233
/// The next 10 statistics count 5 kinds of SIL entities present
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===-------- IDERequestIDZone.def ------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 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+
// This definition file describes the types in the IDE requests
14+
// TypeID zone, for use with the TypeID template.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
SWIFT_TYPEID(CursorInfoRequest)

include/swift/IDE/IDERequests.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//===----- IDERequests.h - IDE functionality Requests -----------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 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+
// This file defines IDE request using the evaluator model.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
#ifndef SWIFT_IDE_REQUESTS_H
17+
#define SWIFT_IDE_REQUESTS_H
18+
19+
#include "swift/AST/ASTTypeIDs.h"
20+
#include "swift/AST/Evaluator.h"
21+
#include "swift/AST/SimpleRequest.h"
22+
#include "swift/IDE/Utils.h"
23+
#include "swift/IDE/IDETypeIDs.h"
24+
25+
namespace swift {
26+
27+
// Input for CursorInfoRequest.
28+
// Putting the source file and location together allows us to print the request
29+
// input well e.g. file.swift:3:4
30+
struct CursorInfoOwner {
31+
SourceFile *File;
32+
SourceLoc Loc;
33+
34+
CursorInfoOwner(SourceFile *File, SourceLoc Loc): File(File), Loc(Loc) { }
35+
36+
friend llvm::hash_code hash_value(const CursorInfoOwner &CI) {
37+
return hash_combine(hash_value(CI.File),
38+
hash_value(CI.Loc.getOpaquePointerValue()));
39+
}
40+
41+
friend bool operator==(const CursorInfoOwner &lhs, const CursorInfoOwner &rhs) {
42+
return lhs.File == rhs.File &&
43+
lhs.Loc.getOpaquePointerValue() == rhs.Loc.getOpaquePointerValue();
44+
}
45+
46+
friend bool operator!=(const CursorInfoOwner &lhs, const CursorInfoOwner &rhs) {
47+
return !(lhs == rhs);
48+
}
49+
bool isValid() const {
50+
return File && File->getBufferID() && Loc.isValid();
51+
}
52+
};
53+
54+
void simple_display(llvm::raw_ostream &out, const CursorInfoOwner &owner);
55+
56+
/// Resolve cursor info at a given location.
57+
class CursorInfoRequest:
58+
public SimpleRequest<CursorInfoRequest,
59+
ide::ResolvedCursorInfo(CursorInfoOwner),
60+
CacheKind::Cached>
61+
{
62+
public:
63+
using SimpleRequest::SimpleRequest;
64+
65+
private:
66+
friend SimpleRequest;
67+
68+
// Evaluation.
69+
llvm::Expected<ide::ResolvedCursorInfo> evaluate(Evaluator &evaluator,
70+
CursorInfoOwner CI) const;
71+
72+
public:
73+
// Caching
74+
bool isCached() const { return true; }
75+
// Source location
76+
SourceLoc getNearestLoc() const;
77+
};
78+
79+
/// The zone number for the IDE.
80+
#define SWIFT_IDE_REQUESTS_TYPEID_ZONE 137
81+
#define SWIFT_TYPEID_ZONE SWIFT_IDE_REQUESTS_TYPEID_ZONE
82+
#define SWIFT_TYPEID_HEADER "swift/IDE/IDERequestIDZone.def"
83+
#include "swift/Basic/DefineTypeIDZone.h"
84+
#undef SWIFT_TYPEID_ZONE
85+
#undef SWIFT_TYPEID_HEADER
86+
87+
// Set up reporting of evaluated requests.
88+
#define SWIFT_TYPEID(RequestType) \
89+
template<> \
90+
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
91+
const RequestType &request) { \
92+
++stats.getFrontendCounters().RequestType; \
93+
}
94+
#include "swift/IDE/IDERequestIDZone.def"
95+
#undef SWIFT_TYPEID
96+
97+
} // end namespace swift
98+
99+
#endif // SWIFT_IDE_REQUESTS_H

include/swift/IDE/IDETypeIDZone.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===---------- IDETypeIDZone.def ------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 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+
// This definition file describes the types in the IDE type
14+
// TypeID zone, for use with the TypeID template.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
SWIFT_TYPEID_NAMED(ide::ResolvedCursorInfo, ResolvedCursorInfo)

0 commit comments

Comments
 (0)