Encapsulate Substitution's state.

Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
This commit is contained in:
Joe Groff
2014-07-23 18:00:38 +00:00
parent 1e16a23460
commit 623aba1786
31 changed files with 175 additions and 124 deletions

View File

@@ -955,7 +955,8 @@ ConstraintSystem::getTypeOfMemberReference(Type baseTy, ValueDecl *value,
ProtocolConformance *conformance = nullptr;
if (TC.conformsToProtocol(baseObjTy, proto, DC, &conformance) &&
conformance->isComplete()) {
auto memberTy = conformance->getTypeWitness(assocType, &TC).Replacement;
auto memberTy = conformance->getTypeWitness(assocType, &TC)
.getReplacement();
if (!isTypeReference)
memberTy = MetatypeType::get(memberTy);
@@ -1101,7 +1102,7 @@ ConstraintSystem::getTypeOfMemberReference(Type baseTy, ValueDecl *value,
ProtocolConformance *conformance = nullptr;
if (TC.conformsToProtocol(baseObjTy, proto, DC, &conformance) &&
conformance->isComplete()) {
type = conformance->getTypeWitness(assocType, &TC).Replacement;
type = conformance->getTypeWitness(assocType, &TC).getReplacement();
}
}
} else if (isa<ConstructorDecl>(value) || isa<EnumElementDecl>(value) ||