Skip to content

Commit 2325cf1

Browse files
authored
Merge pull request swiftlang#73011 from Snowy1803/6.0-salvage-debug-info-tuple
[6.0] [DebugInfo] Salvage debug info for tuples
2 parents b0ac3e0 + 0302374 commit 2325cf1

40 files changed

+166
-139
lines changed

docs/SIL.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4297,7 +4297,6 @@ less verbose.
42974297
debug-var-attr ::= 'let'
42984298
debug-var-attr ::= 'name' string-literal
42994299
debug-var-attr ::= 'argno' integer-literal
4300-
debug-var-attr ::= 'implicit'
43014300

43024301
There are a number of attributes that provide details about the source
43034302
variable that is being described, including the name of the

include/swift/SIL/SILDebugVariable.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct SILDebugVariable {
3838
StringRef Name;
3939
unsigned ArgNo : 16;
4040
unsigned Constant : 1;
41-
unsigned Implicit : 1;
4241
unsigned isDenseMapSingleton : 2;
4342
std::optional<SILType> Type;
4443
std::optional<SILLocation> Loc;
@@ -58,17 +57,17 @@ struct SILDebugVariable {
5857
}
5958

6059
SILDebugVariable()
61-
: ArgNo(0), Constant(false), Implicit(false), isDenseMapSingleton(0),
60+
: ArgNo(0), Constant(false), isDenseMapSingleton(0),
6261
Scope(nullptr) {}
6362
SILDebugVariable(bool Constant, uint16_t ArgNo)
64-
: ArgNo(ArgNo), Constant(Constant), Implicit(false),
63+
: ArgNo(ArgNo), Constant(Constant),
6564
isDenseMapSingleton(0), Scope(nullptr) {}
6665
SILDebugVariable(StringRef Name, bool Constant, unsigned ArgNo,
67-
bool IsImplicit = false, std::optional<SILType> AuxType = {},
66+
std::optional<SILType> AuxType = {},
6867
std::optional<SILLocation> DeclLoc = {},
6968
const SILDebugScope *DeclScope = nullptr,
7069
llvm::ArrayRef<SILDIExprElement> ExprElements = {})
71-
: Name(Name), ArgNo(ArgNo), Constant(Constant), Implicit(IsImplicit),
70+
: Name(Name), ArgNo(ArgNo), Constant(Constant),
7271
isDenseMapSingleton(0), Type(AuxType), Loc(DeclLoc), Scope(DeclScope),
7372
DIExpr(ExprElements) {}
7473

@@ -85,9 +84,8 @@ struct SILDebugVariable {
8584
// it in this class so that's it's easier to carry DIExpr around.
8685
bool operator==(const SILDebugVariable &V) const {
8786
return ArgNo == V.ArgNo && Constant == V.Constant && Name == V.Name &&
88-
Implicit == V.Implicit && Type == V.Type && Loc == V.Loc &&
89-
Scope == V.Scope && isDenseMapSingleton == V.isDenseMapSingleton &&
90-
DIExpr == V.DIExpr;
87+
Type == V.Type && Loc == V.Loc && Scope == V.Scope &&
88+
isDenseMapSingleton == V.isDenseMapSingleton && DIExpr == V.DIExpr;
9189
}
9290

9391
SILDebugVariable withoutDIExpr() const {
@@ -103,7 +101,7 @@ struct SILDebugVariable {
103101

104102
/// Returns the hashcode for the new projection path.
105103
inline llvm::hash_code hash_value(const SILDebugVariable &P) {
106-
return llvm::hash_combine(P.ArgNo, P.Constant, P.Name, P.Implicit,
104+
return llvm::hash_combine(P.ArgNo, P.Constant, P.Name,
107105
P.isDenseMapSingleton, P.Type, P.Loc, P.Scope,
108106
P.DIExpr);
109107
}

include/swift/SIL/SILInstruction.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,12 +1849,10 @@ class TailAllocatedDebugVariable {
18491849
int_type HasValue : 1;
18501850
/// True if this is a let-binding.
18511851
int_type Constant : 1;
1852-
/// True if this variable is created by compiler
1853-
int_type Implicit : 1;
18541852
/// When this is nonzero there is a tail-allocated string storing
18551853
/// variable name present. This typically only happens for
18561854
/// instructions that were created from parsing SIL assembler.
1857-
int_type NameLength : 13;
1855+
int_type NameLength : 14;
18581856
/// The source function argument position from left to right
18591857
/// starting with 1 or 0 if this is a local variable.
18601858
int_type ArgNo : 16;
@@ -1876,9 +1874,6 @@ class TailAllocatedDebugVariable {
18761874
StringRef getName(const char *buf) const;
18771875
bool isLet() const { return Bits.Data.Constant; }
18781876

1879-
bool isImplicit() const { return Bits.Data.Implicit; }
1880-
void setImplicit(bool V = true) { Bits.Data.Implicit = V; }
1881-
18821877
std::optional<SILDebugVariable>
18831878
get(VarDecl *VD, const char *buf, std::optional<SILType> AuxVarType = {},
18841879
std::optional<SILLocation> DeclLoc = {},
@@ -1890,8 +1885,8 @@ class TailAllocatedDebugVariable {
18901885
StringRef name = getName(buf);
18911886
if (VD && name.empty())
18921887
name = VD->getName().str();
1893-
return SILDebugVariable(name, isLet(), getArgNo(), isImplicit(), AuxVarType,
1894-
DeclLoc, DeclScope, DIExprElements);
1888+
return SILDebugVariable(name, isLet(), getArgNo(), AuxVarType, DeclLoc,
1889+
DeclScope, DIExprElements);
18951890
}
18961891
};
18971892
static_assert(sizeof(TailAllocatedDebugVariable) == 4,

lib/SIL/IR/SILInstructions.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ TailAllocatedDebugVariable::TailAllocatedDebugVariable(
175175
Bits.Data.HasValue = true;
176176
Bits.Data.Constant = Var->Constant;
177177
Bits.Data.ArgNo = Var->ArgNo;
178-
Bits.Data.Implicit = Var->Implicit;
179178
Bits.Data.NameLength = Var->Name.size();
180179
assert(Bits.Data.ArgNo == Var->ArgNo && "Truncation");
181180
assert(Bits.Data.NameLength == Var->Name.size() && "Truncation");
@@ -256,10 +255,6 @@ AllocStackInst::AllocStackInst(
256255
assert(sharedUInt32().AllocStackInst.numOperands ==
257256
TypeDependentOperands.size() &&
258257
"Truncation");
259-
auto *VD = Loc.getLocation().getAsASTNode<VarDecl>();
260-
if (Var && VD) {
261-
VarInfo.setImplicit(VD->isImplicit() || VarInfo.isImplicit());
262-
}
263258
TrailingOperandsList::InitOperandsList(getAllOperands().begin(), this,
264259
TypeDependentOperands);
265260
}
@@ -454,8 +449,6 @@ DebugValueInst::DebugValueInst(
454449
getTrailingObjects<SILLocation>(),
455450
getTrailingObjects<const SILDebugScope *>(),
456451
getTrailingObjects<SILDIExprElement>()) {
457-
if (auto *VD = DebugLoc.getLocation().getAsASTNode<VarDecl>())
458-
VarInfo.setImplicit(VD->isImplicit() || VarInfo.isImplicit());
459452
setPoisonRefs(poisonRefs);
460453
if (usesMoveableValueDebugInfo || Operand->getType().isMoveOnly())
461454
setUsesMoveableValueDebugInfo();

lib/SIL/IR/SILPrinter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
14241424

14251425
if (Var->ArgNo)
14261426
*this << ", argno " << Var->ArgNo;
1427-
if (Var->Implicit)
1428-
*this << ", implicit";
14291427
if (Var->Type) {
14301428
*this << ", type ";
14311429
Var->Type->print(PrintState.OS, PrintState.ASTOptions);

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,6 @@ bool SILParser::parseSILDebugVar(SILDebugVariable &Var) {
16771677
Var.Constant = false;
16781678
} else if (Key == "loc") {
16791679
Var.Constant = false;
1680-
} else if (Key == "implicit") {
1681-
Var.Implicit = true;
16821680
} else {
16831681
P.diagnose(P.Tok, diag::sil_dbg_unknown_key, Key);
16841682
return true;

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,7 @@ bool swift::hasOnlyEndOfScopeOrEndOfLifetimeUses(SILInstruction *inst) {
238238
// Include debug uses only in Onone mode.
239239
if (isDebugUser && inst->getFunction()->getEffectiveOptimizationMode() <=
240240
OptimizationMode::NoOptimization)
241-
if (auto DbgVarInst = DebugVarCarryingInst(user)) {
242-
auto VarInfo = DbgVarInst.getVarInfo();
243-
if (VarInfo && !VarInfo->Implicit)
244-
return false;
245-
}
241+
return false;
246242
}
247243
}
248244
return true;
@@ -1848,8 +1844,8 @@ void swift::salvageDebugInfo(SILInstruction *I) {
18481844
}
18491845
// If a `struct` SIL instruction is "unwrapped" and removed,
18501846
// for instance, in favor of using its enclosed value directly,
1851-
// we need to make sure any of its related `debug_value` instruction
1852-
// is preserved.
1847+
// we need to make sure any of its related `debug_value` instructions
1848+
// are preserved.
18531849
if (auto *STI = dyn_cast<StructInst>(I)) {
18541850
auto STVal = STI->getResult(0);
18551851
llvm::ArrayRef<VarDecl *> FieldDecls =
@@ -1875,6 +1871,31 @@ void swift::salvageDebugInfo(SILInstruction *I) {
18751871
}
18761872
}
18771873
}
1874+
// Similarly, if a `tuple` SIL instruction is "unwrapped" and removed,
1875+
// we need to make sure any of its related `debug_value` instructions
1876+
// are preserved.
1877+
if (auto *TTI = dyn_cast<TupleInst>(I)) {
1878+
auto TTVal = TTI->getResult(0);
1879+
for (Operand *U : getDebugUses(TTVal)) {
1880+
auto *DbgInst = cast<DebugValueInst>(U->getUser());
1881+
auto VarInfo = DbgInst->getVarInfo();
1882+
if (!VarInfo)
1883+
continue;
1884+
TupleType *TT = TTI->getTupleType();
1885+
for (auto i : indices(TT->getElements())) {
1886+
SILDebugVariable NewVarInfo = *VarInfo;
1887+
auto FragDIExpr = SILDebugInfoExpression::createTupleFragment(TT, i);
1888+
NewVarInfo.DIExpr.append(FragDIExpr);
1889+
1890+
if (!NewVarInfo.Type)
1891+
NewVarInfo.Type = TTI->getType();
1892+
1893+
// Create a new debug_value
1894+
SILBuilder(TTI, DbgInst->getDebugScope())
1895+
.createDebugValue(DbgInst->getLoc(), TTI->getElement(i), NewVarInfo);
1896+
}
1897+
}
1898+
}
18781899

18791900
if (auto *IA = dyn_cast<IndexAddrInst>(I)) {
18801901
if (IA->getBase() && IA->getIndex())

test/AutoDiff/compiler_crashers_fixed/58660-conflicting-debug-info-inlining.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ struct MyModel: Differentiable {
4545
@differentiable(reverse)
4646
mutating func member4() {
4747
// CHECK-LABEL: // pullback of MyModel.member4()
48-
// CHECK-NOT: debug_value %{{.*}} : $MyModel.TangentVector, var, name %{{.*}}, argno 1, implicit, scope
48+
// CHECK-NOT: debug_value %{{.*}} : $MyModel.TangentVector, var, name %{{.*}}, argno 1, scope
4949
// CHECK: bb0(%{{.*}} : $_AD__$s4main7MyModelV7member4yyF_bb3__Pred__src_0_wrt_0):
50-
// CHECK: debug_value %{{.*}} : $MyModel.TangentVector, var, name "derivative of 'self' in scope at {{.*}} (scope #1)", implicit, scope
50+
// CHECK: debug_value %{{.*}} : $MyModel.TangentVector, var, name "derivative of 'self' in scope at {{.*}} (scope #1)", scope
5151
// Must be a differentiable type.
5252
var localVar: Float = 0
5353

test/Concurrency/transfernonsendable.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ bb3(%4 : @owned $FakeOptional<NonSendableKlass>):
287287

288288
sil [ossa] @warningIfCallingGetter : $@convention(method) @async (@sil_isolated @guaranteed MyActor) -> () {
289289
bb0(%0 : @guaranteed $MyActor):
290-
debug_value %0 : $MyActor, let, name "self", argno 1, implicit
290+
debug_value %0 : $MyActor, let, name "self", argno 1
291291
hop_to_executor %0 : $MyActor
292292
%3 = class_method %0 : $MyActor, #MyActor.klass!getter : (isolated MyActor) -> () -> NonSendableKlass, $@convention(method) (@sil_isolated @guaranteed MyActor) -> @owned NonSendableKlass
293293
%4 = apply %3(%0) : $@convention(method) (@sil_isolated @guaranteed MyActor) -> @owned NonSendableKlass
@@ -301,7 +301,7 @@ bb0(%0 : @guaranteed $MyActor):
301301

302302
sil [ossa] @assignIntoSetter : $@convention(method) @async (@sil_isolated @guaranteed MyActor) -> () {
303303
bb0(%0 : @guaranteed $MyActor):
304-
debug_value %0 : $MyActor, let, name "self", argno 1, implicit
304+
debug_value %0 : $MyActor, let, name "self", argno 1
305305
hop_to_executor %0 : $MyActor
306306
%4 = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
307307
%5 = apply %4() : $@convention(thin) () -> @owned NonSendableKlass

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ bb0(%arg : $Builtin.Word):
16801680

16811681
sil hidden [ossa] @test_unconditional_checked_cast : $@convention(method) (@guaranteed ChildClass) -> @owned ChildClass {
16821682
bb0(%0 : @guaranteed $ChildClass):
1683-
debug_value %0 : $ChildClass, let, name "self", argno 1, implicit
1683+
debug_value %0 : $ChildClass, let, name "self", argno 1
16841684
%2 = copy_value %0 : $ChildClass
16851685
%3 = upcast %2 : $ChildClass to $ParentClass
16861686
%4 = function_ref @copyParentClass : $@convention(thin) (@guaranteed ParentClass) -> @owned ParentClass
@@ -1693,4 +1693,4 @@ bb0(%0 : @guaranteed $ChildClass):
16931693
%11 = copy_value %8 : $ChildClass
16941694
destroy_value %8 : $ChildClass
16951695
return %11 : $ChildClass
1696-
}
1696+
}

0 commit comments

Comments
 (0)