Skip to content

Commit f6f9acc

Browse files
committed
Add SILBuilder constructors that take a DebugScope.
Allow a new SILBuilder to be created for an insertion point, while providing all of its necessary context. Ultimately, the builder's constructor should take an insertion point, DebugLocation, and context. Then we won't need to pass SILLocation to all of its methods. This makes much more sense and is much safer than saving the insertion point via an RAII object or defining a separate SILBuilderWithScope. Those broken abstractions should go away.
1 parent e04378f commit f6f9acc

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,20 @@ class SILBuilder {
173173
/// location.
174174
///
175175
/// Clients should prefer this constructor.
176-
SILBuilder(SILInstruction *I, SILBuilderContext &C)
176+
SILBuilder(SILInstruction *I, const SILDebugScope *DS, SILBuilderContext &C)
177177
: TempContext(C.getModule()), C(C), F(I->getFunction()) {
178+
assert(DS && "instruction has no debug scope");
179+
setCurrentDebugScope(DS);
178180
setInsertionPoint(I);
179181
}
180182

183+
SILBuilder(SILBasicBlock *BB, const SILDebugScope *DS, SILBuilderContext &C)
184+
: TempContext(C.getModule()), C(C), F(BB->getParent()) {
185+
assert(DS && "block has no debug scope");
186+
setCurrentDebugScope(DS);
187+
setInsertionPoint(BB);
188+
}
189+
181190
// Allow a pass to override the current SIL module conventions. This should
182191
// only be done by a pass responsible for lowering SIL to a new stage
183192
// (e.g. AddressLowering).
@@ -2123,10 +2132,8 @@ class SILBuilderWithScope : public SILBuilder {
21232132
///
21242133
/// Clients should prefer this constructor.
21252134
SILBuilderWithScope(SILInstruction *I, SILBuilderContext &C)
2126-
: SILBuilder(I, C) {
2127-
assert(I->getDebugScope() && "instruction has no debug scope");
2128-
setCurrentDebugScope(I->getDebugScope());
2129-
}
2135+
: SILBuilder(I, I->getDebugScope(), C)
2136+
{}
21302137

21312138
explicit SILBuilderWithScope(
21322139
SILInstruction *I,

0 commit comments

Comments
 (0)