Skip to content

Commit 43a41d0

Browse files
committed
use new noncopyable types infrastructure
The infrastructure underpinning the new feature NoncopyableGenerics is mature enough to be used.
1 parent dbc398a commit 43a41d0

Some content is hidden

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

46 files changed

+205
-671
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/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/AST/ASTPrinter.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7701,17 +7701,15 @@ static void getSyntacticInheritanceClause(const ProtocolDecl *proto,
77017701
InvertibleProtocolSet inverses = InvertibleProtocolSet::full();
77027702

77037703
for (auto *inherited : proto->getInheritedProtocols()) {
7704-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
7705-
if (auto ip = inherited->getInvertibleProtocolKind()) {
7706-
inverses.remove(*ip);
7707-
continue;
7708-
}
7704+
if (auto ip = inherited->getInvertibleProtocolKind()) {
7705+
inverses.remove(*ip);
7706+
continue;
7707+
}
77097708

7710-
for (auto ip : InvertibleProtocolSet::full()) {
7711-
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
7712-
if (inherited->inheritsFrom(proto))
7713-
inverses.remove(ip);
7714-
}
7709+
for (auto ip : InvertibleProtocolSet::full()) {
7710+
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
7711+
if (inherited->inheritsFrom(proto))
7712+
inverses.remove(ip);
77157713
}
77167714

77177715
Results.emplace_back(TypeLoc::withoutLoc(inherited->getDeclaredInterfaceType()),
@@ -7720,19 +7718,17 @@ static void getSyntacticInheritanceClause(const ProtocolDecl *proto,
77207718
/*isPreconcurrency=*/false);
77217719
}
77227720

7723-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
7724-
for (auto ip : inverses) {
7725-
InvertibleProtocolSet singleton;
7726-
singleton.insert(ip);
7721+
for (auto ip : inverses) {
7722+
InvertibleProtocolSet singleton;
7723+
singleton.insert(ip);
77277724

7728-
auto inverseTy = ProtocolCompositionType::get(
7729-
ctx, ArrayRef<Type>(), singleton,
7730-
/*hasExplicitAnyObject=*/false);
7731-
Results.emplace_back(TypeLoc::withoutLoc(inverseTy),
7732-
/*isUnchecked=*/false,
7733-
/*isRetroactive=*/false,
7734-
/*isPreconcurrency=*/false);
7735-
}
7725+
auto inverseTy = ProtocolCompositionType::get(
7726+
ctx, ArrayRef<Type>(), singleton,
7727+
/*hasExplicitAnyObject=*/false);
7728+
Results.emplace_back(TypeLoc::withoutLoc(inverseTy),
7729+
/*isUnchecked=*/false,
7730+
/*isRetroactive=*/false,
7731+
/*isPreconcurrency=*/false);
77367732
}
77377733
}
77387734

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

lib/AST/ConformanceLookup.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -398,18 +398,6 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance(
398398
Type type, const AnyMetatypeType *metatypeType, ProtocolDecl *protocol) {
399399
ASTContext &ctx = protocol->getASTContext();
400400

401-
if (!ctx.LangOpts.hasFeature(swift::Feature::NoncopyableGenerics) &&
402-
protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
403-
// Only metatypes of Copyable types are Copyable.
404-
if (metatypeType->getInstanceType()->isNoncopyable()) {
405-
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
406-
} else {
407-
return ProtocolConformanceRef(
408-
ctx.getBuiltinConformance(type, protocol,
409-
BuiltinConformanceKind::Synthesized));
410-
}
411-
}
412-
413401
// All metatypes are Sendable, Copyable, Escapable, and BitwiseCopyable.
414402
if (auto kp = protocol->getKnownProtocolKind()) {
415403
switch (*kp) {
@@ -843,26 +831,6 @@ bool TypeBase::isSendableType() {
843831
/// Copyable and Escapable checking utilities
844832
///
845833

846-
/// Returns true if this type is _always_ Copyable using the legacy check
847-
/// that does not rely on conformances.
848-
static bool alwaysNoncopyable(Type ty) {
849-
if (auto *nominal = ty->getNominalOrBoundGenericNominal())
850-
return !nominal->canBeCopyable();
851-
852-
if (auto *expansion = ty->getAs<PackExpansionType>()) {
853-
return alwaysNoncopyable(expansion->getPatternType());
854-
}
855-
856-
// if any components of the tuple are move-only, then the tuple is move-only.
857-
if (auto *tupl = ty->getCanonicalType()->getAs<TupleType>()) {
858-
for (auto eltTy : tupl->getElementTypes())
859-
if (alwaysNoncopyable(eltTy))
860-
return true;
861-
}
862-
863-
return false; // otherwise, the conservative assumption is it's copyable.
864-
}
865-
866834
/// Preprocesses a type before querying whether it conforms to an invertible.
867835
static CanType preprocessTypeForInvertibleQuery(Type orig) {
868836
Type type = orig;
@@ -912,26 +880,10 @@ static bool conformsToInvertible(CanType type, InvertibleProtocolKind ip) {
912880
/// \returns true iff this type lacks conformance to Copyable.
913881
bool TypeBase::isNoncopyable() {
914882
auto canType = preprocessTypeForInvertibleQuery(this);
915-
auto &ctx = canType->getASTContext();
916-
917-
// for legacy-mode queries that are not dependent on conformances to Copyable
918-
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics))
919-
return alwaysNoncopyable(canType);
920-
921883
return !conformsToInvertible(canType, InvertibleProtocolKind::Copyable);
922884
}
923885

924886
bool TypeBase::isEscapable() {
925887
auto canType = preprocessTypeForInvertibleQuery(this);
926-
auto &ctx = canType->getASTContext();
927-
928-
// for legacy-mode queries that are not dependent on conformances to Escapable
929-
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
930-
if (auto nom = canType.getAnyNominal())
931-
return nom->canBeEscapable();
932-
else
933-
return true;
934-
}
935-
936888
return conformsToInvertible(canType, InvertibleProtocolKind::Escapable);
937889
}

lib/AST/ConformanceLookupTable.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,8 @@ void ConformanceLookupTable::expandImpliedConformances(NominalTypeDecl *nominal,
552552
for (auto *inherited : conformingProtocol->getInheritedProtocols()) {
553553
// Conforming a ~Copyable nominal to a protocol that inherits Copyable
554554
// should not imply a Copyable conformance on the nominal.
555-
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics))
556-
if (inherited->getInvertibleProtocolKind())
557-
continue;
555+
if (inherited->getInvertibleProtocolKind())
556+
continue;
558557

559558
addProtocol(inherited, SourceLoc(), source);
560559
}

0 commit comments

Comments
 (0)