Skip to content

Commit 9e5a9b9

Browse files
committed
AST: Remove NoncopyableGenerics feature suppression.
It is no longer necessary to produce `.swiftinterface` files the support older compilers that lack support for the NoncopyableGenerics feature. Cleaning this up makes the stdlib `.swiftinterface` far more readable.
1 parent b1bf693 commit 9e5a9b9

File tree

8 files changed

+53
-388
lines changed

8 files changed

+53
-388
lines changed

include/swift/AST/PrintOptions.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,6 @@ struct PrintOptions {
385385
/// Suppress 'sending' on arguments and results.
386386
bool SuppressSendingArgsAndResults = false;
387387

388-
/// Suppress Noncopyable generics.
389-
bool SuppressNoncopyableGenerics = false;
390-
391-
/// Suppress printing of `borrowing` and `consuming`.
392-
bool SuppressNoncopyableOwnershipModifiers = false;
393-
394388
/// Suppress printing of '~Proto' for suppressible, non-invertible protocols.
395389
bool SuppressConformanceSuppression = false;
396390

include/swift/Basic/Features.def

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(AssociatedTypeImplements, 0, "@_implements on asso
193193
LANGUAGE_FEATURE(BuiltinAddressOfRawLayout, 0, "Builtin.addressOfRawLayout")
194194
LANGUAGE_FEATURE(MoveOnlyPartialConsumption, 429, "Partial consumption of noncopyable values")
195195
LANGUAGE_FEATURE(BitwiseCopyable, 426, "BitwiseCopyable protocol")
196-
SUPPRESSIBLE_LANGUAGE_FEATURE(NoncopyableGenerics, 427, "Noncopyable generics")
196+
BASELINE_LANGUAGE_FEATURE(NoncopyableGenerics, 427, "Noncopyable generics")
197+
BASELINE_LANGUAGE_FEATURE(NoncopyableGenerics2, 427, "Noncopyable generics alias")
197198
SUPPRESSIBLE_LANGUAGE_FEATURE(ConformanceSuppression, 426, "Suppressible inferred conformances")
198199
SUPPRESSIBLE_LANGUAGE_FEATURE(BitwiseCopyable2, 426, "BitwiseCopyable feature")
199200
LANGUAGE_FEATURE(BodyMacros, 415, "Function body macros")
@@ -348,9 +349,6 @@ EXPERIMENTAL_FEATURE(Embedded, true)
348349
/// Enables importing the Volatile module
349350
EXPERIMENTAL_FEATURE(Volatile, true)
350351

351-
// Alias for NoncopyableGenerics
352-
EXPERIMENTAL_FEATURE(NoncopyableGenerics2, true)
353-
354352
// Enables ~Copyable and ~Escapable annotations on associatedtype declarations.
355353
EXPERIMENTAL_FEATURE(SuppressedAssociatedTypes, true)
356354

lib/AST/ASTPrinter.cpp

Lines changed: 9 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -983,12 +983,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
983983
/// The default generic signature flags for printing requirements.
984984
static unsigned
985985
defaultGenericRequirementFlags(const PrintOptions &options) {
986-
unsigned flags = PrintRequirements;
987-
988-
if (!options.SuppressNoncopyableGenerics)
989-
flags |= PrintInverseRequirements;
990-
991-
return flags;
986+
return PrintRequirements | PrintInverseRequirements;
992987
}
993988

994989
void printInheritedFromRequirementSignature(ProtocolDecl *proto,
@@ -1148,18 +1143,8 @@ class PrintAST : public ASTVisitor<PrintAST> {
11481143
Printer.callPrintDeclPre(D, Options.BracketOptions);
11491144

11501145
if (Options.PrintCompatibilityFeatureChecks) {
1151-
printWithCompatibilityFeatureChecks(Printer, Options, D, [&] {
1152-
// If we are in a scope where non-copyable generics are being suppressed
1153-
// and we are also printing a decl that has @_preInverseGenerics, make
1154-
// sure we also suppress printing ownership modifiers that were added
1155-
// to satisfy the requirements of non-copyability.
1156-
llvm::SaveAndRestore<bool> scope(
1157-
Options.SuppressNoncopyableOwnershipModifiers,
1158-
Options.SuppressNoncopyableGenerics &&
1159-
D->getAttrs().hasAttribute<PreInverseGenericsAttr>());
1160-
1161-
ASTVisitor::visit(D);
1162-
});
1146+
printWithCompatibilityFeatureChecks(Printer, Options, D,
1147+
[&] { ASTVisitor::visit(D); });
11631148
} else {
11641149
ASTVisitor::visit(D);
11651150
}
@@ -1642,9 +1627,8 @@ void PrintAST::printInheritedFromRequirementSignature(ProtocolDecl *proto,
16421627
// The invertible protocols themselves do not need to state inverses in their
16431628
// inheritance clause, because they do not gain any default requirements.
16441629
// HACK: also exclude Sendable from getting inverses printed.
1645-
if (!proto->getInvertibleProtocolKind()
1646-
&& !proto->isSpecificProtocol(KnownProtocolKind::Sendable) &&
1647-
!Options.SuppressNoncopyableGenerics)
1630+
if (!proto->getInvertibleProtocolKind() &&
1631+
!proto->isSpecificProtocol(KnownProtocolKind::Sendable))
16481632
flags |= PrintInverseRequirements;
16491633

16501634
printRequirementSignature(
@@ -1701,18 +1685,6 @@ void PrintAST::printGenericSignature(GenericSignature genericSig,
17011685
AllInverses());
17021686
}
17031687

1704-
// Erase any requirements involving invertible protocols.
1705-
static void eraseInvertibleProtocolConformances(
1706-
SmallVectorImpl<Requirement> &requirements) {
1707-
llvm::erase_if(requirements, [&](Requirement req) {
1708-
if (req.getKind() != RequirementKind::Conformance)
1709-
return false;
1710-
1711-
return req.getProtocolDecl()
1712-
->getInvertibleProtocolKind().has_value();
1713-
});
1714-
}
1715-
17161688
InversesAtDepth::InversesAtDepth(GenericContext *level) {
17171689
includedDepth = std::nullopt;
17181690
// Does this generic context have its own generic parameters?
@@ -1745,9 +1717,6 @@ void PrintAST::printGenericSignature(
17451717
} else {
17461718
requirements.append(genericSig.getRequirements().begin(),
17471719
genericSig.getRequirements().end());
1748-
1749-
if (Options.SuppressNoncopyableGenerics)
1750-
eraseInvertibleProtocolConformances(requirements);
17511720
}
17521721

17531722
if (flags & InnermostOnly) {
@@ -2026,9 +1995,6 @@ void PrintAST::printRequirementSignature(ProtocolDecl *owner,
20261995
} else {
20271996
requirements.append(sig.getRequirements().begin(),
20281997
sig.getRequirements().end());
2029-
2030-
if (Options.SuppressNoncopyableGenerics)
2031-
eraseInvertibleProtocolConformances(requirements);
20321998
}
20331999

20342000
if (attachingTo) {
@@ -3172,17 +3138,6 @@ static void suppressingFeatureAssociatedTypeImplements(PrintOptions &options,
31723138
options.ExcludeAttrList.resize(originalExcludeAttrCount);
31733139
}
31743140

3175-
static void suppressingFeatureNoncopyableGenerics(
3176-
PrintOptions &options,
3177-
llvm::function_ref<void()> action) {
3178-
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3179-
options.ExcludeAttrList.push_back(DeclAttrKind::PreInverseGenerics);
3180-
llvm::SaveAndRestore<bool> scope(
3181-
options.SuppressNoncopyableGenerics, true);
3182-
action();
3183-
options.ExcludeAttrList.resize(originalExcludeAttrCount);
3184-
}
3185-
31863141
static void
31873142
suppressingFeatureConformanceSuppression(PrintOptions &options,
31883143
llvm::function_ref<void()> action) {
@@ -3783,14 +3738,10 @@ static void printParameterFlags(ASTPrinter &printer,
37833738
printer.printKeyword("inout", options, " ");
37843739
break;
37853740
case ParamSpecifier::Borrowing:
3786-
if (!options.SuppressNoncopyableOwnershipModifiers) {
3787-
printer.printKeyword("borrowing", options, " ");
3788-
}
3741+
printer.printKeyword("borrowing", options, " ");
37893742
break;
37903743
case ParamSpecifier::Consuming:
3791-
if (!options.SuppressNoncopyableOwnershipModifiers) {
3792-
printer.printKeyword("consuming", options, " ");
3793-
}
3744+
printer.printKeyword("consuming", options, " ");
37943745
break;
37953746
case ParamSpecifier::LegacyShared:
37963747
printer.printKeyword("__shared", options, " ");
@@ -7481,7 +7432,7 @@ void GenericSignature::print(ASTPrinter &Printer,
74817432
}
74827433

74837434
auto flags = PrintAST::PrintParams | PrintAST::PrintRequirements;
7484-
if (Opts.PrintInverseRequirements && !Opts.SuppressNoncopyableGenerics)
7435+
if (Opts.PrintInverseRequirements)
74857436
flags |= PrintAST::PrintInverseRequirements;
74867437
PrintAST(Printer, Opts).printGenericSignature(*this, flags);
74877438
}
@@ -7497,7 +7448,7 @@ void RequirementSignature::print(ProtocolDecl *owner,
74977448
ASTPrinter &Printer,
74987449
const PrintOptions &Opts) const {
74997450
auto flags = PrintAST::PrintParams | PrintAST::PrintRequirements;
7500-
if (Opts.PrintInverseRequirements && !Opts.SuppressNoncopyableGenerics)
7451+
if (Opts.PrintInverseRequirements)
75017452
flags |= PrintAST::PrintInverseRequirements;
75027453
PrintAST(Printer, Opts).printRequirementSignature(owner, *this, flags, nullptr);
75037454
}
@@ -7898,10 +7849,6 @@ swift::getInheritedForPrinting(
78987849

78997850
// Preserve any inverses that appeared in the unprintable type.
79007851
if (foundUnprintable) {
7901-
if (printableInverses.contains(InvertibleProtocolKind::Copyable)
7902-
&& options.SuppressNoncopyableGenerics)
7903-
printableInverses.remove(InvertibleProtocolKind::Copyable);
7904-
79057852
if (!printableInverses.empty()) {
79067853
auto inversesTy = ProtocolCompositionType::get(decl->getASTContext(),
79077854
/*members=*/{},
@@ -7911,26 +7858,6 @@ swift::getInheritedForPrinting(
79117858
}
79127859
continue;
79137860
}
7914-
7915-
// Suppress Copyable and ~Copyable.
7916-
if (options.SuppressNoncopyableGenerics) {
7917-
if (auto pct = ty->getAs<ProtocolCompositionType>()) {
7918-
auto inverses = pct->getInverses();
7919-
if (inverses.contains(InvertibleProtocolKind::Copyable)) {
7920-
inverses.remove(InvertibleProtocolKind::Copyable);
7921-
ty = ProtocolCompositionType::get(decl->getASTContext(),
7922-
pct->getMembers(),
7923-
inverses,
7924-
pct->hasExplicitAnyObject());
7925-
if (ty->isAny())
7926-
continue;
7927-
}
7928-
}
7929-
7930-
if (auto protoTy = ty->getAs<ProtocolType>())
7931-
if (protoTy->getDecl()->isSpecificProtocol(KnownProtocolKind::Copyable))
7932-
continue;
7933-
}
79347861
}
79357862
if (options.SuppressConformanceSuppression &&
79367863
inherited.getEntry(i).isSuppressed()) {

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -504,94 +504,6 @@ UNINTERESTING_FEATURE(SuppressedAssociatedTypes)
504504

505505
static bool disallowFeatureSuppression(StringRef featureName, Decl *decl);
506506

507-
static bool allSubstTypesAreCopyable(Type type, DeclContext *context) {
508-
assert(type->getAnyNominal());
509-
auto bgt = type->getAs<BoundGenericType>();
510-
if (!bgt)
511-
return false; // nothing is bound.
512-
513-
for (auto argInterfaceTy : bgt->getGenericArgs())
514-
if (context->mapTypeIntoContext(argInterfaceTy)->isNoncopyable())
515-
return false;
516-
517-
return true;
518-
}
519-
520-
static bool usesFeatureNoncopyableGenerics(Decl *decl) {
521-
if (decl->getAttrs().hasAttribute<PreInverseGenericsAttr>())
522-
return true;
523-
524-
if (auto *valueDecl = dyn_cast<ValueDecl>(decl)) {
525-
if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
526-
auto reqSig = proto->getRequirementSignature();
527-
528-
SmallVector<Requirement, 2> reqs;
529-
SmallVector<InverseRequirement, 2> inverses;
530-
reqSig.getRequirementsWithInverses(proto, reqs, inverses);
531-
if (!inverses.empty())
532-
return true;
533-
}
534-
535-
if (isa<AbstractFunctionDecl>(valueDecl) ||
536-
isa<AbstractStorageDecl>(valueDecl)) {
537-
auto *context = decl->getInnermostDeclContext();
538-
auto usesFeature = valueDecl->getInterfaceType().findIf(
539-
[&](Type type) -> bool {
540-
auto *nominalDecl = type->getAnyNominal();
541-
if (!nominalDecl || !isa<StructDecl, EnumDecl, ClassDecl>(nominalDecl))
542-
return false;
543-
544-
if (!usesFeatureNoncopyableGenerics(nominalDecl))
545-
return false;
546-
547-
// If we only _refer_ to a TypeDecl that uses NoncopyableGenerics,
548-
// and a suppressed version of that decl is in the interface, and
549-
// if we only substitute Copyable types for the generic parameters,
550-
// then we can say this decl is not "using" the feature such that
551-
// a feature guard is required. In other words, this reference to the
552-
// type will always be valid, regardless of whether the feature is
553-
// enabled or not. (rdar://127389991)
554-
if (!disallowFeatureSuppression("NoncopyableGenerics", nominalDecl)
555-
&& allSubstTypesAreCopyable(type, context)) {
556-
return false;
557-
}
558-
559-
return true;
560-
});
561-
if (usesFeature)
562-
return true;
563-
}
564-
}
565-
566-
if (auto *ext = dyn_cast<ExtensionDecl>(decl)) {
567-
if (auto *nominal = ext->getExtendedNominal())
568-
if (usesFeatureNoncopyableGenerics(nominal))
569-
return true;
570-
}
571-
572-
SmallVector<Requirement, 2> reqs;
573-
SmallVector<InverseRequirement, 2> inverseReqs;
574-
575-
if (auto *proto = dyn_cast<ProtocolDecl>(decl)) {
576-
577-
// We have baked-in support for Sendable not needing to state inverses
578-
// in its inheritance clause within interface files. So, it technically is
579-
// not using the feature with respect to the concerns of an interface file.
580-
if (proto->isSpecificProtocol(KnownProtocolKind::Sendable))
581-
return false;
582-
583-
proto->getRequirementSignature().getRequirementsWithInverses(
584-
proto, reqs, inverseReqs);
585-
} else if (auto *genCtx = decl->getAsGenericContext()) {
586-
if (auto genericSig = genCtx->getGenericSignature())
587-
genericSig->getRequirementsWithInverses(reqs, inverseReqs);
588-
}
589-
590-
return !inverseReqs.empty();
591-
}
592-
593-
UNINTERESTING_FEATURE(NoncopyableGenerics2)
594-
595507
static bool usesFeatureStructLetDestructuring(Decl *decl) {
596508
auto sd = dyn_cast<StructDecl>(decl);
597509
if (!sd)

test/ModuleInterface/conformance_suppression.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@
66
// CHECK: #if compiler(>=5.3) && $ConformanceSuppression
77
// CHECK-NEXT: public enum RecollectionOrganization<T> : ~Swift.BitwiseCopyable, Swift.Copyable where T : ~Copyable {
88
// CHECK-NEXT: }
9-
// CHECK-NEXT: #elseif compiler(>=5.3) && $NoncopyableGenerics
10-
// CHECK-NEXT: public enum RecollectionOrganization<T> : Swift.Copyable where T : ~Copyable {
11-
// CHECK-NEXT: }
129
// CHECK-NEXT: #else
13-
// CHECK-NEXT: public enum RecollectionOrganization<T> {
10+
// CHECK-NEXT: public enum RecollectionOrganization<T> : Swift.Copyable where T : ~Copyable {
1411
// CHECK-NEXT: }
1512
// CHECK-NEXT: #endif
1613
public enum RecollectionOrganization<T : ~Copyable> : ~BitwiseCopyable, Copyable {}

test/ModuleInterface/invertible_constraints.swift

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

0 commit comments

Comments
 (0)