Skip to content

Commit 90c83be

Browse files
committed
Swift Optimizer: make the Stack data structure also work with a ModulePassContext
1 parent fbb694b commit 90c83be

File tree

1 file changed

+7
-6
lines changed
  • SwiftCompilerSources/Sources/Optimizer/DataStructures

1 file changed

+7
-6
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/Stack.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import SIL
2626
/// destruct this data structure, e.g. in a `defer {}` block.
2727
struct Stack<Element> : CollectionLikeSequence {
2828

29-
private let context: PassContext
29+
private let bridgedContext: BridgedPassContext
3030
private var firstSlab = BridgedSlab(data: nil)
3131
private var lastSlab = BridgedSlab(data: nil)
3232
private var endIndex: Int = 0
@@ -61,7 +61,8 @@ struct Stack<Element> : CollectionLikeSequence {
6161
}
6262
}
6363

64-
init(_ context: PassContext) { self.context = context }
64+
init(_ context: PassContext) { self.bridgedContext = context._bridged }
65+
init(_ context: ModulePassContext) { self.bridgedContext = context._bridged }
6566

6667
func makeIterator() -> Iterator {
6768
return Iterator(slab: firstSlab, index: 0, lastSlab: lastSlab, endIndex: endIndex)
@@ -77,11 +78,11 @@ struct Stack<Element> : CollectionLikeSequence {
7778

7879
mutating func push(_ element: Element) {
7980
if endIndex >= Stack.slabCapacity {
80-
lastSlab = PassContext_allocSlab(context._bridged, lastSlab)
81+
lastSlab = PassContext_allocSlab(bridgedContext, lastSlab)
8182
endIndex = 0
8283
} else if firstSlab.data == nil {
8384
assert(endIndex == 0)
84-
firstSlab = PassContext_allocSlab(context._bridged, lastSlab)
85+
firstSlab = PassContext_allocSlab(bridgedContext, lastSlab)
8586
lastSlab = firstSlab
8687
}
8788
(Stack.bind(lastSlab) + endIndex).initialize(to: element)
@@ -109,12 +110,12 @@ struct Stack<Element> : CollectionLikeSequence {
109110

110111
if endIndex == 0 {
111112
if lastSlab.data == firstSlab.data {
112-
_ = PassContext_freeSlab(context._bridged, lastSlab)
113+
_ = PassContext_freeSlab(bridgedContext, lastSlab)
113114
firstSlab.data = nil
114115
lastSlab.data = nil
115116
endIndex = 0
116117
} else {
117-
lastSlab = PassContext_freeSlab(context._bridged, lastSlab)
118+
lastSlab = PassContext_freeSlab(bridgedContext, lastSlab)
118119
endIndex = Stack.slabCapacity
119120
}
120121
}

0 commit comments

Comments
 (0)