Skip to content

Commit 680fbc5

Browse files
committed
Revert "Merge pull request swiftlang#79171 from augusto2112/debug-info-witness-table"
This reverts commit c8eba86, reversing changes made to 98c3993.
1 parent c8eba86 commit 680fbc5

16 files changed

+104
-251
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7364,10 +7364,7 @@ class GenericTypeParamType : public SubstitutableType,
73647364

73657365
/// Get the name of the generic type parameter.
73667366
Identifier getName() const;
7367-
7368-
/// Get the canonical <tau>_n_n name;
7369-
Identifier getCanonicalName() const;
7370-
7367+
73717368
/// The depth of this generic type parameter, i.e., the number of outer
73727369
/// levels of generic parameter lists that enclose this type parameter.
73737370
///

lib/AST/Type.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,10 +2176,8 @@ Identifier GenericTypeParamType::getName() const {
21762176
if (!isCanonical())
21772177
return Name;
21782178

2179-
return getCanonicalName();
2180-
}
2179+
// Otherwise, we're canonical. Produce an anonymous '<tau>_n_n' name.
21812180

2182-
Identifier GenericTypeParamType::getCanonicalName() const {
21832181
// getASTContext() doesn't actually mutate an already-canonical type.
21842182
auto &C = const_cast<GenericTypeParamType*>(this)->getASTContext();
21852183
auto &names = C.CanonicalGenericTypeParamTypeNames;

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
279279
DebugTypeInfo DebugType,
280280
bool IsLocalToUnit,
281281
std::optional<SILLocation> Loc);
282-
283-
void emitArtificialVariable(IRGenFunction &IGF, llvm::Value *Metadata,
284-
StringRef Name, StringRef Identifier);
285-
286282
void emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,
287-
GenericTypeParamType *Type);
288-
289-
void emitWitnessTable(IRGenFunction &IGF, llvm::Value *Metadata,
290-
StringRef Name, ProtocolDecl *protocol);
291-
283+
unsigned Depth, unsigned Index, StringRef Name);
292284
void emitPackCountParameter(IRGenFunction &IGF, llvm::Value *Metadata,
293285
SILDebugVariable VarInfo);
294286

@@ -3912,10 +3904,9 @@ void IRGenDebugInfoImpl::emitGlobalVariableDeclaration(
39123904
Var->addDebugInfo(GV);
39133905
}
39143906

