Skip to content

Commit 442739a

Browse files
committed
[NFC] Add a Builder.insertionBlock API.
Some utilities, like Builder.insert(after:) pass a Builder object that represents an insertion point. That insertion point is sometimes needed to determine which instructions to create (endApply vs. abortApply). But there is no way to recover the insertion point. We don't want to simply return an instruction, because that could be interpreted in different ways. Instead we provide insertion block, but only in those situations where it makes sense and can't be used incorrectly.
1 parent 5fc103b commit 442739a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public struct Builder {
2929
private let notificationHandler: BridgedChangeNotificationHandler
3030
private let notifyNewInstruction: (Instruction) -> ()
3131

32+
/// Return 'nil' when inserting at the start of a function or in a global initializer.
33+
public var insertionBlock: BasicBlock? {
34+
switch insertAt {
35+
case let .before(inst):
36+
return inst.parentBlock
37+
case let .atEndOf(block):
38+
return block
39+
case .atStartOf, .staticInitializer:
40+
return nil
41+
}
42+
}
43+
3244
public var bridged: BridgedBuilder {
3345
switch insertAt {
3446
case .before(let inst):

0 commit comments

Comments
 (0)