Skip to content

Commit 2fc311a

Browse files
Merge pull request swiftlang#35444 from adrian-prantl/async-box-di
Add debug info support for boxed arguments in async functions.
2 parents ef22a10 + b3f5ac3 commit 2fc311a

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
199199
llvm::DILocalVariable *Var, llvm::DIExpression *Expr,
200200
unsigned Line, unsigned Col, llvm::DILocalScope *Scope,
201201
const SILDebugScope *DS, bool InCoroContext = false);
202+
#ifndef NDEBUG
203+
bool verifyCoroutineArgument(llvm::Value *Addr);
204+
#endif
205+
202206
void emitGlobalVariableDeclaration(llvm::GlobalVariable *Storage,
203207
StringRef Name, StringRef LinkageName,
204208
DebugTypeInfo DebugType,
@@ -1611,6 +1615,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16111615
return getOrCreateDesugaredType(CanTy, DbgTy);
16121616
}
16131617

1618+
// SILBox should appear only inside of coroutine contexts.
1619+
case TypeKind::SILBox:
16141620
case TypeKind::DependentMember:
16151621
case TypeKind::GenericTypeParam: {
16161622
// FIXME: Provide a more meaningful debug type.
@@ -1628,7 +1634,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16281634
case TypeKind::Hole:
16291635
case TypeKind::Module:
16301636
case TypeKind::SILBlockStorage:
1631-
case TypeKind::SILBox:
16321637
case TypeKind::SILToken:
16331638
case TypeKind::BuiltinUnsafeValueBuffer:
16341639
case TypeKind::BuiltinDefaultActorStorage:
@@ -1652,7 +1657,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16521657
switch (Ty->getKind()) {
16531658
case TypeKind::GenericFunction: // Not yet supported.
16541659
case TypeKind::SILBlockStorage: // Not supported at all.
1655-
case TypeKind::SILBox:
16561660
return false;
16571661
default:
16581662
return true;
@@ -2455,6 +2459,28 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
24552459
}
24562460
}
24572461

2462+
#ifndef NDEBUG
2463+
bool IRGenDebugInfoImpl::verifyCoroutineArgument(llvm::Value *Addr) {
2464+
llvm::Value *Storage = Addr;
2465+
while (Storage) {
2466+
if (auto *LdInst = dyn_cast<llvm::LoadInst>(Storage))
2467+
Storage = LdInst->getOperand(0);
2468+
else if (auto *GEPInst = dyn_cast<llvm::GetElementPtrInst>(Storage))
2469+
Storage = GEPInst->getOperand(0);
2470+
else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
2471+
Storage = BCInst->getOperand(0);
2472+
else if (auto *CallInst = dyn_cast<llvm::CallInst>(Storage)) {
2473+
assert(CallInst->getCalledFunction() == IGM.getProjectBoxFn() &&
2474+
"unhandled projection");
2475+
Storage = CallInst->getArgOperand(0);
2476+
} else
2477+
2478+
break;
2479+
}
2480+
return llvm::isa<llvm::Argument>(Storage);
2481+
}
2482+
#endif
2483+
24582484
void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
24592485
llvm::GlobalVariable *Var, StringRef Name, StringRef LinkageName,
24602486
DebugTypeInfo DbgTy, bool IsLocalToUnit, bool InFixedBuffer,
@@ -2638,6 +2664,12 @@ void IRGenDebugInfo::emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,
26382664
Builder, Storage, Var, Expr, Line, Col, Scope, DS, InCoroContext);
26392665
}
26402666

