Skip to content

Sema: Narrow SwiftUI type witness matching compatibility hack to building a swiftinterface #61901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2024,10 +2024,6 @@ ERROR(synthesized_nominal_extension,none,
ERROR(type_does_not_conform,none,
"type %0 does not conform to protocol %1", (Type, Type))

// FIXME: SwiftUI source compatibility hack; see usage for details.
WARNING(type_does_not_conform_swiftui_warning,none,
"type %0 does not conform to protocol %1", (Type, Type))

ERROR(non_final_class_cannot_conform_to_self_same_type,none,
"non-final class %0 cannot safely conform to protocol %1, "
"which requires that %2 %select{is exactly equal to|inherit from}3 %4",
Expand Down
45 changes: 6 additions & 39 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4733,23 +4733,16 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
// of 'Never' if it is declared in a context that does not satisfy the
// requirements of the conformance context.
//
// FIXME: If SwiftUI redeclares the typealias under the correct constraints,
// this can be removed.
// FIXME: Remove this eventually.
bool skipRequirementCheck = false;
if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
if (typeAliasDecl->getUnderlyingType()->isNever()) {
if (typeAliasDecl->getParentModule()->getName().is("SwiftUI")) {
if (typeAliasDecl->getParentModule()->getName().is("SwiftUI") &&
typeAliasDecl->getParentSourceFile() &&
typeAliasDecl->getParentSourceFile()->Kind == SourceFileKind::Interface) {
if (typeAliasDecl->getUnderlyingType()->isNever()) {
if (typeAliasDecl->getDeclContext()->getSelfNominalTypeDecl() ==
DC->getSelfNominalTypeDecl()) {
const auto reqs =
typeAliasDecl->getGenericSignature().requirementsNotSatisfiedBy(
DC->getGenericSignatureOfContext());
if (!reqs.empty()) {
SwiftUIInvalidTyWitness = {assocType, typeAliasDecl,
reqs.front()};

skipRequirementCheck = true;
}
skipRequirementCheck = true;
}
}
}
Expand Down Expand Up @@ -5423,32 +5416,6 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
if (Conformance->isInvalid()) {
return;
}

// As a narrow fix for a source compatibility issue with SwiftUI's
// swiftinterface, but only if the conformance succeeds, warn about an
// actually malformed conformance if we recorded a 'typealias' type witness
// with an underlying type of 'Never', which resides in a context that does
// not satisfy the requirements of the conformance context.
//
// FIXME: If SwiftUI redeclares the typealias under the correct constraints,
// this can be removed.
if (SwiftUIInvalidTyWitness) {
const auto &info = SwiftUIInvalidTyWitness.getValue();
const auto &failedReq = info.FailedReq;

auto &diags = getASTContext().Diags;
diags.diagnose(Loc, diag::type_does_not_conform_swiftui_warning, Adoptee,
Proto->getDeclaredInterfaceType());
diags.diagnose(info.AssocTypeDecl, diag::no_witnesses_type,
info.AssocTypeDecl->getName());

if (failedReq.getKind() != RequirementKind::Layout) {
diags.diagnose(info.TypeWitnessDecl,
diag::protocol_type_witness_missing_requirement,
failedReq.getFirstType(), failedReq.getSecondType(),
(unsigned)failedReq.getKind());
}
}
}

/// Retrieve the Objective-C method key from the given function.
Expand Down
8 changes: 0 additions & 8 deletions lib/Sema/TypeCheckProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -760,14 +760,6 @@ class ConformanceChecker : public WitnessChecker {
/// Whether objcMethodRequirements has been computed.
bool computedObjCMethodRequirements = false;

// FIXME: SwiftUI source compatibility hack; see usage for details.
struct SwiftUIInvalidTypeWitness final {
AssociatedTypeDecl *AssocTypeDecl;
TypeAliasDecl *TypeWitnessDecl;
Requirement FailedReq;
};
llvm::Optional<SwiftUIInvalidTypeWitness> SwiftUIInvalidTyWitness = None;

/// Retrieve the associated types that are referenced by the given
/// requirement with a base of 'Self'.
ArrayRef<AssociatedTypeDecl *> getReferencedAssociatedTypes(ValueDecl *req);
Expand Down
36 changes: 0 additions & 36 deletions test/Generics/constrained_type_witnesses_swiftui_hack.swift

This file was deleted.