Skip to content

Commit 76c6510

Browse files
authored
Merge pull request #72276 from kavon/ncgenerics-xfails-3
2 parents abad373 + b5840cf commit 76c6510

File tree

107 files changed

+1706
-1358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1706
-1358
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,10 +4392,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
43924392
/// Type if it `isEscapable` instead of using this.
43934393
CanBeInvertible::Result canBeEscapable() const;
43944394

4395-
/// Determine whether this type has ~<target>` stated on
4396-
/// itself, one of its inherited types or `Self` requirements.
4397-
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;
4398-
43994395
// Implement isa/cast/dyncast/etc.
44004396
static bool classof(const Decl *D) {
44014397
return D->getKind() >= DeclKind::First_NominalTypeDecl &&

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7676,9 +7676,6 @@ ERROR(bitwise_copyable_outside_module,none,
76767676
(const ValueDecl *))
76777677

76787678
// -- older ones below --
7679-
ERROR(noncopyable_cannot_conform_to_type, none,
7680-
"noncopyable %kind0 cannot conform to %1",
7681-
(const ValueDecl *, Type))
76827679
ERROR(noncopyable_parameter_requires_ownership, none,
76837680
"parameter of noncopyable type %0 must specify ownership", (Type))
76847681
ERROR(noncopyable_parameter_subscript_unsupported, none,

include/swift/AST/Requirement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ struct InverseRequirement {
270270
static void expandDefaults(ASTContext &ctx,
271271
ArrayRef<Type> gps,
272272
SmallVectorImpl<StructuralRequirement> &result);
273+
274+
void print(raw_ostream &os, const PrintOptions &opts, bool forInherited=false) const;
273275
};
274276

275277
} // end namespace swift

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,6 @@ struct RequireOSSAModules_t {
486486
explicit operator bool() const { return bool(value); }
487487
};
488488

489-
/// Help prevent confusion between different bools being passed around.
490-
struct RequireNoncopyableGenerics_t {
491-
private:
492-
bool value;
493-
public:
494-
RequireNoncopyableGenerics_t(const ASTContext &ctx)
495-
: RequireNoncopyableGenerics_t(ctx.LangOpts) {}
496-
RequireNoncopyableGenerics_t(const LangOptions &opts)
497-
: value(opts.hasFeature(Feature::NoncopyableGenerics)) {}
498-
499-
explicit operator bool() const { return value; }
500-
};
501-
502489
class ModuleInterfaceCheckerImpl: public ModuleInterfaceChecker {
503490
friend class ModuleInterfaceLoader;
504491
ASTContext &Ctx;
@@ -507,26 +494,22 @@ class ModuleInterfaceCheckerImpl: public ModuleInterfaceChecker {
507494
std::string BackupInterfaceDir;
508495
ModuleInterfaceLoaderOptions Opts;
509496
RequireOSSAModules_t RequiresOSSAModules;
510-
RequireNoncopyableGenerics_t RequireNCGenerics;
511497

512498
public:
513499
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx, StringRef cacheDir,
514500
StringRef prebuiltCacheDir,
515501
StringRef BackupInterfaceDir,
516502
ModuleInterfaceLoaderOptions opts,
517-
RequireOSSAModules_t requiresOSSAModules,
518-
RequireNoncopyableGenerics_t requireNCGenerics)
503+
RequireOSSAModules_t requiresOSSAModules)
519504
: Ctx(Ctx), CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
520505
BackupInterfaceDir(BackupInterfaceDir),
521-
Opts(opts), RequiresOSSAModules(requiresOSSAModules),
522-
RequireNCGenerics(requireNCGenerics) {}
506+
Opts(opts), RequiresOSSAModules(requiresOSSAModules) {}
523507
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx, StringRef cacheDir,
524508
StringRef prebuiltCacheDir,
525509
ModuleInterfaceLoaderOptions opts,
526-
RequireOSSAModules_t requiresOSSAModules,
527-
RequireNoncopyableGenerics_t requireNCGenerics):
510+
RequireOSSAModules_t requiresOSSAModules):
528511
ModuleInterfaceCheckerImpl(Ctx, cacheDir, prebuiltCacheDir, StringRef(),
529-
opts, requiresOSSAModules, requireNCGenerics) {}
512+
opts, requiresOSSAModules) {}
530513
std::vector<std::string>
531514
getCompiledModuleCandidatesForInterface(StringRef moduleName,
532515
StringRef interfacePath) override;
@@ -602,7 +585,6 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
602585
bool SerializeDependencyHashes, bool TrackSystemDependencies,
603586
ModuleInterfaceLoaderOptions Opts,
604587
RequireOSSAModules_t RequireOSSAModules,
605-
RequireNoncopyableGenerics_t RequireNCGenerics,
606588
bool silenceInterfaceDiagnostics);
607589