3915-
void IRGenDebugInfoImpl::emitArtificialVariable(IRGenFunction &IGF,
3916-
llvm::Value *Metadata,
3917-
StringRef Name,
3918-
StringRef Identifier) {
3907+
void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
3908+
llvm::Value *Metadata, unsigned Depth,
3909+
unsigned Index, StringRef Name) {
39193910
if (Opts.DebugInfoLevel <= IRGenDebugInfoLevel::LineTables)
39203911
return;
39213912

@@ -3924,44 +3915,23 @@ void IRGenDebugInfoImpl::emitArtificialVariable(IRGenFunction &IGF,
39243915
if (!DS || DS->getInlinedFunction()->isTransparent())
39253916
return;
39263917

3927-
uint64_t PtrWidthInBits =
3928-
CI.getTargetInfo().getPointerWidth(clang::LangAS::Default);
3918+
llvm::SmallString<8> Buf;
3919+
static const char *Tau = SWIFT_UTF8("\u03C4");
3920+
llvm::raw_svector_ostream OS(Buf);
3921+
OS << '$' << Tau << '_' << Depth << '_' << Index;
3922+
uint64_t PtrWidthInBits = CI.getTargetInfo().getPointerWidth(clang::LangAS::Default);
39293923
assert(PtrWidthInBits % 8 == 0);
39303924
auto DbgTy = DebugTypeInfo::getTypeMetadata(
39313925
getMetadataType(Name)->getDeclaredInterfaceType().getPointer(),
39323926
Size(PtrWidthInBits / 8),
39333927
Alignment(CI.getTargetInfo().getPointerAlign(clang::LangAS::Default)));
3934-
emitVariableDeclaration(
3935-
IGF.Builder, Metadata, DbgTy, IGF.getDebugScope(), {},
3936-
{Identifier, 0, false}, // swift.type is already a pointer type,
3937-
// having a shadow copy doesn't add another
3938-
// layer of indirection.
3939-
IGF.isAsync() ? CoroDirectValue : DirectValue, ArtificialValue);
3940-
}
3941-
3942-
void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
3943-
llvm::Value *Metadata,
3944-
GenericTypeParamType *Type) {
3945-
llvm::SmallString<8> Buf;
3946-
llvm::raw_svector_ostream OS(Buf);
3947-
OS << "$" << Type->getCanonicalName().str();
3948-
auto Name = Type->getName().str();
3949-
3950-
emitArtificialVariable(IGF, Metadata, Name, OS.str());
3951-
}
3952-
3953-
void IRGenDebugInfoImpl::emitWitnessTable(IRGenFunction &IGF,
3954-
llvm::Value *Metadata, StringRef Name,
3955-
ProtocolDecl *protocol) {
3956-
llvm::SmallString<32> Buf;
3957-
llvm::raw_svector_ostream OS(Buf);
3958-
DebugTypeInfo DbgTy(protocol->getDeclaredType());
3959-
auto MangledName = getMangledName(DbgTy).Canonical;
3960-
OS << "$WT" << Name << "$$" << MangledName;;
3961-
// Make sure this ID lives long enough.
3962-
auto Id = IGF.getSwiftModule()->getASTContext().getIdentifier(OS.str());
3963-
3964-
emitArtificialVariable(IGF, Metadata, Name, Id.str());
3928+
emitVariableDeclaration(IGF.Builder, Metadata, DbgTy, IGF.getDebugScope(),
3929+
{}, {OS.str().str(), 0, false},
3930+
// swift.type is already a pointer type,
3931+
// having a shadow copy doesn't add another
3932+
// layer of indirection.
3933+
IGF.isAsync() ? CoroDirectValue : DirectValue,
3934+
ArtificialValue);
39653935
}
39663936

39673937
void IRGenDebugInfoImpl::emitPackCountParameter(IRGenFunction &IGF,
@@ -4100,15 +4070,10 @@ void IRGenDebugInfo::emitGlobalVariableDeclaration(
41004070
}
41014071

41024072
void IRGenDebugInfo::emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,
4103-
GenericTypeParamType *Type) {
4073+
unsigned Depth, unsigned Index,
4074+
StringRef Name) {
41044075
static_cast<IRGenDebugInfoImpl *>(this)->emitTypeMetadata(IGF, Metadata,
4105-
Type);
4106-
}
4107-
4108-
void IRGenDebugInfo::emitWitnessTable(IRGenFunction &IGF, llvm::Value *Metadata,
4109-
StringRef Name, ProtocolDecl *protocol) {
4110-
static_cast<IRGenDebugInfoImpl *>(this)->emitWitnessTable(IGF, Metadata, Name,
4111-
protocol);
4076+
Depth, Index, Name);
41124077
}
41134078

