Skip to content

Commit fdec03e

Browse files
authored
---
yaml --- r: 293723 b: refs/heads/tensorflow c: f3bda1c h: refs/heads/master i: 293721: c107881 293719: 2a8a618
1 parent a764c73 commit fdec03e

File tree

131 files changed

+1580
-589
lines changed

Some content is hidden

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

131 files changed

+1580
-589
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: ade2df1253dcc43d0af497c8ad93ba23f64a4942
819+
refs/heads/tensorflow: f3bda1c59ca6d30c4707ffa67c0b955d53632d15
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ set(SWIFT_BENCH_MODULES
4343
single-source/BinaryFloatingPointProperties
4444
single-source/BitCount
4545
single-source/Breadcrumbs
46+
single-source/BucketSort
4647
single-source/ByteSwap
4748
single-source/COWTree
4849
single-source/COWArrayGuaranteedParameterOverhead
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//===--- BucketSort.swift ----------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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+
// Adapted from the original implementation:
13+
// https://github.com/raywenderlich/swift-algorithm-club/tree/master/Bucket%20Sort
14+
// Issue: https://github.com/raywenderlich/swift-algorithm-club/issues/863
15+
16+
// This benchmark implements the classical BucketSort algorithm described at
17+
// https://en.wikipedia.org/wiki/Bucket_sort. The implementation allows for an
18+
// array of generic type of "SortableItem" to be sorted. Unfortunately, if
19+
// ``sortingAlgo'' type is not known for the callsite in line 84, then the
20+
// ``sort'' method can not be specialized to integer array sorting, which will
21+
// lead to a huge performance loss. Since SortingAlgorithm and InsertionSort are
22+
// declared to be ``public'' and that lines 83-85 can not be inlined in
23+
// BucketSortImpl (due to inlining heuristic limitations), today swift
24+
// compiler (without ExistentialSpecializer) can not achieve this feat. With
25+
// ExistentialSpecializer which enables generic specialization recursively in a
26+
// call chain, we are able to specialize line 84 for InsertionSort on integers.
27+
28+
import TestsUtils
29+
import Foundation
30+
31+
public let BucketSort = BenchmarkInfo(
32+
name: "BucketSort",
33+
runFunction: run_BucketSort,
34+
tags: [.validation, .algorithm],
35+
setUpFunction: { buildWorkload() },
36+
legacyFactor: 10)
37+
38+
public protocol IntegerConvertible {
39+
func convertToInt() -> Int
40+
}
41+
extension Int: IntegerConvertible, SortableItem {
42+
public func convertToInt() -> Int {
43+
return self
44+
}
45+
}
46+
public protocol SortableItem: IntegerConvertible, Comparable { }
47+
public protocol SortingAlgorithm {
48+
func sort<T: SortableItem>(_ items: [T]) -> [T]
49+
}
50+
public struct InsertionSort: SortingAlgorithm {
51+
public func sort<T: SortableItem>(_ items: [T]) -> [T] {
52+
var sortedItems = items
53+
for i in 0 ..< sortedItems.count {
54+
var j = i
55+
while j > 0 && sortedItems[j-1] > sortedItems[j] {
56+
let temp = sortedItems[j-1]
57+
sortedItems[j-1] = sortedItems[j]
58+
sortedItems[j] = temp
59+
j -= 1
60+
}
61+
}
62+
return sortedItems
63+
}
64+
}
65+
func distribute<T>(_ item: T, bucketArray: inout [Bucket<T>]) {
66+
let val = item.convertToInt()
67+
let capacity = bucketArray.first!.capacity
68+
let index = val / capacity
69+
bucketArray[index].add(item)
70+
}
71+
struct Bucket<T: SortableItem> {
72+
var items: [T]
73+
let capacity: Int
74+
init(capacity: Int) {
75+
self.capacity = capacity
76+
items = [T]()
77+
}
78+
mutating func add(_ item: T) {
79+
if items.count < capacity {
80+
items.append(item)
81+
}
82+
}
83+
func sort(_ sortingAlgo: SortingAlgorithm) -> [T] {
84+
return sortingAlgo.sort(items)
85+
}
86+
}
87+
func BucketSortImpl<T>(_ items: [T], sortingAlgorithm: SortingAlgorithm, bucketArray: [Bucket<T>]) -> [T] {
88+
var copyBucketArray = bucketArray
89+
for item in items {
90+
distribute(item, bucketArray: &copyBucketArray)
91+
}
92+
var sortedArray = [T]()
93+
for bucket in copyBucketArray {
94+
sortedArray += bucket.sort(sortingAlgorithm)
95+
}
96+
return sortedArray
97+
}
98+
func isArraySorted(_ arr: [Int]) -> Bool {
99+
var idx = 0
100+
while idx < (arr.count - 1) {
101+
if arr[idx] > arr[idx+1] {
102+
return false
103+
}
104+
idx += 1
105+
}
106+
return true
107+
}
108+
let NUMITEMS = 2500
109+
let MAXBUCKETSIZE = 1000
110+
let NUMBUCKETS: Int = 10
111+
let items: [Int] = {
112+
var array: [Int]? = [Int]()
113+
for _ in 0..<NUMITEMS {
114+
array!.append(Int.random(in: 0..<MAXBUCKETSIZE))
115+
}
116+
return array!
117+
}()
118+
119+
let buckets: [Bucket<Int>] = {
120+
let val = (items.max()?.convertToInt())! + 1
121+
let maxCapacity = Int( ceil( Double(val) / Double(NUMBUCKETS)))
122+
var bucketArray = [Bucket<Int>]()
123+
for _ in 0..<NUMBUCKETS {
124+
bucketArray.append(Bucket<Int>(capacity: maxCapacity))
125+
}
126+
return bucketArray
127+
}()
128+
@inline(never)
129+
func run_BucketSort(_ N : Int) {
130+
for _ in 0..<N {
131+
let sortedArray = BucketSortImpl(items, sortingAlgorithm: InsertionSort(), bucketArray: buckets)
132+
CheckResults(isArraySorted(sortedArray))
133+
}
134+
}
135+
@inline(never)
136+
func buildWorkload() {
137+
blackHole(items)
138+
blackHole(buckets)
139+
}

branches/tensorflow/benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import BinaryFloatingPointConversionFromBinaryInteger
3131
import BinaryFloatingPointProperties
3232
import BitCount
3333
import Breadcrumbs
34+
import BucketSort
3435
import ByteSwap
3536
import COWTree
3637
import COWArrayGuaranteedParameterOverhead
@@ -199,6 +200,7 @@ registerBenchmark(BinaryFloatingPointPropertiesNextUp)
199200
registerBenchmark(BinaryFloatingPointPropertiesUlp)
200201
registerBenchmark(BitCount)
201202
registerBenchmark(Breadcrumbs)
203+
registerBenchmark(BucketSort)
202204
registerBenchmark(ByteSwap)
203205
registerBenchmark(COWTree)
204206
registerBenchmark(COWArrayGuaranteedParameterOverhead)

branches/tensorflow/include/swift/AST/Decl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,14 @@ struct OverloadSignature {
234234
/// Whether this signature is of a member defined in an extension of a generic
235235
/// type.
236236
unsigned InExtensionOfGenericType : 1;
237+
238+
/// Whether this declaration has an opaque return type.
239+
unsigned HasOpaqueReturnType : 1;
237240

238241
OverloadSignature()
239242
: UnaryOperator(UnaryOperatorKind::None), IsInstanceMember(false),
240243
IsVariable(false), IsFunction(false), InProtocolExtension(false),
241-
InExtensionOfGenericType(false) {}
244+
InExtensionOfGenericType(false), HasOpaqueReturnType(false) {}
242245
};
243246

244247
/// Determine whether two overload signatures conflict.

branches/tensorflow/include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,9 @@ ERROR(parameter_specifier_as_attr_disallowed,none,
852852
"'%0' before a parameter name is not allowed, place it before the parameter type instead",
853853
(StringRef))
854854
ERROR(parameter_specifier_repeated,none,
855-
"parameter must not have multiple '__owned', 'inout', '__shared',"
856-
" 'var', or 'let' specifiers", ())
857-
ERROR(parameter_let_var_as_attr,none,
858-
"'%0' as a parameter attribute is not allowed",
855+
"parameter must not have multiple '__owned', 'inout', or '__shared' specifiers", ())
856+
WARNING(parameter_let_var_as_attr,none,
857+
"'%0' in this position is interpreted as an argument label",
859858
(StringRef))
860859

861860

branches/tensorflow/include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ IDENTIFIER(type)
110110
IDENTIFIER(Value)
111111
IDENTIFIER(value)
112112
IDENTIFIER_WITH_NAME(value_, "_value")
113+
IDENTIFIER(WinSDK)
113114
IDENTIFIER(with)
114115
IDENTIFIER(withArguments)
115116
IDENTIFIER(withKeywordArguments)

branches/tensorflow/include/swift/AST/Module.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,6 @@ class SourceFile final : public FileUnit {
983983
/// If not, we can fast-path module checks.
984984
bool HasImplementationOnlyImports = false;
985985

986-
/// The list of protocol conformances that were "used" within this
987-
/// source file.
988-
llvm::SetVector<NormalProtocolConformance *> UsedConformances;
989-
990986
/// The scope map that describes this source file.
991987
ASTScope *Scope = nullptr;
992988

@@ -1146,17 +1142,6 @@ class SourceFile final : public FileUnit {
11461142

11471143
virtual bool walk(ASTWalker &walker) override;
11481144

1149-
/// Note that the given conformance was used by this source file.
1150-
void addUsedConformance(NormalProtocolConformance *conformance) {
1151-
UsedConformances.insert(conformance);
1152-
}
1153-
1154-
/// Retrieve the set of conformances that were used in this source
1155-
/// file.
1156-
ArrayRef<NormalProtocolConformance *> getUsedConformances() const {
1157-
return UsedConformances.getArrayRef();
1158-
}
1159-
11601145
/// @{
11611146

11621147
/// Look up the given operator in this file.

branches/tensorflow/include/swift/AST/TypeCheckRequests.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,11 @@ class PropertyDelegateBackingPropertyInfoRequest :
550550
// Allow AnyValue to compare two Type values, even though Type doesn't
551551
// support ==.
552552
template<>
553-
bool AnyValue::Holder<Type>::equals(const HolderBase &other) const;
553+
inline bool AnyValue::Holder<Type>::equals(const HolderBase &other) const {
554+
assert(typeID == other.typeID && "Caller should match type IDs");
555+
return value.getPointer() ==
556+
static_cast<const Holder<Type> &>(other).value.getPointer();
557+
}
554558

555559
void simple_display(llvm::raw_ostream &out, const Type &type);
556560

branches/tensorflow/include/swift/AST/Types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4689,6 +4689,14 @@ class ArchetypeType : public SubstitutableType,
46894689

46904690
/// Get the generic environment this archetype lives in.
46914691
GenericEnvironment *getGenericEnvironment() const;
4692+
4693+
/// Get the protocol/class existential type that most closely represents the
4694+
/// set of constraints on this archetype.
4695+
///
4696+
/// Right now, this only considers constraints on the archetype itself, not
4697+
/// any of its associated types, since those are the only kind of existential
4698+
/// type we can represent.
4699+
Type getExistentialType() const;
46924700

46934701
// Implement isa/cast/dyncast/etc.
46944702
static bool classof(const TypeBase *T) {

branches/tensorflow/include/swift/Basic/Statistics.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ FRONTEND_STATISTIC(AST, NumPrefixOperators)
141141
/// Number of precedence groups in the AST context.
142142
FRONTEND_STATISTIC(AST, NumPrecedenceGroups)
143143

144-
/// Number of conformances used by code processed by this frontend job.
145-
FRONTEND_STATISTIC(AST, NumUsedConformances)
146-
147144
/// Number of full function bodies parsed.
148145
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)
149146

branches/tensorflow/include/swift/Parse/Parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ class Parser {
609609

610610
void skipUntilDeclRBrace(tok T1, tok T2);
611611

612+
void skipListUntilDeclRBrace(SourceLoc startLoc, tok T1, tok T2);
613+
612614
/// Skip a single token, but match parentheses, braces, and square brackets.
613615
///
614616
/// Note: this does \em not match angle brackets ("<" and ">")! These are

branches/tensorflow/include/swift/Parse/Token.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class Token {
173173
return true;
174174
}
175175

176-
// 'let', 'var', and 'inout' cannot be argument labels.
177-
if (isAny(tok::kw_let, tok::kw_var, tok::kw_inout))
176+
// inout cannot be used as an argument label.
177+
if (is(tok::kw_inout))
178178
return false;
179179

180180
// All other keywords can be argument labels.

branches/tensorflow/include/swift/SIL/BridgedTypes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ BRIDGING_KNOWN_TYPE(Swift, Error)
5353
BRIDGE_TYPE(ObjectiveC, ObjCBool, Swift, Bool, false)
5454
BRIDGE_TYPE(Darwin, DarwinBoolean, Swift, Bool, false)
5555

56+
BRIDGING_KNOWN_TYPE(WinSDK, WindowsBool)
57+
BRIDGE_TYPE(WinSDK, WindowsBool, Swift, Bool, false)
58+
5659
#undef BRIDGING_KNOWN_TYPE
5760
#undef BRIDGE_TYPE
5861

branches/tensorflow/include/swift/SIL/SILBuilder.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -452,22 +452,13 @@ class SILBuilder {
452452

453453
ApplyInst *createApply(
454454
SILLocation Loc, SILValue Fn, SubstitutionMap Subs,
455-
ArrayRef<SILValue> Args, bool isNonThrowing,
455+
ArrayRef<SILValue> Args, bool isNonThrowing = false,
456456
const GenericSpecializationInformation *SpecializationInfo = nullptr) {
457457
return insert(ApplyInst::create(getSILDebugLocation(Loc), Fn, Subs, Args,
458458
isNonThrowing, C.silConv, *F,
459459
C.OpenedArchetypes, SpecializationInfo));
460460
}
461461

462-
ApplyInst *createApply(
463-
SILLocation Loc, SILValue Fn, ArrayRef<SILValue> Args, bool isNonThrowing,
464-
const GenericSpecializationInformation *SpecializationInfo = nullptr) {
465-
SILFunctionConventions conventions(Fn->getType().castTo<SILFunctionType>(),
466-
getModule());
467-
return createApply(Loc, Fn, SubstitutionMap(), Args, isNonThrowing,
468-
SpecializationInfo);
469-
}
470-
471462
TryApplyInst *createTryApply(
472463
SILLocation Loc, SILValue fn, SubstitutionMap subs,
473464
ArrayRef<SILValue> args, SILBasicBlock *normalBB, SILBasicBlock *errorBB,
@@ -490,7 +481,7 @@ class SILBuilder {
490481

491482
BeginApplyInst *createBeginApply(
492483
SILLocation Loc, SILValue Fn, SubstitutionMap Subs,
493-
ArrayRef<SILValue> Args, bool isNonThrowing,
484+
ArrayRef<SILValue> Args, bool isNonThrowing = false,
494485
const GenericSpecializationInformation *SpecializationInfo = nullptr) {
495486
return insert(BeginApplyInst::create(
496487
getSILDebugLocation(Loc), Fn, Subs, Args, isNonThrowing, C.silConv, *F,

branches/tensorflow/lib/AST/ASTContext.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,6 +3946,12 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal,
39463946
addTrivial(getIdentifier("DarwinBoolean"), darwin);
39473947
}
39483948

3949+
if (auto winsdk = getLoadedModule(Id_WinSDK)) {
3950+
// NOTE: WindowsBool is odd because it is bridged to Bool in APIs, but can
3951+
// also be trivially bridged.
3952+
addTrivial(getIdentifier("WindowsBool"), winsdk);
3953+
}
3954+
39493955
if (auto objectiveC = getLoadedModule(Id_ObjectiveC)) {
39503956
addTrivial(Id_Selector, objectiveC, true);
39513957

@@ -4003,6 +4009,7 @@ ASTContext::getForeignRepresentationInfo(NominalTypeDecl *nominal,
40034009
}
40044010
};
40054011
conditionallyAddTrivial(nominal, getIdentifier("DarwinBoolean") , Id_Darwin);
4012+
conditionallyAddTrivial(nominal, getIdentifier("WindowsBool"), Id_WinSDK);
40064013
conditionallyAddTrivial(nominal, Id_Selector, Id_ObjectiveC, true);
40074014
conditionallyAddTrivial(nominal, getIdentifier("ObjCBool"), Id_ObjectiveC);
40084015
conditionallyAddTrivial(nominal, getSwiftId(KnownFoundationEntity::NSZone), Id_ObjectiveC, true);

0 commit comments

Comments
 (0)