2667+
#ifndef NDEBUG
2668+
bool IRGenDebugInfo::verifyCoroutineArgument(llvm::Value *Addr) {
2669+
return static_cast<IRGenDebugInfoImpl *>(this)->verifyCoroutineArgument(Addr);
2670+
}
2671+
#endif
2672+
26412673
void IRGenDebugInfo::emitGlobalVariableDeclaration(
26422674
llvm::GlobalVariable *Storage, StringRef Name, StringRef LinkageName,
26432675
DebugTypeInfo DebugType, bool IsLocalToUnit, bool InFixedBuffer,

lib/IRGen/IRGenDebugInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ class IRGenDebugInfo {
150150
llvm::DILocalVariable *Var, llvm::DIExpression *Expr,
151151
unsigned Line, unsigned Col, llvm::DILocalScope *Scope,
152152
const SILDebugScope *DS, bool InCoroContext = false);
153+
#ifndef NDEBUG
154+
/// Verify that Addr can be processed by llvm's CoroFrame/CoroSplit.
155+
bool verifyCoroutineArgument(llvm::Value *Addr);
156+
#endif
153157

154158
enum { NotHeapAllocated = false };
155159

lib/IRGen/IRGenSIL.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,26 +4360,23 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
43604360
(IsLoadablyByAddress) ? DirectValue : IndirectValue;
43614361
VarInfo->Name = getVarName(i, IsAnonymous);
43624362
auto *Addr = getLoweredAddress(SILVal).getAddress();
4363+
SILType SILTy = SILVal->getType();
4364+
auto RealType = SILTy.getASTType();
43634365
if (CurSILFn->isAsync() && VarInfo->ArgNo) {
4364-
#ifndef NDEBUG
4365-
llvm::Value *Storage = Addr;
4366-
while (Storage) {
4367-
if (auto *LdInst = dyn_cast<llvm::LoadInst>(Storage))
4368-
Storage = LdInst->getOperand(0);
4369-
else if (auto *GEPInst = dyn_cast<llvm::GetElementPtrInst>(Storage))
4370-
Storage = GEPInst->getOperand(0);
4371-
else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
4372-
Storage = BCInst->getOperand(0);
4373-
else
4374-
break;
4375-
}
4376-
assert(llvm::isa<llvm::Argument>(Storage) &&
4377-
"arg expected to be load from inside swift.context");
4378-
#endif
4366+
if (IGM.DebugInfo)
4367+
assert(IGM.DebugInfo->verifyCoroutineArgument(Addr) &&
4368+
"arg expected to be load from inside %swift.context");
43794369
Indirection = CoroIndirectValue;
4370+
if (auto *PBI = dyn_cast<ProjectBoxInst>(i->getOperand())) {
4371+
// Usually debug info only ever describes the *result* of a projectBox
4372+
// call. To allow the debugger to display a boxed parameter of an async
4373+
// continuation object, however, the debug info can only describe the box
4374+
// itself and thus also needs to emit a box type for it so the debugger
4375+
// knows to call into Remote Mirrors to unbox the value.
4376+
RealType = PBI->getOperand()->getType().getASTType();
4377+
assert(isa<SILBoxType>(RealType));
4378+
}
43804379
}
4381-
SILType SILTy = SILVal->getType();
4382-
auto RealType = SILTy.getASTType();
43834380

43844381
auto DbgTy = DebugTypeInfo::getLocalVariable(
43854382
Decl, RealType, getTypeInfo(SILVal->getType()));

test/DebugInfo/async-boxed-arg.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - -parse-as-library \
2+
// RUN: -module-name M -enable-experimental-concurrency | %FileCheck %s
3+
// REQUIRES: concurrency
4+
5+
extension Collection {
6+
public func f() async throws {
7+
return await try Task.withGroup(resultType: Element.self) { group in
8+
var i = self.startIndex
9+
func doit() async throws {
10+
await group.add { [i] in
11+
return self[i]
12+
}
13+
}
14+
await try doit()
15+
}
16+
}
17+
}
18+
19+
// CHECK: ![[BOXTY:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "$s5IndexSlQzz_x_SlRzlXXD"
20+
// CHECK: !DILocalVariable(name: "i", arg: 3, {{.*}}type: ![[BOXTY]]

0 commit comments

Comments
 (0)