Skip to content

Commit 1a875cb

Browse files
author
Max Moiseev
committed
[stdlib][swift-3-indexing-model] speeding up the compilation
1 parent 6c56af5 commit 1a875cb

File tree

7 files changed

+44
-31
lines changed

7 files changed

+44
-31
lines changed

stdlib/public/core/LazyCollection.swift.gyb

-7
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,6 @@ extension ${TraversalCollection} where Self : LazyCollectionProtocol {
235235

236236
% end
237237

238-
extension LazyCollectionProtocol {
239-
/// Identical to `self`.
240-
public var lazy: Self { // Don't re-wrap already-lazy collections
241-
return self
242-
}
243-
}
244-
245238
@available(*, unavailable, renamed: "LazyCollectionProtocol")
246239
public typealias LazyCollectionType = LazyCollectionProtocol
247240

test/1_stdlib/Inputs/flatMap.gyb

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ ${Test}.test("flatMap/${Kind}/Lazy") {
1212
elements: test.sequence.map(OpaqueValue.init))
1313
let closureLifetimeTracker = LifetimeTracked(0)
1414
var timesClosureWasCalled = 0
15-
var result = s.lazy.flatMap {
15+
16+
let lazySeq = s.lazy
17+
var result = lazySeq.flatMap {
1618
(element: OpaqueValue<Int>) -> ${Minimal}<OpaqueValue<Int32>> in
1719
_blackHole(closureLifetimeTracker)
1820
timesClosureWasCalled += 1
21+
let elements = test.transform(element.value)
1922
return ${Minimal}<OpaqueValue<Int32>>(
20-
elements: test.transform(element.value).map { OpaqueValue(Int32($0)) })
23+
elements: elements.map { OpaqueValue($0) })
2124
}
2225
expectEqual(0, timesClosureWasCalled, "Unexpected eagerness")
2326

@@ -47,8 +50,9 @@ ${Test}.test("flatMap/${Kind}/Lazy") {
4750

4851
// FIXME: we are not calling check${Kind} because of the same issue again.
4952
// <rdar://problem/21989896>
53+
let expected = test.expected.map(OpaqueValue.init)
5054
expectEqualSequence(
51-
test.expected.map(OpaqueValue.init), result,
55+
expected, result,
5256
stackTrace: SourceLocStack().with(test.loc)
5357
) { $0.value == $1.value }
5458
% end

test/1_stdlib/Map.swift

+18-14
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,25 @@ extension LazyMapCollection where Base : TestProtocol1, Element : TestProtocol1
3636
// CHECK: testing...
3737
print("testing...")
3838

39-
// Test mapping a collection
40-
// CHECK-NEXT: [6, 9, 12, 15, 18, 21]
41-
let a = Array((2..<8).lazy.map { $0 * 3 })
42-
print(a)
43-
44-
// Test mapping a sequence
45-
let s = a.makeIterator().lazy.map { $0 / 3 }
46-
// CHECK-NEXT: <2, 3, 4, 5, 6, 7>
47-
print("<", terminator: "")
48-
var prefix = ""
49-
for x in s {
50-
print("\(prefix)\(x)", terminator: "")
51-
prefix = ", "
39+
do {
40+
// Test mapping a collection
41+
// CHECK-NEXT: [6, 9, 12, 15, 18, 21]
42+
let lazyRange = (2..<8).lazy
43+
let a = Array(lazyRange.map { $0 * 3 })
44+
print(a)
45+
46+
// Test mapping a sequence
47+
let lazySeq = a.makeIterator().lazy
48+
let s = lazySeq.map { $0 / 3 }
49+
// CHECK-NEXT: <2, 3, 4, 5, 6, 7>
50+
print("<", terminator: "")
51+
var prefix = ""
52+
for x in s {
53+
print("\(prefix)\(x)", terminator: "")
54+
prefix = ", "
55+
}
56+
print(">")
5257
}
53-
print(">")
5458

5559
//===--- Avoid creating gratuitously self-destructive sequences -----------===//
5660

test/1_stdlib/Range.swift.gyb

+5-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ RangeTestSuite.test("map()") {
127127
}
128128

129129
RangeTestSuite.test("reversed()") {
130-
var result = (0..<10).lazy.reversed()
131-
expectType(Array<Int>.self, &result)
130+
let lazyRange = (0..<10).lazy
131+
var result = lazyRange.reversed()
132+
typealias Expected = LazyRandomAccessCollection<
133+
ReversedRandomAccessCollection<CountableRange<Int>>>
134+
expectType(Expected.self, &result)
132135
expectEqualSequence(
133136
[ 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ],
134137
result)

test/1_stdlib/StringAPI.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,15 @@ func checkHasPrefixHasSuffix(
244244
}
245245
let expectHasPrefix = lhsNFDGraphemeClusters.starts(
246246
with: rhsNFDGraphemeClusters, isEquivalent: (==))
247+
248+
let lazyLhs = lhsNFDGraphemeClusters.lazy
249+
let reversedLhs = lazyLhs.reversed()
250+
251+
let lazyRhs = rhsNFDGraphemeClusters.lazy
252+
let reversedRhs = lazyRhs.reversed()
253+
247254
let expectHasSuffix =
248-
lhsNFDGraphemeClusters.lazy.reversed().starts(
249-
with: rhsNFDGraphemeClusters.lazy.reversed(), isEquivalent: (==))
255+
reversedLhs.starts(with: reversedRhs, isEquivalent: (==))
250256

251257
expectEqual(expectHasPrefix, lhs.hasPrefix(rhs), stackTrace: stackTrace)
252258
expectEqual(

validation-test/stdlib/Arrays.swift.gyb

+3-2
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,12 @@ for (step, evilBoundsCheck) in [ (1, true), (-1, false), (-1, true) ] {
624624
}
625625

626626
for (op, rangeMax) in ["Grow":0, "Shrink":200] {
627+
let lazyRange = (0..<200).lazy
627628
let t3 = ArrayTestSuite.test("\(testPrefix)/replaceSubrange/\(op)Unique")
628629
(_isDebugAssertConfiguration() ? t3.crashOutputMatches(message) : t3)
629630
.code {
630631
let evil = EvilCollection(step, boundsChecked: evilBoundsCheck)
631-
var a = Array((0..<200).lazy.map { LifetimeTracked($0) })
632+
var a = Array(lazyRange.map { LifetimeTracked($0) })
632633
if expectedToFail {
633634
expectCrashLater()
634635
}
@@ -639,7 +640,7 @@ for (step, evilBoundsCheck) in [ (1, true), (-1, false), (-1, true) ] {
639640
(_isDebugAssertConfiguration() ? t4.crashOutputMatches(message) : t4)
640641
.code {
641642
let evil = EvilCollection(step, boundsChecked: evilBoundsCheck)
642-
var a = Array((0..<200).lazy.map { LifetimeTracked($0) })
643+
var a = Array(lazyRange.map { LifetimeTracked($0) })
643644
var b = a
644645
if expectedToFail {
645646
expectCrashLater()

validation-test/stdlib/CollectionType.swift.gyb

+3-1
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,11 @@ CollectionTypeTests.test("index(of:)/ContinueSearch") {
716716
let c = MinimalCollection(
717717
elements: [1, 2, 1, 3, 1].map(MinimalEquatableValue.init))
718718
let foundIndices = c._test_indicesOf(MinimalEquatableValue(1))
719+
let actual = foundIndices.map { c.distance(from: c.startIndex, to: $0) }
719720
expectEqualSequence(
720721
[ 0, 2, 4 ],
721-
foundIndices.map { c.distance(from: c.startIndex, to: $0) })
722+
actual
723+
)
722724
}
723725
}
724726

0 commit comments

Comments
 (0)