Skip to content

Commit 4a8ce3a

Browse files
authored
Merge pull request #61901 from slavapestov/narrow-swiftui-conformance-checker-hack
Sema: Narrow SwiftUI type witness matching compatibility hack to building a swiftinterface
2 parents ce423f8 + 318e404 commit 4a8ce3a

File tree

4 files changed

+6
-87
lines changed

4 files changed

+6
-87
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,10 +2024,6 @@ ERROR(synthesized_nominal_extension,none,
20242024
ERROR(type_does_not_conform,none,
20252025
"type %0 does not conform to protocol %1", (Type, Type))
20262026

2027-
// FIXME: SwiftUI source compatibility hack; see usage for details.
2028-
WARNING(type_does_not_conform_swiftui_warning,none,
2029-
"type %0 does not conform to protocol %1", (Type, Type))
2030-
20312027
ERROR(non_final_class_cannot_conform_to_self_same_type,none,
20322028
"non-final class %0 cannot safely conform to protocol %1, "
20332029
"which requires that %2 %select{is exactly equal to|inherit from}3 %4",

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4733,23 +4733,16 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
47334733
// of 'Never' if it is declared in a context that does not satisfy the
47344734
// requirements of the conformance context.
47354735
//
4736-
// FIXME: If SwiftUI redeclares the typealias under the correct constraints,
4737-
// this can be removed.
4736+
// FIXME: Remove this eventually.
47384737
bool skipRequirementCheck = false;
47394738
if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
4740-
if (typeAliasDecl->getUnderlyingType()->isNever()) {
4741-
if (typeAliasDecl->getParentModule()->getName().is("SwiftUI")) {
4739+
if (typeAliasDecl->getParentModule()->getName().is("SwiftUI") &&
4740+
typeAliasDecl->getParentSourceFile() &&
4741+
typeAliasDecl->getParentSourceFile()->Kind == SourceFileKind::Interface) {
4742+
if (typeAliasDecl->getUnderlyingType()->isNever()) {
47424743
if (typeAliasDecl->getDeclContext()->getSelfNominalTypeDecl() ==
47434744
DC->getSelfNominalTypeDecl()) {
4744-
const auto reqs =
4745-
typeAliasDecl->getGenericSignature().requirementsNotSatisfiedBy(
4746-
DC->getGenericSignatureOfContext());
4747-
if (!reqs.empty()) {
4748-
SwiftUIInvalidTyWitness = {assocType, typeAliasDecl,
4749-
reqs.front()};
4750-
4751-
skipRequirementCheck = true;
4752-
}
4745+
skipRequirementCheck = true;
47534746
}
47544747
}
47554748
}
@@ -5423,32 +5416,6 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
54235416
if (Conformance->isInvalid()) {
54245417
return;
54255418
}
5426-
5427-
// As a narrow fix for a source compatibility issue with SwiftUI's
5428-
// swiftinterface, but only if the conformance succeeds, warn about an
5429-
// actually malformed conformance if we recorded a 'typealias' type witness
5430-
// with an underlying type of 'Never', which resides in a context that does
5431-
// not satisfy the requirements of the conformance context.
5432-
//
5433-
// FIXME: If SwiftUI redeclares the typealias under the correct constraints,
5434-
// this can be removed.
5435-
if (SwiftUIInvalidTyWitness) {
5436-
const auto &info = SwiftUIInvalidTyWitness.getValue();
5437-
const auto &failedReq = info.FailedReq;
5438-
5439-
auto &diags = getASTContext().Diags;
5440-
diags.diagnose(Loc, diag::type_does_not_conform_swiftui_warning, Adoptee,
5441-
Proto->getDeclaredInterfaceType());
5442-
diags.diagnose(info.AssocTypeDecl, diag::no_witnesses_type,
5443-
info.AssocTypeDecl->getName());
5444-
5445-
if (failedReq.getKind() != RequirementKind::Layout) {
5446-
diags.diagnose(info.TypeWitnessDecl,
5447-
diag::protocol_type_witness_missing_requirement,
5448-
failedReq.getFirstType(), failedReq.getSecondType(),
5449-
(unsigned)failedReq.getKind());
5450-
}
5451-
}
54525419
}
54535420

54545421
/// Retrieve the Objective-C method key from the given function.

lib/Sema/TypeCheckProtocol.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -760,14 +760,6 @@ class ConformanceChecker : public WitnessChecker {
760760
/// Whether objcMethodRequirements has been computed.
761761
bool computedObjCMethodRequirements = false;
762762

763-
// FIXME: SwiftUI source compatibility hack; see usage for details.
764-
struct SwiftUIInvalidTypeWitness final {
765-
AssociatedTypeDecl *AssocTypeDecl;
766-
TypeAliasDecl *TypeWitnessDecl;
767-
Requirement FailedReq;
768-
};
769-
llvm::Optional<SwiftUIInvalidTypeWitness> SwiftUIInvalidTyWitness = None;
770-
771763
/// Retrieve the associated types that are referenced by the given
772764
/// requirement with a base of 'Self'.
773765
ArrayRef<AssociatedTypeDecl *> getReferencedAssociatedTypes(ValueDecl *req);

test/Generics/constrained_type_witnesses_swiftui_hack.swift

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)