Skip to content

Commit b8f4aa5

Browse files
Merge pull request #39898 from AnthonyLatsis/envariant
GenericEnvironment: Replace 'substDependentTypesWithErrorTypes' with an assertion
2 parents 48a23a8 + 1cf9622 commit b8f4aa5

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

include/swift/AST/Type.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ class Type {
317317
LookupConformanceFn conformances,
318318
SubstOptions options=None) const;
319319

320-
/// Replace references to substitutable types with error types.
321-
Type substDependentTypesWithErrorTypes() const;
322-
323320
bool isPrivateStdlibType(bool treatNonBuiltinProtocolsAsPublic = true) const;
324321

325322
SWIFT_DEBUG_DUMP;

lib/AST/GenericEnvironment.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ Optional<Type> GenericEnvironment::getMappingIfPresent(
8787
Type GenericEnvironment::mapTypeIntoContext(GenericEnvironment *env,
8888
Type type) {
8989
assert(!type->hasArchetype() && "already have a contextual type");
90+
assert((env || !type->hasTypeParameter()) &&
91+
"no generic environment provided for type with type parameters");
9092

91-
if (!env)
92-
return type.substDependentTypesWithErrorTypes();
93+
if (!env) {
94+
return type;
95+
}
9396

9497
return env->mapTypeIntoContext(type);
9598
}

lib/AST/Type.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,13 +4151,6 @@ Type Type::subst(TypeSubstitutionFn substitutions,
41514151
return substType(*this, substitutions, conformances, options);
41524152
}
41534153

4154-
Type Type::substDependentTypesWithErrorTypes() const {
4155-
return substType(*this,
4156-
[](SubstitutableType *t) -> Type { return Type(); },
4157-
MakeAbstractConformanceForGenericType(),
4158-
SubstFlags::AllowLoweredTypes);
4159-
}
4160-
41614154
const DependentMemberType *TypeBase::findUnresolvedDependentMemberType() {
41624155
if (!hasTypeParameter()) return nullptr;
41634156

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ ValueDecl *DerivedConformance::deriveHashable(ValueDecl *requirement) {
10111011
// Hashable because DerivedConformance::canDeriveHashable returns true
10121012
// even if the conformance can't be derived. See the note there for
10131013
// details.
1014-
auto *dc = ConformanceDecl->getDeclContext();
1014+
auto *dc = cast<DeclContext>(ConformanceDecl);
10151015
tryDiagnoseFailedHashableDerivation(dc, Nominal);
10161016
return nullptr;
10171017
}

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,23 @@ AssociatedTypeDecl *AssociatedTypeInference::completeSolution(
11991199
// If the substitution produced an error, we're done.
12001200
if (type->hasError())
12011201
return witness.getAssocType();
1202+
1203+
// FIXME: If we still have a type parameter and it isn't a generic
1204+
// parameter of the conforming nominal, it's either a cycle or a
1205+
// solution that is beyond the current algorithm, i.e.
1206+
//
1207+
// protocol P {
1208+
// associatedtype A = B
1209+
// associatedtype B = C
1210+
// associatedtype C = Int
1211+
// }
1212+
// struct Conformer: P {}
1213+
if (type->hasTypeParameter() &&
1214+
!adoptee->getAnyNominal()->isGeneric()) {
1215+
return witness.getAssocType();
1216+
}
12021217
}
1218+
12031219
type = dc->mapTypeIntoContext(type);
12041220
}
12051221

test/Sema/enum_conformance_synthesis.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ func genericNotHashable() {
173173
GenericNotHashable<String>.A("a").hash(into: &hasher) // expected-error {{value of type 'GenericNotHashable<String>' has no member 'hash'}}
174174
}
175175

176+
enum GenericNotHashable2<T: Equatable, U: Hashable>: Hashable {
177+
// expected-error@-1 {{type 'GenericNotHashable2' does not conform to protocol 'Hashable'}}
178+
case A(U, T) // expected-note {{associated value type 'T' does not conform to protocol 'Hashable', preventing synthesized conformance of 'GenericNotHashable2<T, U>' to 'Hashable'}}
179+
case B
180+
}
181+
176182
// An enum with no cases should also derive conformance.
177183
enum NoCases: Hashable {}
178184

0 commit comments

Comments
 (0)