Skip to content

Commit c482b09

Browse files
committed
SIL: let Builder.createAllocStack specify a debugVariable
1 parent 28dd6f7 commit c482b09

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,18 @@ public struct Builder {
122122
}
123123
}
124124

125-
public func createAllocStack(_ type: Type, hasDynamicLifetime: Bool = false,
125+
public func createAllocStack(_ type: Type,
126+
debugVariable: DebugVariableInstruction.DebugVariable? = nil,
127+
hasDynamicLifetime: Bool = false,
126128
isLexical: Bool = false, isFromVarDecl: Bool = false,
127129
usesMoveableValueDebugInfo: Bool = false) -> AllocStackInst {
128-
let dr = bridged.createAllocStack(type.bridged, hasDynamicLifetime, isLexical,
130+
let bridgedDebugVar: OptionalBridgedSILDebugVariable
131+
if let debugVariable = debugVariable {
132+
bridgedDebugVar = OptionalBridgedSILDebugVariable(debugVariable)
133+
} else {
134+
bridgedDebugVar = OptionalBridgedSILDebugVariable()
135+
}
136+
let dr = bridged.createAllocStack(type.bridged, bridgedDebugVar, hasDynamicLifetime, isLexical,
129137
isFromVarDecl, usesMoveableValueDebugInfo)
130138
return notifyNew(dr.getAs(AllocStackInst.self))
131139
}

include/swift/SIL/SILBridging.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,22 @@ struct BridgedGenericSpecializationInformation {
630630
struct BridgedSILDebugVariable {
631631
uint64_t storage[16];
632632

633+
BRIDGED_INLINE BridgedSILDebugVariable() {}
633634
BRIDGED_INLINE BridgedSILDebugVariable(const swift::SILDebugVariable &var);
634635
BRIDGED_INLINE BridgedSILDebugVariable(const BridgedSILDebugVariable &rhs);
635636
BRIDGED_INLINE ~BridgedSILDebugVariable();
636637
BRIDGED_INLINE BridgedSILDebugVariable &operator=(const BridgedSILDebugVariable &rhs);
637638
BRIDGED_INLINE swift::SILDebugVariable unbridge() const;
638639
};
639640

641+
struct OptionalBridgedSILDebugVariable {
642+
BridgedSILDebugVariable debugVar;
643+
bool hasDebugVar = false;
644+
645+
OptionalBridgedSILDebugVariable() {}
646+
OptionalBridgedSILDebugVariable(BridgedSILDebugVariable d) : debugVar(d), hasDebugVar(true) {}
647+
};
648+
640649
struct BridgedInstruction {
641650
SwiftObject obj;
642651

@@ -1159,8 +1168,8 @@ struct BridgedBuilder{
11591168
BridgedSILTypeArray elementTypes, BridgedValueArray elementCountOperands) const;
11601169

11611170
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction
1162-
createAllocStack(BridgedType type, bool hasDynamicLifetime, bool isLexical,
1163-
bool isFromVarDecl, bool wasMoved) const;
1171+
createAllocStack(BridgedType type, OptionalBridgedSILDebugVariable debugVar,
1172+
bool hasDynamicLifetime, bool isLexical, bool isFromVarDecl, bool wasMoved) const;
11641173
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createAllocVector(BridgedValue capacity,
11651174
BridgedType type) const;
11661175
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createDeallocStack(BridgedValue operand) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,12 +2162,16 @@ BridgedInstruction BridgedBuilder::createAllocRef(BridgedType type,
21622162
}
21632163

21642164
BridgedInstruction BridgedBuilder::createAllocStack(BridgedType type,
2165+
OptionalBridgedSILDebugVariable debugVar,
21652166
bool hasDynamicLifetime,
21662167
bool isLexical,
21672168
bool isFromVarDecl,
21682169
bool wasMoved) const {
2170+
std::optional<swift::SILDebugVariable> var = std::nullopt;
2171+
if (debugVar.hasDebugVar)
2172+
var = debugVar.debugVar.unbridge();
21692173
return {unbridged().createAllocStack(
2170-
regularLoc(), type.unbridged(), std::nullopt,
2174+
regularLoc(), type.unbridged(), var,
21712175
swift::HasDynamicLifetime_t(hasDynamicLifetime),
21722176
swift::IsLexical_t(isLexical), swift::IsFromVarDecl_t(isFromVarDecl),
21732177
swift::UsesMoveableValueDebugInfo_t(wasMoved), /*skipVarDeclAssert=*/ true)};

0 commit comments

Comments
 (0)