Skip to content

Commit dd54892

Browse files
committed
WebAssembly: add logging in swift_getAssociatedTypeWitness
1 parent d58328c commit dd54892

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,6 +4266,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
42664266
const Metadata *conformingType,
42674267
const ProtocolRequirement *reqBase,
42684268
const ProtocolRequirement *assocType) {
4269+
fprintf(stderr, "Entering slow path: %p %p %p %p\n", wtable, conformingType, reqBase, assocType);
42694270
#ifndef NDEBUG
42704271
{
42714272
const ProtocolConformanceDescriptor *conformance = wtable->Description;
@@ -4292,6 +4293,8 @@ swift_getAssociatedTypeWitnessSlowImpl(
42924293
const char *mangledNameBase =
42934294
(const char *)(uintptr_t(witness) &
42944295
~ProtocolRequirementFlags::AssociatedTypeMangledNameBit);
4296+
fprintf(stderr, "Mangled name base: %p\n", mangledNameBase);
4297+
fprintf(stderr, "name: %s\n", mangledNameBase);
42954298

42964299
// Check whether the mangled name has the prefix byte indicating that
42974300
// the mangled name is relative to the protocol itself.
@@ -4306,13 +4309,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
43064309
const ProtocolConformanceDescriptor *conformance = wtable->Description;
43074310
const ProtocolDescriptor *protocol = conformance->getProtocol();
43084311

4312+
fprintf(stderr, "conformance %p protocol %p\n", conformance, protocol);
4313+
43094314
// Extract the mangled name itself.
43104315
StringRef mangledName =
43114316
Demangle::makeSymbolicMangledNameStringRef(mangledNameBase);
43124317

4318+
fprintf(stderr, "mangledName: %s\n", mangledName.str().c_str());
4319+
43134320
// Demangle the associated type.
43144321
MetadataResponse response;
43154322
if (inProtocolContext) {
4323+
fprintf(stderr, "in protocol context\n");
43164324
// The protocol's Self is the only generic parameter that can occur in the
43174325
// type.
43184326
response =
@@ -4335,6 +4343,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
43354343
dependentDescriptor);
43364344
}).getResponse();
43374345
} else {
4346+
fprintf(stderr, "getting original conforming type\n");
43384347
// The generic parameters in the associated type name are those of the
43394348
// conforming type.
43404349

@@ -4353,6 +4362,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
43534362
}).getResponse();
43544363
}
43554364
auto assocTypeMetadata = response.Value;
4365+
fprintf(stderr, "assocTypeMetadata: %p\n", assocTypeMetadata);
4366+
4367+
if (true) {
4368+
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
4369+
StringRef conformingTypeName(conformingTypeNameInfo.data,
4370+
conformingTypeNameInfo.length);
4371+
StringRef assocTypeName = findAssociatedTypeName(protocol, assocType);
4372+
fprintf(stderr, "fin: %s %s %s %s\n", assocTypeName.str().c_str(),
4373+
conformingTypeName.str().c_str(),
4374+
protocol->Name.get(),
4375+
mangledName.str().c_str());
4376+
}
43564377

43574378
if (!assocTypeMetadata) {
43584379
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
@@ -4388,9 +4409,20 @@ swift::swift_getAssociatedTypeWitness(MetadataRequest request,
43884409
// If the low bit of the witness is clear, it's already a metadata pointer.
43894410
unsigned witnessIndex = assocType - reqBase;
43904411
auto witness = ((const void* const *)wtable)[witnessIndex];
4412+
fprintf(stderr, "getAssociatedTypeWitness fastpath: %x %p\n", witnessIndex, witness);
43914413
if (LLVM_LIKELY((uintptr_t(witness) &
43924414
ProtocolRequirementFlags::AssociatedTypeMangledNameBit) == 0)) {
43934415
// Cached metadata pointers are always complete.
4416+
fprintf(stderr, "fastpath: %p\n", witness);
4417+
auto witnessPtr = (const Metadata *)witness;
4418+
witnessPtr->dump();
4419+
if (witnessPtr->getKind() == MetadataKind::Class) {
4420+
fprintf(stderr, "class description:\n");
4421+
auto witnessClass = witnessPtr->getClassObject();
4422+
fprintf(stderr, "%lx\n", *(unsigned long*)&witnessClass->Data);
4423+
if (witnessClass->isTypeMetadata())
4424+
fprintf(stderr, "name: %s\n", witnessClass->getDescription()->Name.get());
4425+
}
43944426
return MetadataResponse{(const Metadata *)witness, MetadataState::Complete};
43954427
}
43964428

0 commit comments

Comments
 (0)