41144079
void IRGenDebugInfo::emitPackCountParameter(IRGenFunction &IGF,

lib/IRGen/IRGenDebugInfo.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,7 @@ class IRGenDebugInfo {
186186

187187
/// Emit debug metadata for type metadata (for generic types). So meta.
188188
void emitTypeMetadata(IRGenFunction &IGF, llvm::Value *Metadata,
189-
GenericTypeParamType *Type);
190-
191-
/// Emit debug metadata for a (protocol) witness table.
192-
void emitWitnessTable(IRGenFunction &IGF, llvm::Value *Metadata,
193-
StringRef Name, ProtocolDecl *protocol);
189+
unsigned Depth, unsigned Index, StringRef Name);
194190

195191
/// Emit debug info for the IR function parameter holding the size of one or
196192
/// more parameter / type packs.

lib/IRGen/IRGenSIL.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,42 +1163,8 @@ class IRGenSILFunction :
11631163
emitPackCountDebugVariable(Shape);
11641164
}
11651165
});
1166-
1167-
if (auto *BGT = llvm::dyn_cast<BoundGenericType>(Ty)) {
1168-
auto Decl = BGT->getDecl();
1169-
auto GE = Decl->getGenericEnvironment();
1170-
auto Requirements = BGT->getDecl()
1171-
->getGenericEnvironment()
1172-
->getGenericSignature()
1173-
.getRequirements();
1174-
for (auto Requirement : Requirements) {
1175-
if (Requirement.getKind() == RequirementKind::Conformance) {
1176-
auto ProtocolDecl = Requirement.getProtocolDecl();
1177-
auto ConformingType = Requirement.getFirstType();
1178-
Type Archetype;
1179-
if (auto GTPT = llvm::dyn_cast<GenericTypeParamType>(
1180-
ConformingType.getPointer()))
1181-
Archetype = GE->mapTypeIntoContext(GTPT);
1182-
else if (auto DMT = llvm::dyn_cast<DependentMemberType>(
1183-
ConformingType.getPointer()))
1184-
Archetype = GE->mapTypeIntoContext(DMT);
1185-
1186-
if (Lowering::TypeConverter::protocolRequiresWitnessTable(
1187-
ProtocolDecl) &&
1188-
tryGetLocalTypeData(
1189-
Archetype->getCanonicalType(),
1190-
LocalTypeDataKind::forAbstractProtocolWitnessTable(
1191-
ProtocolDecl))) {
1192-
auto Conformance =
1193-
ProtocolConformanceRef::forAbstract(Archetype, ProtocolDecl);
1194-
1195-
emitWitnessTableRef(*this, Archetype->getCanonicalType(),
1196-
Conformance);
1197-
}
1198-
}
1199-
}
1200-
}
12011166
}
1167+
12021168
/// Emit debug info for a function argument or a local variable.
12031169
template <typename StorageType>
12041170
void emitDebugVariableDeclaration(

lib/IRGen/LocalTypeData.cpp

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -408,59 +408,26 @@ static void maybeEmitDebugInfoForLocalTypeData(IRGenFunction &IGF,
408408
// functions that were inlined into transparent functions. Correct would be to
409409
// check which instruction requests the type metadata and see whether its
410410
// inlined function is transparent.
411-
auto *DS = IGF.getDebugScope();
411+
auto * DS = IGF.getDebugScope();
412412
if (DS && DS->getInlinedFunction() &&
413413
DS->getInlinedFunction()->isTransparent())
414414
return;
415-
// For formal type metadata and witness tables.
416-
ProtocolDecl *proto = nullptr;
417-
418-
if (key.Kind.isAbstractProtocolConformance())
419-
proto = key.Kind.getAbstractProtocolConformance();
420-
else if (key.Kind.isConcreteProtocolConformance())
421-
proto = key.Kind.getConcreteProtocolConformance()->getProtocol();
422-
else if (key.Kind != LocalTypeDataKind::forFormalTypeMetadata())
415+
416+
// Only for formal type metadata.
417+
if (key.Kind != LocalTypeDataKind::forFormalTypeMetadata())
423418
return;
424419

425420
// Only for archetypes, and not for opened/opaque archetypes.
426421
auto type = dyn_cast<ArchetypeType>(key.Type);
427422
if (!type)
428423
return;
429-
if (!type->isRoot() && !proto)
424+
if (!type->isRoot())
430425
return;
431426
if (!isa<PrimaryArchetypeType>(type) && !isa<PackArchetypeType>(type))
432427
return;
433428

434-
auto interfaceType = type->getInterfaceType();
435-
llvm::SmallString<16> name;
436-
llvm::SmallString<16> displayName;
437-
if (auto DMT =
438-
llvm::dyn_cast<DependentMemberType>(interfaceType.getPointer())) {
439-
std::function<void(DependentMemberType *)> visitDependentMembers =
440-
[&](DependentMemberType *member) {
441-
if (member == nullptr)
442-
return;
443-
if (auto *parent =
444-
llvm::dyn_cast<DependentMemberType>(member->getBase())) {
445-
visitDependentMembers(parent);
446-
name.append("$");
447-
displayName.append(".");
448-
}
449-
name.append(member->getName().str());
450-
displayName.append(member->getName().str());
451-
};
452-
name.append(DMT->getRootGenericParam()->getCanonicalName().str());
453-
name.append("$");
454-
displayName.append(DMT->getRootGenericParam()->getName().str());
455-
displayName.append(".");
456-
visitDependentMembers(DMT);
457-
} else if (auto GTPT = llvm::dyn_cast<GenericTypeParamType>(
458-
interfaceType.getPointer())) {
459-
name = GTPT->getCanonicalName().str();
460-
displayName = GTPT->getName().str();
461-
} else {
462-
return;
463-
}
429+
auto *typeParam = type->getInterfaceType()->castTo<GenericTypeParamType>();
430+
auto name = typeParam->getName().str();
464431

465432
llvm::Value *data = value.getMetadata();
466433

@@ -471,7 +438,7 @@ static void maybeEmitDebugInfoForLocalTypeData(IRGenFunction &IGF,
471438
// though; see the comment in IRGenFunctionSIL::emitShadowCopyIfNeeded().
472439
if (!IGF.IGM.IRGen.Opts.shouldOptimize() && !IGF.isAsync()) {
473440
auto alloca =
474-
IGF.createAlloca(data->getType(), IGF.IGM.getPointerAlignment(), displayName);
441+
IGF.createAlloca(data->getType(), IGF.IGM.getPointerAlignment(), name);
475442
IGF.Builder.CreateStore(data, alloca);
476443
data = alloca.getAddress();
477444
}
@@ -480,12 +447,10 @@ static void maybeEmitDebugInfoForLocalTypeData(IRGenFunction &IGF,
480447
if (!IGF.IGM.DebugInfo)
481448
return;
482449

483-
if (proto) {
484-
IGF.IGM.DebugInfo->emitWitnessTable(IGF, data, name, proto);
485-
} else {
486-
auto *typeParam = type->getInterfaceType()->castTo<GenericTypeParamType>();
487-
IGF.IGM.DebugInfo->emitTypeMetadata(IGF, data, typeParam);
488-
}
450+
IGF.IGM.DebugInfo->emitTypeMetadata(IGF, data,
451+
typeParam->getDepth(),
452+
typeParam->getIndex(),
453+
name);
489454
}
490455

491456
void

test/DebugInfo/move_function_dbginfo.swift

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,19 @@ public func copyableVarArgTest(_ k: inout Klass) {
237237
// DWARF-NEXT: DW_AT_artificial (true)
238238
//
239239
// DWARF: DW_TAG_variable
240-
// DWARF: DW_AT_location
241-
// DWARF: DW_AT_name ("$WT\317\204_0_0$$$s3out1P_pD")
242-
// DWARF: DW_AT_type (
243-
// DWARF: DW_AT_artificial (true)
244-
//
245-
// DWARF: DW_TAG_variable
246240
// DWARF-NEXT: DW_AT_location (0x{{[a-z0-9]+}}:
247241
// DWARF-NEXT: [0x{{[a-z0-9]+}}, 0x{{[a-z0-9]+}}):
248242
// DWARF-NEXT: DW_AT_name ("k")
249243
// DWARF-NEXT: DW_AT_decl_file (
250244
// DWARF-NEXT: DW_AT_decl_line (
251245
// DWARF-NEXT: DW_AT_type (
252246
//
247+
// DWARF: DW_TAG_variable
248+
// DWARF-NEXT: DW_AT_location (
249+
// DWARF-NEXT: DW_AT_name ("m")
250+
// DWARF-NEXT: DW_AT_decl_file (
251+
// DWARF-NEXT: DW_AT_decl_line (
252+
// DWARF-NEXT: DW_AT_type (
253253
public func addressOnlyValueTest<T : P>(_ x: T) {
254254
let k = x
255255
k.doSomething()
@@ -265,6 +265,33 @@ public func addressOnlyValueTest<T : P>(_ x: T) {
265265
// CHECK: ret void
266266
// CHECK-NEXT: }
267267
//
268+
// DWARF: DW_AT_linkage_name ("$s3out23addressOnlyValueArgTestyyxnAA1PRzlF")
269+
// DWARF-NEXT: DW_AT_name ("addressOnlyValueArgTest")
270+
// DWARF-NEXT: DW_AT_decl_file (
271+
// DWARF-NEXT: DW_AT_decl_line (
272+
// DWARF-NEXT: DW_AT_type (
273+
// DWARF-NEXT: DW_AT_external (
274+
//
275+
// DWARF: DW_TAG_formal_parameter
276+
// DWARF-NEXT: DW_AT_location (0x{{[a-z0-9]+}}:
277+
// DWARF-NEXT: [0x{{[a-z0-9]+}}, 0x{{[a-z0-9]+}}):
278+
// DWARF-NEXT: DW_AT_name ("k")
279+
// DWARF-NEXT: DW_AT_decl_file (
280+
// DWARF-NEXT: DW_AT_decl_line (
281+
// DWARF-NEXT: DW_AT_type (
282+
//
283+
// DWARF: DW_TAG_variable
284+
// DWARF-NEXT: DW_AT_location (
285+
// DWARF-NEXT: DW_AT_name ("$\317\204_0_0")
286+
// DWARF-NEXT: DW_AT_type (
287+
// DWARF-NEXT: DW_AT_artificial (true)
288+
//
289+
// DWARF: DW_TAG_variable
290+
// DWARF-NEXT: DW_AT_location (
291+
// DWARF-NEXT: DW_AT_name ("m")
292+
// DWARF-NEXT: DW_AT_decl_file (
293+
// DWARF-NEXT: DW_AT_decl_line (
294+
// DWARF-NEXT: DW_AT_type (
268295
public func addressOnlyValueArgTest<T : P>(_ k: __owned T) {
269296
k.doSomething()
270297
let m = consume k
@@ -279,6 +306,35 @@ public func addressOnlyValueArgTest<T : P>(_ k: __owned T) {
279306
// CHECK: ret void
280307
// CHECK-NEXT: }
281308
//
309+
// DWARF: DW_AT_linkage_name ("$s3out18addressOnlyVarTestyyxAA1PRzlF")
310+
// DWARF-NEXT: DW_AT_name ("addressOnlyVarTest")
311+
// DWARF-NEXT: DW_AT_decl_file (
312+
// DWARF-NEXT: DW_AT_decl_line (
313+
// DWARF-NEXT: DW_AT_type (
314+
// DWARF-NEXT: DW_AT_external (
315+
//
316+
// DWARF: DW_TAG_formal_parameter
317+
// DWARF-NEXT: DW_AT_location (
318+
// DWARF-NEXT: DW_AT_name ("x")
319+
// DWARF-NEXT: DW_AT_decl_file (
320+
// DWARF-NEXT: DW_AT_decl_line (
321+
// DWARF-NEXT: DW_AT_type (
322+
//
323+
// DWARF: DW_TAG_variable
324+
// DWARF-NEXT: DW_AT_location (
325+
// DWARF-NEXT: DW_AT_name ("$\317\204_0_0")
326+
// DWARF-NEXT: DW_AT_type (
327+
// DWARF-NEXT: DW_AT_artificial (true)
328+
//
329+
// DWARF: DW_TAG_variable
330+
// DWARF-NEXT: DW_AT_location (0x{{[a-z0-9]+}}:
331+
// DWARF-NEXT: [0x{{[a-z0-9]+}}, 0x{{[a-z0-9]+}}):
332+
// TODO: Missing def in dbg info here.
333+
// DWARF-NEXT: [0x{{[a-z0-9]+}}, 0x{{[a-z0-9]+}}):
334+
// DWARF-NEXT: DW_AT_name ("k")
335+
// DWARF-NEXT: DW_AT_decl_file (
336+
// DWARF-NEXT: DW_AT_decl_line (
337+
// DWARF-NEXT: DW_AT_type (
282338
public func addressOnlyVarTest<T : P>(_ x: T) {
283339
var k = x // << this
284340
k.doSomething()

0 commit comments

Comments
 (0)