Skip to content

Commit 2bdabdd

Browse files
committed
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 e2d37d3 commit 2bdabdd

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,47 @@ _findExtendedTypeContextDescriptor(const ExtensionContextDescriptor *extension,
276276
/// buildContextDescriptorMangling in MetadataReader.
277277
bool swift::_isCImportedTagType(const TypeContextDescriptor *type,
278278
const ParsedTypeIdentity &identity) {
279+
fprintf(stderr, "trying to dump type %p\n", type);
280+
fprintf(stderr, "name: %s\n", type->Name.get());
281+
fprintf(stderr, "trying to dump identity %p\n", &identity);
282+
fprintf(stderr, "User facing name: %s\n", identity.UserFacingName.str().c_str());
283+
fprintf(stderr, "ok, let's go\n");
279284
// Tag types are always imported as structs or enums.
280285
if (type->getKind() != ContextDescriptorKind::Enum &&
281286
type->getKind() != ContextDescriptorKind::Struct)
282287
return false;
283288

289+
fprintf(stderr, "is it a c typedef\n");
290+
284291
// Not a typedef imported as a nominal type.
285292
if (identity.isCTypedef())
286293
return false;
287294

295+
fprintf(stderr, "is related entity\n");
296+
288297
// Not a related entity.
289298
if (identity.isAnyRelatedEntity())
290299
return false;
291300

301+
fprintf(stderr, "is c imported context\n");
302+
fprintf(stderr, "type's parent, raw: %x\n", *((unsigned int*)&type->Parent));
303+
fprintf(stderr, "type's parent: %p\n", type->Parent.get());
304+
// fprintf(stderr, "type's parent name: %s\n", type->Parent->Name.get());
305+
fprintf(stderr, "trying to get module context\n");
306+
307+
for (auto cur = type->Parent.get(); true; cur = cur->Parent.get()) {
308+
fprintf(stderr, "cur %p\n", cur);
309+
fprintf(stderr, "cur %x\n", (unsigned int)cur->getKind());
310+
if (auto module = dyn_cast<ModuleContextDescriptor>(cur)) {
311+
fprintf(stderr, "found\n");
312+
break;
313+
}
314+
}
315+
316+
fprintf(stderr, "type's parent module context: %p\n", type->Parent->getModuleContext());
317+
fprintf(stderr, "trying to get name\n");
318+
fprintf(stderr, "type's parent module context name: %s\n", type->Parent->getModuleContext()->Name.get());
319+
292320
// Imported from C.
293321
return type->Parent->isCImportedContext();
294322
}

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ static const ProtocolConformanceDescriptor *
545545
swift_conformsToSwiftProtocolImpl(const Metadata * const type,
546546
const ProtocolDescriptor *protocol,
547547
StringRef module) {
548+
fprintf(stderr, "in impl2\n");
548549
auto &C = Conformances.get();
549550

550551
// See if we have a cached conformance. The ConcurrentMap data structure
@@ -571,17 +572,25 @@ swift_conformsToSwiftProtocolImpl(const Metadata * const type,
571572
C.cacheFailure(type, protocol, snapshot.count());
572573
return nullptr;
573574
}
574-
575+
fprintf(stderr, "got to really scan\n");
575576
// Really scan conformance records.
576577
for (size_t i = startIndex; i < endIndex; i++) {
578+
fprintf(stderr, "index = %lx\n", (unsigned long)i);
577579
auto &section = snapshot.Start[i];
578580
// Eagerly pull records for nondependent witnesses into our cache.
579581
for (const auto &record : section) {
580-
auto &descriptor = *record.get();
582+
fprintf(stderr, "got a record\n");
583+
auto descriptorPtr = record.get();
584+
auto &descriptor = *descriptorPtr;
585+
fprintf(stderr, "got the descriptor: %p\n", descriptorPtr);
586+
fprintf(stderr, "got the protocol: %p\n", descriptor.getProtocol());
587+
descriptor.getProtocol()->dump();
588+
fprintf(stderr, "got it\n");
581589

582590
// We only care about conformances for this protocol.
583591
if (descriptor.getProtocol() != protocol)
584592
continue;
593+
fprintf(stderr, "about to get matching type\n");
585594

586595
// If there's a matching type, record the positive result.
587596
ConformanceCandidate candidate(descriptor);
@@ -596,6 +605,7 @@ swift_conformsToSwiftProtocolImpl(const Metadata * const type,
596605
}
597606

598607
// Conformance scan is complete.
608+
fprintf(stderr, "about to update cache\n");
599609

600610
// Search the cache once more, and this time update the cache if necessary.
601611
FoundConformance = searchInConformanceCache(type, protocol);
@@ -610,12 +620,21 @@ swift_conformsToSwiftProtocolImpl(const Metadata * const type,
610620
static const WitnessTable *
611621
swift_conformsToProtocolImpl(const Metadata * const type,
612622
const ProtocolDescriptor *protocol) {
623+
// WebAssembly: logging pls
624+
fprintf(stderr, "swift_conformsToProtocolImpl: %p %p\n", type, protocol);
625+
protocol->dump();
626+
fprintf(stderr, "trying to dump the type now\n");
627+
type->dump();
628+
fprintf(stderr, "dumped the type\n");
629+
// end WebAssembly
613630
auto description =
614631
swift_conformsToSwiftProtocol(type, protocol, StringRef());
615632
if (!description)
616633
return nullptr;
634+
description->getProtocol()->dump();
617635

618-
return description->getWitnessTable(type);
636+
auto retval = description->getWitnessTable(type);
637+
return retval;
619638
}
620639

621640
const ContextDescriptor *

0 commit comments

Comments
 (0)