Skip to content

Commit de91e3c

Browse files
zhuoweikateinoigakukun
authored andcommitted
WebAssembly: add logging in swift_getAssociatedTypeWitness
1 parent 0918ea1 commit de91e3c

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
@@ -4403,6 +4403,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
44034403
const Metadata *conformingType,
44044404
const ProtocolRequirement *reqBase,
44054405
const ProtocolRequirement *assocType) {
4406+
fprintf(stderr, "Entering slow path: %p %p %p %p\n", wtable, conformingType, reqBase, assocType);
44064407
#ifndef NDEBUG
44074408
{
44084409
const ProtocolConformanceDescriptor *conformance = wtable->Description;
@@ -4429,6 +4430,8 @@ swift_getAssociatedTypeWitnessSlowImpl(
44294430
const char *mangledNameBase =
44304431
(const char *)(uintptr_t(witness) &
44314432
~ProtocolRequirementFlags::AssociatedTypeMangledNameBit);
4433+
fprintf(stderr, "Mangled name base: %p\n", mangledNameBase);
4434+
fprintf(stderr, "name: %s\n", mangledNameBase);
44324435

44334436
// Check whether the mangled name has the prefix byte indicating that
44344437
// the mangled name is relative to the protocol itself.
@@ -4443,13 +4446,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
44434446
const ProtocolConformanceDescriptor *conformance = wtable->Description;
44444447
const ProtocolDescriptor *protocol = conformance->getProtocol();
44454448

4449+
fprintf(stderr, "conformance %p protocol %p\n", conformance, protocol);
4450+
44464451
// Extract the mangled name itself.
44474452
StringRef mangledName =
44484453
Demangle::makeSymbolicMangledNameStringRef(mangledNameBase);
44494454

4455+
fprintf(stderr, "mangledName: %s\n", mangledName.str().c_str());
4456+
44504457
// Demangle the associated type.
44514458
MetadataResponse response;
44524459
if (inProtocolContext) {
4460+
fprintf(stderr, "in protocol context\n");
44534461
// The protocol's Self is the only generic parameter that can occur in the
44544462
// type.
44554463
response =
@@ -4472,6 +4480,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
44724480
dependentDescriptor);
44734481
}).getResponse();
44744482
} else {
4483+
fprintf(stderr, "getting original conforming type\n");
44754484
// The generic parameters in the associated type name are those of the
44764485
// conforming type.
44774486

@@ -4490,6 +4499,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
44904499
}).getResponse();
44914500
}
44924501
auto assocTypeMetadata = response.Value;
4502+
fprintf(stderr, "assocTypeMetadata: %p\n", assocTypeMetadata);
4503+
4504+
if (true) {
4505+
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
4506+
StringRef conformingTypeName(conformingTypeNameInfo.data,
4507+
conformingTypeNameInfo.length);
4508+
StringRef assocTypeName = findAssociatedTypeName(protocol, assocType);
4509+
fprintf(stderr, "fin: %s %s %s %s\n", assocTypeName.str().c_str(),
4510+
conformingTypeName.str().c_str(),
4511+
protocol->Name.get(),
4512+
mangledName.str().c_str());
4513+
}
44934514

44944515
if (!assocTypeMetadata) {
44954516
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
@@ -4525,9 +4546,20 @@ swift::swift_getAssociatedTypeWitness(MetadataRequest request,
45254546
// If the low bit of the witness is clear, it's already a metadata pointer.
45264547
unsigned witnessIndex = assocType - reqBase;
45274548
auto witness = ((const void* const *)wtable)[witnessIndex];
4549+
fprintf(stderr, "getAssociatedTypeWitness fastpath: %x %p\n", witnessIndex, witness);
45284550
if (LLVM_LIKELY((uintptr_t(witness) &
45294551
ProtocolRequirementFlags::AssociatedTypeMangledNameBit) == 0)) {
45304552
// Cached metadata pointers are always complete.
4553+
fprintf(stderr, "fastpath: %p\n", witness);
4554+
auto witnessPtr = (const Metadata *)witness;
4555+
witnessPtr->dump();
4556+
if (witnessPtr->getKind() == MetadataKind::Class) {
4557+
fprintf(stderr, "class description:\n");
4558+
auto witnessClass = witnessPtr->getClassObject();
4559+
fprintf(stderr, "%lx\n", *(unsigned long*)&witnessClass->Data);
4560+
if (witnessClass->isTypeMetadata())
4561+
fprintf(stderr, "name: %s\n", witnessClass->getDescription()->Name.get());
4562+
}
45314563
return MetadataResponse{(const Metadata *)witness, MetadataState::Complete};
45324564
}
45334565

0 commit comments

Comments
 (0)