Skip to content

Commit 69c25f6

Browse files
committed
WebAssembly: add logging in swift_getAssociatedTypeWitness
1 parent 6ff2890 commit 69c25f6

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
@@ -4277,6 +4277,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
42774277
const Metadata *conformingType,
42784278
const ProtocolRequirement *reqBase,
42794279
const ProtocolRequirement *assocType) {
4280+
fprintf(stderr, "Entering slow path: %p %p %p %p\n", wtable, conformingType, reqBase, assocType);
42804281
#ifndef NDEBUG
42814282
{
42824283
const ProtocolConformanceDescriptor *conformance = wtable->Description;
@@ -4303,6 +4304,8 @@ swift_getAssociatedTypeWitnessSlowImpl(
43034304
const char *mangledNameBase =
43044305
(const char *)(uintptr_t(witness) &
43054306
~ProtocolRequirementFlags::AssociatedTypeMangledNameBit);
4307+
fprintf(stderr, "Mangled name base: %p\n", mangledNameBase);
4308+
fprintf(stderr, "name: %s\n", mangledNameBase);
43064309

43074310
// Check whether the mangled name has the prefix byte indicating that
43084311
// the mangled name is relative to the protocol itself.
@@ -4317,13 +4320,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
43174320
const ProtocolConformanceDescriptor *conformance = wtable->Description;
43184321
const ProtocolDescriptor *protocol = conformance->getProtocol();
43194322

4323+
fprintf(stderr, "conformance %p protocol %p\n", conformance, protocol);
4324+
43204325
// Extract the mangled name itself.
43214326
StringRef mangledName =
43224327
Demangle::makeSymbolicMangledNameStringRef(mangledNameBase);
43234328

4329+
fprintf(stderr, "mangledName: %s\n", mangledName.str().c_str());
4330+
43244331
// Demangle the associated type.
43254332
MetadataResponse response;
43264333
if (inProtocolContext) {
4334+
fprintf(stderr, "in protocol context\n");
43274335
// The protocol's Self is the only generic parameter that can occur in the
43284336
// type.
43294337
response =
@@ -4346,6 +4354,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
43464354
dependentDescriptor);
43474355
}).getResponse();
43484356
} else {
4357+
fprintf(stderr, "getting original conforming type\n");
43494358
// The generic parameters in the associated type name are those of the
43504359
// conforming type.
43514360

@@ -4364,6 +4373,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
43644373
}).getResponse();
43654374
}
43664375
auto assocTypeMetadata = response.Value;
4376+
fprintf(stderr, "assocTypeMetadata: %p\n", assocTypeMetadata);
4377+
4378+
if (true) {
4379+
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
4380+
StringRef conformingTypeName(conformingTypeNameInfo.data,
4381+
conformingTypeNameInfo.length);
4382+
StringRef assocTypeName = findAssociatedTypeName(protocol, assocType);
4383+
fprintf(stderr, "fin: %s %s %s %s\n", assocTypeName.str().c_str(),
4384+
conformingTypeName.str().c_str(),
4385+
protocol->Name.get(),
4386+
mangledName.str().c_str());
4387+
}
43674388

43684389
if (!assocTypeMetadata) {
43694390
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
@@ -4399,9 +4420,20 @@ swift::swift_getAssociatedTypeWitness(MetadataRequest request,
43994420
// If the low bit of the witness is clear, it's already a metadata pointer.
44004421
unsigned witnessIndex = assocType - reqBase;
44014422
auto witness = ((const void* const *)wtable)[witnessIndex];
4423+
fprintf(stderr, "getAssociatedTypeWitness fastpath: %x %p\n", witnessIndex, witness);
44024424
if (LLVM_LIKELY((uintptr_t(witness) &
44034425
ProtocolRequirementFlags::AssociatedTypeMangledNameBit) == 0)) {
44044426
// Cached metadata pointers are always complete.
4427+
fprintf(stderr, "fastpath: %p\n", witness);
4428+
auto witnessPtr = (const Metadata *)witness;
4429+
witnessPtr->dump();
4430+
if (witnessPtr->getKind() == MetadataKind::Class) {
4431+
fprintf(stderr, "class description:\n");
4432+
auto witnessClass = witnessPtr->getClassObject();
4433+
fprintf(stderr, "%lx\n", *(unsigned long*)&witnessClass->Data);
4434+
if (witnessClass->isTypeMetadata())
4435+
fprintf(stderr, "name: %s\n", witnessClass->getDescription()->Name.get());
4436+
}
44054437
return MetadataResponse{(const Metadata *)witness, MetadataState::Complete};
44064438
}
44074439

0 commit comments

Comments
 (0)