[Runtime] Consolidate runtime functions used for demangle-to-metadata.

Clean up the interfaces used to go from a mangled name or demangle tree to
metadata. Parameterize these interfaces for generic parameter substitutions
(already in use) and dependent conformance substitutions (speculative).
This commit is contained in:
Doug Gregor
2018-11-15 15:57:44 -08:00
parent 9191ffe124
commit cd6d6be64d
5 changed files with 131 additions and 71 deletions

View File

@@ -2552,7 +2552,7 @@ swift::swift_initClassMetadata(ClassMetadata *self,
Demangle::makeSymbolicMangledNameStringRef(superclassNameBase);
SubstGenericParametersFromMetadata substitutions(self);
const Metadata *superclass =
_getTypeByMangledName(superclassName, substitutions);
_getTypeByMangledName(superclassName, substitutions, substitutions);
if (!superclass) {
fatalError(0,
"failed to demangle superclass of %s from mangled name '%s'\n",
@@ -2642,7 +2642,7 @@ swift::swift_updateClassMetadata(ClassMetadata *self,
Demangle::makeSymbolicMangledNameStringRef(superclassNameBase);
SubstGenericParametersFromMetadata substitutions(self);
const Metadata *superclass =
_getTypeByMangledName(superclassName, substitutions);
_getTypeByMangledName(superclassName, substitutions, substitutions);
if (!superclass) {
fatalError(0,
"failed to demangle superclass of %s from mangled name '%s'\n",
@@ -4111,12 +4111,23 @@ swift_getAssociatedTypeWitnessSlowImpl(
// type.
assocTypeMetadata =
_getTypeByMangledName(mangledName,
[conformingType](unsigned depth, unsigned index) -> const Metadata * {
if (depth == 0 && index == 0)
return conformingType;
[conformingType](unsigned depth, unsigned index) -> const Metadata * {
if (depth == 0 && index == 0)
return conformingType;
return nullptr;
});
return nullptr;
},
[&](const Metadata *type, unsigned index) -> const WitnessTable * {
auto requirements = protocol->getRequirements();
auto dependentDescriptor = requirements.data() + index;
if (dependentDescriptor < requirements.begin() ||
dependentDescriptor >= requirements.end())
return nullptr;
return swift_getAssociatedConformanceWitness(wtable, conformingType,
type, reqBase,
dependentDescriptor);
});
} else {
// The generic parameters in the associated type name are those of the
// conforming type.
@@ -4126,7 +4137,8 @@ swift_getAssociatedTypeWitnessSlowImpl(
auto originalConformingType = findConformingSuperclass(conformingType,
conformance);
SubstGenericParametersFromMetadata substitutions(originalConformingType);
assocTypeMetadata = _getTypeByMangledName(mangledName, substitutions);
assocTypeMetadata = _getTypeByMangledName(mangledName, substitutions,
substitutions);
}
if (!assocTypeMetadata) {
@@ -4191,8 +4203,11 @@ static const WitnessTable *swift_getAssociatedConformanceWitnessSlowImpl(
assert(assocConformance >= requirements.begin() &&
assocConformance < requirements.end());
assert(reqBase == requirements.data() - WitnessTableFirstRequirementOffset);
assert(assocConformance->Flags.getKind() ==
ProtocolRequirementFlags::Kind::AssociatedConformanceAccessFunction);
assert(
assocConformance->Flags.getKind() ==
ProtocolRequirementFlags::Kind::AssociatedConformanceAccessFunction ||
assocConformance->Flags.getKind() ==
ProtocolRequirementFlags::Kind::BaseProtocol);
}
#endif
@@ -4859,8 +4874,10 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
return;
auto mangledName = Demangle::mangleNode(node);
auto result = _getTypeByMangledName(mangledName,
[](unsigned, unsigned){ return nullptr; });
auto result =
_getTypeByMangledName(mangledName,
[](unsigned, unsigned){ return nullptr; },
[](const Metadata *, unsigned) { return nullptr; });
if (metadata != result)
swift::warning(RuntimeErrorFlagNone,
"Metadata mangled name failed to roundtrip: %p -> %s -> %p\n",