[Runtime] Introduce equality operation for nominal type descriptors.

Nominal type descriptors are not always unique, so testing them via pointer
equality is not correct. Introduce an "isEqual()" operation for
nominal type descriptors that performs the appropriate equality check,
using pointer equality when possible, and falling back to string
comparisons of the mangled type name when it is not possible.

Introduce a "nonunique" flag into nominal type descriptors to describe
when they are, in fact, not unique. The only nonunique nominal type
descriptors currently come from Clang-imported types; all
Swift-defined types have unique nominal type descriptors. Use this
flag to make the aforementioned operation efficient in the "unique"
case.

Use the new isEqual() operation for protocol conformance lookup, and
make sure we're caching results based on the known-canonical nominal
type descriptor.
This commit is contained in:
Doug Gregor
2018-01-04 11:47:50 -08:00
parent 12a774abec
commit 6118d86032
6 changed files with 64 additions and 8 deletions

View File

@@ -2205,6 +2205,9 @@ namespace {
}
}
// Whether the nominal type descriptor is known to be unique.
flags = flags.withIsUnique(asImpl().isUniqueDescriptor());
// Calculate the number of generic parameters at each nesting depth.
unsigned totalGenericParams = 0;
SmallVector<unsigned, 2> numPrimaryParams;
@@ -2263,12 +2266,21 @@ namespace {
return var;
}
// Imported declarations have nonunique nominal type descriptors.
bool isUniqueDescriptor() {
return !isa<ClangModuleUnit>(
asImpl().getTarget()->getModuleScopeContext());
}
// Derived class must provide:
// NominalTypeDecl *getTarget();
// unsigned getKind();
// unsigned getGenericParamsOffset();
// void addKindDependentFields();
//
// Derived class can override:
// bool isUniqueDescriptor();
};
/// Build a doubly-null-terminated list of field names.