mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduce ProtocolConformanceRef. NFC.
The main idea here is that we really, really want to be able to recover the protocol requirement of a conformance reference even if it's abstract due to the conforming type being abstract (e.g. an archetype). I've made the conversion from ProtocolConformance* explicit to discourage casual contamination of the Ref with a null value. As part of this change, always make conformance arrays in Substitutions fully parallel to the requirements, as opposed to occasionally being empty when the conformances are abstract. As another part of this, I've tried to proactively fix prospective bugs with partially-concrete conformances, which I believe can happen with concretely-bound archetypes. In addition to just giving us stronger invariants, this is progress towards the removal of the archetype from Substitution.
This commit is contained in:
@@ -704,25 +704,24 @@ ArrayRef<Substitution> BoundGenericType::getSubstitutions(
|
||||
if (!type)
|
||||
type = ErrorType::get(module->getASTContext());
|
||||
|
||||
SmallVector<ProtocolConformance *, 4> conformances;
|
||||
if (type->is<TypeVariableType>() || type->isTypeParameter()) {
|
||||
SmallVector<ProtocolConformanceRef, 4> conformances;
|
||||
for (auto proto : archetype->getConformsTo()) {
|
||||
// If the type is a type variable or is dependent, just fill in null
|
||||
// conformances. FIXME: It seems like we should record these as
|
||||
// requirements (?).
|
||||
conformances.assign(archetype->getConformsTo().size(), nullptr);
|
||||
} else {
|
||||
// Find the conformances.
|
||||
for (auto proto : archetype->getConformsTo()) {
|
||||
// conformances.
|
||||
if (type->is<TypeVariableType>() || type->isTypeParameter()) {
|
||||
conformances.push_back(ProtocolConformanceRef(proto));
|
||||
|
||||
// Otherwise, find the conformances.
|
||||
} else {
|
||||
auto conforms = module->lookupConformance(type, proto, resolver);
|
||||
switch (conforms.getInt()) {
|
||||
case ConformanceKind::Conforms:
|
||||
conformances.push_back(conforms.getPointer());
|
||||
conformances.push_back(
|
||||
ProtocolConformanceRef(proto, conforms.getPointer()));
|
||||
break;
|
||||
case ConformanceKind::UncheckedConforms:
|
||||
conformances.push_back(nullptr);
|
||||
break;
|
||||
case ConformanceKind::DoesNotConform:
|
||||
conformances.push_back(nullptr);
|
||||
conformances.push_back(ProtocolConformanceRef(proto));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user