mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add error reporting when looking up types by demangled name.
This commit is contained in:
@@ -2916,24 +2916,22 @@ getSuperclassMetadata(MetadataRequest request, const ClassMetadata *self) {
|
||||
StringRef superclassName =
|
||||
Demangle::makeSymbolicMangledNameStringRef(superclassNameBase);
|
||||
SubstGenericParametersFromMetadata substitutions(self);
|
||||
MetadataResponse response =
|
||||
swift_getTypeByMangledName(request, superclassName,
|
||||
substitutions.getGenericArgs(),
|
||||
auto result = swift_getTypeByMangledName(
|
||||
request, superclassName, substitutions.getGenericArgs(),
|
||||
[&substitutions](unsigned depth, unsigned index) {
|
||||
return substitutions.getMetadata(depth, index);
|
||||
},
|
||||
[&substitutions](const Metadata *type, unsigned index) {
|
||||
return substitutions.getWitnessTable(type, index);
|
||||
}).getResponse();
|
||||
auto superclass = response.Value;
|
||||
if (!superclass) {
|
||||
fatalError(0,
|
||||
"failed to demangle superclass of %s from mangled name '%s'\n",
|
||||
self->getDescription()->Name.get(),
|
||||
superclassName.str().c_str());
|
||||
});
|
||||
if (auto *error = result.getError()) {
|
||||
fatalError(
|
||||
0, "failed to demangle superclass of %s from mangled name '%s': %s\n",
|
||||
self->getDescription()->Name.get(), superclassName.str().c_str(),
|
||||
error->copyErrorString());
|
||||
}
|
||||
|
||||
return response;
|
||||
return result.getType().getResponse();
|
||||
} else {
|
||||
return MetadataResponse();
|
||||
}
|
||||
@@ -4928,12 +4926,12 @@ swift_getAssociatedTypeWitnessSlowImpl(
|
||||
Demangle::makeSymbolicMangledNameStringRef(mangledNameBase);
|
||||
|
||||
// Demangle the associated type.
|
||||
MetadataResponse response;
|
||||
TypeLookupErrorOr<TypeInfo> result = TypeInfo();
|
||||
if (inProtocolContext) {
|
||||
// The protocol's Self is the only generic parameter that can occur in the
|
||||
// type.
|
||||
response =
|
||||
swift_getTypeByMangledName(request, mangledName, nullptr,
|
||||
result = swift_getTypeByMangledName(
|
||||
request, mangledName, nullptr,
|
||||
[conformingType](unsigned depth, unsigned index) -> const Metadata * {
|
||||
if (depth == 0 && index == 0)
|
||||
return conformingType;
|
||||
@@ -4950,7 +4948,7 @@ swift_getAssociatedTypeWitnessSlowImpl(
|
||||
return swift_getAssociatedConformanceWitness(wtable, conformingType,
|
||||
type, reqBase,
|
||||
dependentDescriptor);
|
||||
}).getResponse();
|
||||
});
|
||||
} else {
|
||||
// The generic parameters in the associated type name are those of the
|
||||
// conforming type.
|
||||
@@ -4960,29 +4958,30 @@ swift_getAssociatedTypeWitnessSlowImpl(
|
||||
auto originalConformingType = findConformingSuperclass(conformingType,
|
||||
conformance);
|
||||
SubstGenericParametersFromMetadata substitutions(originalConformingType);
|
||||
response = swift_getTypeByMangledName(request, mangledName,
|
||||
substitutions.getGenericArgs(),
|
||||
[&substitutions](unsigned depth, unsigned index) {
|
||||
return substitutions.getMetadata(depth, index);
|
||||
},
|
||||
[&substitutions](const Metadata *type, unsigned index) {
|
||||
return substitutions.getWitnessTable(type, index);
|
||||
}).getResponse();
|
||||
result = swift_getTypeByMangledName(
|
||||
request, mangledName, substitutions.getGenericArgs(),
|
||||
[&substitutions](unsigned depth, unsigned index) {
|
||||
return substitutions.getMetadata(depth, index);
|
||||
},
|
||||
[&substitutions](const Metadata *type, unsigned index) {
|
||||
return substitutions.getWitnessTable(type, index);
|
||||
});
|
||||
}
|
||||
auto *error = result.getError();
|
||||
MetadataResponse response = result.getType().getResponse();
|
||||
auto assocTypeMetadata = response.Value;
|
||||
|
||||
if (!assocTypeMetadata) {
|
||||
if (error || !assocTypeMetadata) {
|
||||
const char *errStr = error ? error->copyErrorString()
|
||||
: "NULL metadata but no error was provided";
|
||||
auto conformingTypeNameInfo = swift_getTypeName(conformingType, true);
|
||||
StringRef conformingTypeName(conformingTypeNameInfo.data,
|
||||
conformingTypeNameInfo.length);
|
||||
StringRef assocTypeName = findAssociatedTypeName(protocol, assocType);
|
||||
fatalError(0,
|
||||
"failed to demangle witness for associated type '%s' in "
|
||||
"conformance '%s: %s' from mangled name '%s'\n",
|
||||
assocTypeName.str().c_str(),
|
||||
conformingTypeName.str().c_str(),
|
||||
protocol->Name.get(),
|
||||
mangledName.str().c_str());
|
||||
"conformance '%s: %s' from mangled name '%s' - %s\n",
|
||||
assocTypeName.str().c_str(), conformingTypeName.str().c_str(),
|
||||
protocol->Name.get(), mangledName.str().c_str(), errStr);
|
||||
}
|
||||
|
||||
assert((uintptr_t(assocTypeMetadata) &
|
||||
@@ -5935,7 +5934,7 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
|
||||
nullptr,
|
||||
[](unsigned, unsigned){ return nullptr; },
|
||||
[](const Metadata *, unsigned) { return nullptr; })
|
||||
.getMetadata();
|
||||
.getType().getMetadata();
|
||||
if (metadata != result)
|
||||
swift::warning(RuntimeErrorFlagNone,
|
||||
"Metadata mangled name failed to roundtrip: %p -> %s -> %p\n",
|
||||
|
||||
Reference in New Issue
Block a user