608590
/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as
@@ -657,8 +639,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
657639
const ClangImporterOptions &clangImporterOpts,
658640
const CASOptions &casOpts,
659641
bool suppressRemarks,
660-
RequireOSSAModules_t requireOSSAModules,
661-
RequireNoncopyableGenerics_t requireNCGenerics);
642+
RequireOSSAModules_t requireOSSAModules);
662643
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
663644
SwiftInterfaceInfo &interfaceInfo,
664645
StringRef interfacePath,
@@ -671,8 +652,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
671652
ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent,
672653
StringRef moduleCachePath, StringRef prebuiltCachePath,
673654
StringRef backupModuleInterfaceDir, bool serializeDependencyHashes,
674-
bool trackSystemDependencies, RequireOSSAModules_t requireOSSAModules,
675-
RequireNoncopyableGenerics_t requireNCGenerics);
655+
bool trackSystemDependencies, RequireOSSAModules_t requireOSSAModules);
676656

677657
template<typename ...ArgTypes>
678658
static InFlightDiagnostic diagnose(StringRef interfacePath,

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class SerializedModuleLoaderBase : public ModuleLoader {
182182
ModuleLoadingBehavior transitiveBehavior,
183183
bool isFramework,
184184
bool isRequiredOSSAModules,
185-
bool isRequiredNoncopyableGenerics,
186185
StringRef SDKName,
187186
StringRef packageName,
188187
llvm::vfs::FileSystem *fileSystem,
@@ -212,7 +211,6 @@ class SerializedModuleLoaderBase : public ModuleLoader {
212211
bool isFramework);
213212

214213
bool isRequiredOSSAModules() const;
215-
bool isRequiredNoncopyableGenerics() const;
216214

217215
/// Check whether the module with a given name can be imported without
218216
/// importing it.

include/swift/Serialization/Validation.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ enum class Status {
8686
/// The module file was built with a different SDK than the one in use
8787
/// to build the client.
8888
SDKMismatch,
89-
90-
/// The module file was built with a different NoncopyableGenerics feature
91-
/// mode than the compiler loading it.
92-
NoncopyableGenericsMismatch,
9389
};
9490

9591
/// Returns the string for the Status enum.
@@ -262,8 +258,6 @@ struct SearchPath {
262258
/// refers directly into this buffer.
263259
/// \param requiresOSSAModules If true, necessitates the module to be
264260
/// compiled with -enable-ossa-modules.
265-
/// \param requiresNoncopyableGenerics requires the module to have been built
266-
/// with the feature \c NoncopyableGenerics enabled.
267261
/// \param requiredSDK If not empty, only accept modules built with
268262
/// a compatible SDK. The StringRef represents the canonical SDK name.
269263
/// \param[out] extendedInfo If present, will be populated with additional
@@ -272,7 +266,7 @@ struct SearchPath {
272266
/// \param[out] dependencies If present, will be populated with list of
273267
/// input files the module depends on, if present in INPUT_BLOCK.
274268
ValidationInfo validateSerializedAST(
275-
StringRef data, bool requiresOSSAModules, bool requiresNoncopyableGenerics,
269+
StringRef data, bool requiresOSSAModules,
276270
StringRef requiredSDK,
277271
ExtendedValidationInfo *extendedInfo = nullptr,
278272
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies =

lib/APIDigester/ModuleAnalyzerNodes.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static PrintOptions getTypePrintOpts(CheckerOptions CheckerOpts) {
1717
PrintOptions Opts;
1818
Opts.SynthesizeSugarOnTypes = true;
1919
Opts.UseOriginallyDefinedInModuleNames = true;
20+
Opts.PrintInverseRequirements = true; // Only inverses are relevant for ABI stability
2021
if (!CheckerOpts.Migrator) {
2122
// We should always print fully qualified type names for checking either
2223
// API or ABI stability.
@@ -1222,8 +1223,15 @@ Requirement getCanonicalRequirement(Requirement &Req) {
12221223
}
12231224
}
12241225

1226+
// Get an inverse requirement with the subject type canonicalized.
1227+
InverseRequirement getCanonicalInverseRequirement(InverseRequirement &Req) {
1228+
return {Req.subject->getCanonicalType(), Req.protocol, Req.loc};
1229+
}
1230+
12251231
static
1226-
StringRef printGenericSignature(SDKContext &Ctx, ArrayRef<Requirement> AllReqs,
1232+
StringRef printGenericSignature(SDKContext &Ctx,
1233+
ArrayRef<Requirement> AllReqs,
1234+
ArrayRef<InverseRequirement> Inverses,
12271235
bool Canonical) {
12281236
llvm::SmallString<32> Result;
12291237
llvm::raw_svector_ostream OS(Result);
@@ -1243,6 +1251,17 @@ StringRef printGenericSignature(SDKContext &Ctx, ArrayRef<Requirement> AllReqs,
12431251
else
12441252
Req.print(OS, Opts);
12451253
}
1254+
for (auto Inv: Inverses) {
1255+
if (!First) {
1256+
OS << ", ";
1257+
} else {
1258+
First = false;
1259+
}
1260+
if (Canonical)
1261+
getCanonicalInverseRequirement(Inv).print(OS, Opts);
1262+
else
1263+
Inv.print(OS, Opts);
1264+
}
12461265
OS << ">";
12471266
return Ctx.buffer(OS.str());
12481267
}
@@ -1251,8 +1270,10 @@ static StringRef printGenericSignature(SDKContext &Ctx, Decl *D, bool Canonical)
12511270
llvm::SmallString<32> Result;
12521271
llvm::raw_svector_ostream OS(Result);
12531272
if (auto *PD = dyn_cast<ProtocolDecl>(D)) {
1254-
return printGenericSignature(Ctx, PD->getRequirementSignature().getRequirements(),
1255-
Canonical);
1273+
SmallVector<Requirement, 2> reqs;
1274+
SmallVector<InverseRequirement, 2> inverses;
1275+
PD->getRequirementSignature().getRequirementsWithInverses(PD, reqs, inverses);
1276+
return printGenericSignature(Ctx, reqs, inverses, Canonical);
12561277
}
12571278
PrintOptions Opts = getTypePrintOpts(Ctx.getOpts());
12581279
if (auto *GC = D->getAsGenericContext()) {
@@ -1269,7 +1290,7 @@ static StringRef printGenericSignature(SDKContext &Ctx, Decl *D, bool Canonical)
12691290

12701291
static
12711292
StringRef printGenericSignature(SDKContext &Ctx, ProtocolConformance *Conf, bool Canonical) {
1272-
return printGenericSignature(Ctx, Conf->getConditionalRequirements(), Canonical);
1293+
return printGenericSignature(Ctx, Conf->getConditionalRequirements(), {}, Canonical);
12731294
}
12741295

12751296
static std::optional<uint8_t>

lib/AST/ASTPrinter.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7467,6 +7467,13 @@ void Requirement::print(ASTPrinter &printer, const PrintOptions &opts) const {
74677467
PrintAST(printer, opts).printRequirement(*this);
74687468
}
74697469

7470+
void InverseRequirement::print(raw_ostream &os,
7471+
const PrintOptions &opts,
7472+
bool forInherited) const {
7473+
StreamPrinter printer(os);
7474+
PrintAST(printer, opts).printRequirement(*this, forInherited);
7475+
}
7476+
74707477
std::string GenericSignatureImpl::getAsString() const {
74717478
return GenericSignature(const_cast<GenericSignatureImpl *>(this))
74727479
.getAsString();
@@ -7770,17 +7777,15 @@ static void getSyntacticInheritanceClause(const ProtocolDecl *proto,
77707777
InvertibleProtocolSet inverses = InvertibleProtocolSet::full();
77717778

77727779
for (auto *inherited : proto->getInheritedProtocols()) {
7773-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
7774-
if (auto ip = inherited->getInvertibleProtocolKind()) {
7775-
inverses.remove(*ip);
7776-
continue;
7777-
}
7780+
if (auto ip = inherited->getInvertibleProtocolKind()) {
7781+
inverses.remove(*ip);
7782+
continue;
7783+
}
77787784

7779-
for (auto ip : InvertibleProtocolSet::full()) {
7780-
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
7781-
if (inherited->inheritsFrom(proto))
7782-
inverses.remove(ip);
7783-
}
7785+
for (auto ip : InvertibleProtocolSet::full()) {
7786+
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
7787+
if (inherited->inheritsFrom(proto))
7788+
inverses.remove(ip);
77847789
}
77857790

77867791
Results.emplace_back(TypeLoc::withoutLoc(inherited->getDeclaredInterfaceType()),
@@ -7789,19 +7794,17 @@ static void getSyntacticInheritanceClause(const ProtocolDecl *proto,
77897794
/*isPreconcurrency=*/false);
77907795
}
77917796

7792-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
7793-
for (auto ip : inverses) {
7794-
InvertibleProtocolSet singleton;
7795-
singleton.insert(ip);
7797+
for (auto ip : inverses) {
7798+
InvertibleProtocolSet singleton;
7799+
singleton.insert(ip);
77967800

7797-
auto inverseTy = ProtocolCompositionType::get(
7798-
ctx, ArrayRef<Type>(), singleton,
7799-
/*hasExplicitAnyObject=*/false);
7800-
Results.emplace_back(TypeLoc::withoutLoc(inverseTy),
7801-
/*isUnchecked=*/false,
7802-
/*isRetroactive=*/false,
7803-
/*isPreconcurrency=*/false);
7804-
}
7801+
auto inverseTy = ProtocolCompositionType::get(
7802+
ctx, ArrayRef<Type>(), singleton,
7803+
/*hasExplicitAnyObject=*/false);
7804+
Results.emplace_back(TypeLoc::withoutLoc(inverseTy),
7805+
/*isUnchecked=*/false,
7806+
/*isRetroactive=*/false,
7807+
/*isPreconcurrency=*/false);
78057808
}
78067809
}
78077810

lib/AST/Builtins.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,6 @@ struct CollectGenericParams {
296296
auto protocolType = synthesizeType(SC, conf.Protocol);
297297
Requirement req = {RequirementKind::Conformance, type, protocolType};
298298

299-
// If it's an invertible protocol and NoncopyableGenerics is disabled
300-
// then skip the requirement.
301-
if (req.getProtocolDecl()->getInvertibleProtocolKind())
302-
if (!SC.Context.LangOpts.hasFeature(Feature::NoncopyableGenerics))
303-
return;
304-
305299
AddedRequirements.push_back(req);
306300
}
307301

@@ -736,13 +730,6 @@ namespace {
736730
Requirement req(RequirementKind::Conformance,
737731
generator.build(*this),
738732
proto->getDeclaredInterfaceType());
739-
740-
// If it's an invertible protocol and NoncopyableGenerics is disabled
741-
// then skip the requirement.
742-
if (req.getProtocolDecl()->getInvertibleProtocolKind())
743-
if (!Context.LangOpts.hasFeature(Feature::NoncopyableGenerics))
744-
return;
745-
746733
addedRequirements.push_back(req);
747734
}
748735

0 commit comments

Comments
 (0)