More progress towards getting same-type constraints working correctly.

Swift SVN r16023
This commit is contained in:
Joe Pamer
2014-04-07 21:31:52 +00:00
parent b9fdfe3063
commit 18f3bf67b0
7 changed files with 40 additions and 19 deletions

View File

@@ -40,7 +40,7 @@ enum class AllocationArena;
/// \brief Type substitution mapping from substitutable types to their
/// replacements.
typedef llvm::DenseMap<SubstitutableType *, Type> TypeSubstitutionMap;
typedef llvm::DenseMap<TypeBase *, Type> TypeSubstitutionMap;
/// Map from non-type requirements to the corresponding conformance witnesses.
typedef llvm::DenseMap<ValueDecl *, ConcreteDeclRef> WitnessMap;

View File

@@ -43,7 +43,7 @@ class TypeWalker;
/// \brief Type substitution mapping from substitutable types to their
/// replacements.
typedef llvm::DenseMap<SubstitutableType *, Type> TypeSubstitutionMap;
typedef llvm::DenseMap<TypeBase *, Type> TypeSubstitutionMap;
/// Type - This is a simple value object that contains a pointer to a type
/// class. This is potentially sugared. We use this throughout the codebase

View File

@@ -1640,10 +1640,6 @@ GenericParamList::getSubstitutionMap(ArrayRef<swift::Substitution> Subs) const {
auto sub = Subs.front();
Subs = Subs.slice(1);
// Only substitute primary archetypes.
if (!arch->isPrimary())
continue;
map.insert({arch, sub.Replacement});
}
@@ -1757,13 +1753,22 @@ GenericSignature::getSubstitutionMap(ArrayRef<Substitution> args) const {
return subs;
}
// Seed the type map with pre-existing substitutions.
for (auto sub : args) {
subs[sub.Archetype] = sub.Replacement;
}
for (auto depTy : getAllDependentTypes()) {
auto replacement = args.front().Replacement;
args = args.slice(1);
// FIXME: DependentMemberTypes aren't SubstitutableTypes.
if (auto subTy = depTy->getAs<SubstitutableType>())
if (auto subTy = depTy->getAs<SubstitutableType>()) {
subs[subTy] = replacement;
}
else if (auto dTy = depTy->getAs<DependentMemberType>()) {
subs[dTy] = replacement;
}
}
assert(args.empty() && "did not use all substitutions?!");
return subs;
@@ -1896,8 +1901,15 @@ Type Type::subst(Module *module, TypeSubstitutionMap &substitutions,
.subst(module, substitutions, ignoreMissing, resolver);
// Resolve the member relative to the substituted base.
if (Type r = depMemTy->substBaseType(module, newBase, resolver))
if (Type r = depMemTy->substBaseType(module, newBase, resolver)) {
// Substitute archtypes for generic type parameters to prevent
// dependent types from leaking.
if (auto GTPT = r->getAs<GenericTypeParamType>()) {
return GTPT->getDecl()->getArchetype();
}
return r;
}
return failed(type);
}

View File

@@ -566,8 +566,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, TypeMatchKind kind,
// Add a new constraint between these types. We consider the current
// type-matching problem to the "solved" by this addition, because
// this new constraint will be solved at a later point.
// Obviously, this must not happen at the top level, or the algorithm
// would not terminate.
// Obviously, this must not happen at the top level, or the
// algorithm would not terminate.
addConstraint(getConstraintKind(kind), rep1, rep2,
getConstraintLocator(locator));
return SolutionKind::Solved;

View File

@@ -1189,10 +1189,17 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
// in the case of a conformance check against an associated type rooted off of
// "Self"), we'll need to open the type up so as not to short-circuit the
// binding constraint against the already bound overload type.
if ((choice.getKind() == OverloadChoiceKind::TypeDecl) &&
refType->getAs<DependentMemberType>()) {
if (refType->isDependentType()) {
openedFullType = openType(openedFullType,
choice.getDecl()->
getPotentialGenericDeclContext());
refType = openType(refType,
choice.getDecl()->getPotentialGenericDeclContext());
if (auto FT = openedFullType->getAs<FunctionType>()) {
auto returnType = FT->getResult();
addConstraint(ConstraintKind::Bind, returnType, refType);
}
}
// Add the type binding constraint.

View File

@@ -824,10 +824,12 @@ bool TypeChecker::checkSubstitutions(TypeSubstitutionMap &Substitutions,
// Find all of the primary archetypes and enter them into the archetype
// stack.
for (const auto &sub : Substitutions) {
auto archetype = sub.first->getArchetype();
if (auto subTy = sub.first->getAs<SubstitutableType>()) {
auto archetype = subTy->getArchetype();
if (archetype->isPrimary() && knownArchetypes.insert(archetype))
archetypeStack.push_back(archetype);
}
}
// Check that each of the replacements for the archetypes conform
// to the required protocols.

View File

@@ -352,7 +352,7 @@ public:
// then required to have keywords for every argument that name properties
// of the type.
Pattern *visitCallExpr(CallExpr *ce) {
DependentGenericTypeResolver resolver;
PartialGenericTypeToArchetypeResolver resolver(TC);
SmallVector<ComponentIdentTypeRepr *, 2> components;
if (!ExprToIdentTypeRepr(components, TC.Context).visit(ce->getFn()))