Skip to content

Commit 64c0cd3

Browse files
zhuoweikateinoigakukun
authored andcommitted
WebAssembly: add a ton of logging when looking up metadata
Not sure what's going on here: https://gist.github.com/zhuowei/beff646ebc09bed4458421cf7aba210b
1 parent 92d6050 commit 64c0cd3

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,47 @@ _findExtendedTypeContextDescriptor(const ContextDescriptor *maybeExtension,
299299
/// buildContextDescriptorMangling in MetadataReader.
300300
bool swift::_isCImportedTagType(const TypeContextDescriptor *type,
301301
const ParsedTypeIdentity &identity) {
302+
fprintf(stderr, "trying to dump type %p\n", type);
303+
fprintf(stderr, "name: %s\n", type->Name.get());
304+
fprintf(stderr, "trying to dump identity %p\n", &identity);
305+
fprintf(stderr, "User facing name: %s\n", identity.UserFacingName.str().c_str());
306+
fprintf(stderr, "ok, let's go\n");
302307
// Tag types are always imported as structs or enums.
303308
if (type->getKind() != ContextDescriptorKind::Enum &&
304309
type->getKind() != ContextDescriptorKind::Struct)
305310
return false;
306311

312+
fprintf(stderr, "is it a c typedef\n");
313+
307314
// Not a typedef imported as a nominal type.
308315
if (identity.isCTypedef())
309316
return false;
310317

318+
fprintf(stderr, "is related entity\n");
319+
311320
// Not a related entity.
312321
if (identity.isAnyRelatedEntity())
313322
return false;
314323

324+
fprintf(stderr, "is c imported context\n");
325+
fprintf(stderr, "type's parent, raw: %x\n", *((unsigned int*)&type->Parent));
326+
fprintf(stderr, "type's parent: %p\n", type->Parent.get());
327+
// fprintf(stderr, "type's parent name: %s\n", type->Parent->Name.get());
328+
fprintf(stderr, "trying to get module context\n");
329+
330+
for (auto cur = type->Parent.get(); true; cur = cur->Parent.get()) {
331+
fprintf(stderr, "cur %p\n", cur);
332+
fprintf(stderr, "cur %x\n", (unsigned int)cur->getKind());
333+
if (auto module = dyn_cast<ModuleContextDescriptor>(cur)) {
334+
fprintf(stderr, "found\n");
335+
break;
336+
}
337+
}
338+
339+
fprintf(stderr, "type's parent module context: %p\n", type->Parent->getModuleContext());
340+
fprintf(stderr, "trying to get name\n");
341+
fprintf(stderr, "type's parent module context name: %s\n", type->Parent->getModuleContext()->Name.get());
342+
315343
// Imported from C.
316344
return type->Parent->isCImportedContext();
317345
}

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ static const ProtocolConformanceDescriptor *
553553
swift_conformsToSwiftProtocolImpl(const Metadata * const type,
554554
const ProtocolDescriptor *protocol,
555555
StringRef module) {
556+
fprintf(stderr, "in impl2\n");
556557
auto &C = Conformances.get();
557558

558559
// See if we have a cached conformance. The ConcurrentMap data structure
@@ -579,17 +580,25 @@ swift_conformsToSwiftProtocolImpl(const Metadata * const type,
579580
C.cacheFailure(type, protocol, snapshot.count());
580581
return nullptr;
581582
}
582-
583+
fprintf(stderr, "got to really scan\n");
583584
// Really scan conformance records.
584585
for (size_t i = startIndex; i < endIndex; i++) {
586+
fprintf(stderr, "index = %lx\n", (unsigned long)i);
585587
auto &section = snapshot.Start[i];
586588
// Eagerly pull records for nondependent witnesses into our cache.
587589
for (const auto &record : section) {
588-
auto &descriptor = *record.get();
590+
fprintf(stderr, "got a record\n");
591+
auto descriptorPtr = record.get();
592+
auto &descriptor = *descriptorPtr;
593+
fprintf(stderr, "got the descriptor: %p\n", descriptorPtr);
594+
fprintf(stderr, "got the protocol: %p\n", descriptor.getProtocol());
595+
descriptor.getProtocol()->dump();
596+
fprintf(stderr, "got it\n");
589597

590598
// We only care about conformances for this protocol.
591599
if (descriptor.getProtocol() != protocol)
592600
continue;
601+
fprintf(stderr, "about to get matching type\n");
593602

594603
// If there's a matching type, record the positive result.
595604
ConformanceCandidate candidate(descriptor);
@@ -604,6 +613,7 @@ swift_conformsToSwiftProtocolImpl(const Metadata * const type,
604613
}
605614

606615
// Conformance scan is complete.
616+
fprintf(stderr, "about to update cache\n");
607617

608618
// Search the cache once more, and this time update the cache if necessary.
609619
FoundConformance = searchInConformanceCache(type, protocol);
@@ -618,10 +628,18 @@ swift_conformsToSwiftProtocolImpl(const Metadata * const type,
618628
static const WitnessTable *
619629
swift_conformsToProtocolImpl(const Metadata * const type,
620630
const ProtocolDescriptor *protocol) {
631+
// WebAssembly: logging pls
632+
fprintf(stderr, "swift_conformsToProtocolImpl: %p %p\n", type, protocol);
633+
protocol->dump();
634+
fprintf(stderr, "trying to dump the type now\n");
635+
type->dump();
636+
fprintf(stderr, "dumped the type\n");
637+
// end WebAssembly
621638
auto description =
622639
swift_conformsToSwiftProtocol(type, protocol, StringRef());
623640
if (!description)
624641
return nullptr;
642+
description->getProtocol()->dump();
625643

626644
return description->getWitnessTable(
627645
findConformingSuperclass(type, description));

0 commit comments

Comments
 (0)