Skip to content

Commit 6c7047a

Browse files
zhuoweikateinoigakukun
authored andcommitted
WebAssembly: add logging in swift_getAssociatedTypeWitness
1 parent 0a04e7a commit 6c7047a

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
@@ -4350,6 +4350,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
43504350
const Metadata *conformingType,
43514351
const ProtocolRequirement *reqBase,
43524352
const ProtocolRequirement *assocType) {
4353+
fprintf(stderr, "Entering slow path: %p %p %p %p\n", wtable, conformingType, reqBase, assocType);
43534354
#ifndef NDEBUG
43544355
{
43554356
const ProtocolConformanceDescriptor *conformance = wtable->Description;
@@ -4376,6 +4377,8 @@ swift_getAssociatedTypeWitnessSlowImpl(
43764377
const char *mangledNameBase =
43774378
(const char *)(uintptr_t(witness) &
43784379
~ProtocolRequirementFlags::AssociatedTypeMangledNameBit);
4380+
fprintf(stderr, "Mangled name base: %p\n", mangledNameBase);
4381+
fprintf(stderr, "name: %s\n", mangledNameBase);
43794382

43804383
// Check whether the mangled name has the prefix byte indicating that
43814384
// the mangled name is relative to the protocol itself.
@@ -4390,13 +4393,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
43904393
const ProtocolConformanceDescriptor *conformance = wtable->Description;
43914394
const ProtocolDescriptor *protocol = conformance->getProtocol();
43924395

4396+
fprintf(stderr, "conformance %p protocol %p\n", conformance, protocol);
4397+
43934398
// Extract the mangled name itself.
43944399
StringRef mangledName =
43954400
Demangle::makeSymbolicMangledNameStringRef(mangledNameBase);
43964401

4402+
fprintf(stderr, "mangledName: %s\n", mangledName.str().c_str());
4403+
43974404
// Demangle the associated type.
43984405
MetadataResponse response;
43994406
if (inProtocolContext) {
4407+
fprintf(stderr, "in protocol context\n");
44004408
// The protocol's Self is the only generic parameter that can occur in the
44014409
// type.
44024410
response =
@@ -4419,6 +4427,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
44194427
dependentDescriptor);
44204428
}).getResponse();
44214429
} else {
4430+
fprintf(stderr, "getting original conforming type\n");
44224431
// The generic parameters in the associated type name are those of the
44234432
// conforming type.
44244433

@@ -4437,6 +4446,18 @@ swift_getAssociatedTypeWitnessSlowImpl(
44374446
}).getResponse();
44384447
}
44394448
auto assocTypeMetadata = response.Value;
4449+
fprintf(stderr, "assocTypeMetadata: %p\n", assocTypeMetadata);
4450+
4451+
if (true) {
4452+
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
4453+
StringRef conformingTypeName(conformingTypeNameInfo.data,
4454+
conformingTypeNameInfo.length);
4455+
StringRef assocTypeName = findAssociatedTypeName(protocol, assocType);
4456+
fprintf(stderr, "fin: %s %s %s %s\n", assocTypeName.str().c_str(),
4457+
conformingTypeName.str().c_str(),
4458+
protocol->Name.get(),
4459+
mangledName.str().c_str());
4460+
}
44404461

44414462
if (!assocTypeMetadata) {
44424463
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
@@ -4472,9 +4493,20 @@ swift::swift_getAssociatedTypeWitness(MetadataRequest request,
44724493
// If the low bit of the witness is clear, it's already a metadata pointer.
44734494
unsigned witnessIndex = assocType - reqBase;
44744495
auto witness = ((const void* const *)wtable)[witnessIndex];
4496+
fprintf(stderr, "getAssociatedTypeWitness fastpath: %x %p\n", witnessIndex, witness);
44754497
if (LLVM_LIKELY((uintptr_t(witness) &
44764498
ProtocolRequirementFlags::AssociatedTypeMangledNameBit) == 0)) {
44774499
// Cached metadata pointers are always complete.
4500+
fprintf(stderr, "fastpath: %p\n", witness);
4501+
auto witnessPtr = (const Metadata *)witness;
4502+
witnessPtr->dump();
4503+
if (witnessPtr->getKind() == MetadataKind::Class) {
4504+
fprintf(stderr, "class description:\n");
4505+
auto witnessClass = witnessPtr->getClassObject();
4506+
fprintf(stderr, "%lx\n", *(unsigned long*)&witnessClass->Data);
4507+
if (witnessClass->isTypeMetadata())
4508+
fprintf(stderr, "name: %s\n", witnessClass->getDescription()->Name.get());
4509+
}
44784510
return MetadataResponse{(const Metadata *)witness, MetadataState::Complete};
44794511
}
44804512

0 commit comments

Comments
 (0)