Skip to content

Use new noncopyable types infrastructure #72276

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
merged 29 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
71de500
Test: update `inverse_copyable_requirement.swift`
kavon Mar 12, 2024
8f2ed59
un-XFAIL `type_in_function.swift`
kavon Mar 12, 2024
af933c6
Sema: remove TypeResolver::diagnoseMoveOnlyGeneric
kavon Mar 12, 2024
149c052
use new noncopyable types infrastructure
kavon Mar 13, 2024
84a44f8
Sema: remove more unneeded legacy code
kavon Mar 13, 2024
2a51f10
more enablement of code
kavon Mar 13, 2024
2d065bb
Features: Sendable doesn't use NoncopyableGenerics
kavon Mar 13, 2024
341ff24
Test: fold together similar NCGenerics tests
kavon Mar 13, 2024
69e8263
Test: update mangling of non-ABI shared symbols
kavon Mar 13, 2024
8a13ced
NCGenerics: claim to have Escapable runtime info.
kavon Mar 13, 2024
102ccbc
Test: updates for NoncopyableGenerics
kavon Mar 14, 2024
47676b2
Test: fix a number of NCGenerics-specific tests
kavon Mar 14, 2024
2951162
Test: disable `move-only-cxx-value-type.swift`
kavon Mar 14, 2024
9ae263c
Test: disable `lazy_parsing.swift`
kavon Mar 14, 2024
d73dfe9
Test: update `xref-extensions-counters.swift`
kavon Mar 14, 2024
48beac2
Test: misc. test updates for NoncopyableGenerics
kavon Mar 14, 2024
8f97b7f
Test: update for NoncopyableGenerics
kavon Mar 14, 2024
ae862d3
Test: NCGenerics update `generic_classes_objc.sil`
kavon Mar 14, 2024
53fb8c3
XFAIL test for minor issue
kavon Mar 14, 2024
bb51be7
Test: update for NoncopyableGenerics infra.
kavon Mar 14, 2024
55edc30
NFC: expose an `InverseRequirement::print`
kavon Mar 14, 2024
3b02f30
APIDigester: Stringify inverses in GenericSigs
kavon Mar 14, 2024
11220bb
ABI Tests: include Copyable/Escapable in baseline
kavon Mar 14, 2024
b40611f
Deserialization: handle bogus type in BuiltinConfs
kavon Mar 14, 2024
cc709d6
Test: update baseline for NoncopyableGenerics
kavon Mar 15, 2024
f1b222d
XFAIL test with a newly revealed mistake
kavon Mar 15, 2024
f18c7f9
Test: fix and enable test
kavon Mar 15, 2024
ca25edb
XFAIL `parse_stdlib.sil` temporarily
kavon Mar 15, 2024
b5840cf
NCGenerics: workaround lldb bug
kavon Mar 15, 2024
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/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4392,10 +4392,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// Type if it `isEscapable` instead of using this.
CanBeInvertible::Result canBeEscapable() const;

/// Determine whether this type has ~<target>` stated on
/// itself, one of its inherited types or `Self` requirements.
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
return D->getKind() >= DeclKind::First_NominalTypeDecl &&
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7676,9 +7676,6 @@ ERROR(bitwise_copyable_outside_module,none,
(const ValueDecl *))

// -- older ones below --
ERROR(noncopyable_cannot_conform_to_type, none,
"noncopyable %kind0 cannot conform to %1",
(const ValueDecl *, Type))
ERROR(noncopyable_parameter_requires_ownership, none,
"parameter of noncopyable type %0 must specify ownership", (Type))
ERROR(noncopyable_parameter_subscript_unsupported, none,
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/Requirement.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ struct InverseRequirement {
static void expandDefaults(ASTContext &ctx,
ArrayRef<Type> gps,
SmallVectorImpl<StructuralRequirement> &result);

void print(raw_ostream &os, const PrintOptions &opts, bool forInherited=false) const;
};

} // end namespace swift
Expand Down
32 changes: 6 additions & 26 deletions include/swift/Frontend/ModuleInterfaceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,6 @@ struct RequireOSSAModules_t {
explicit operator bool() const { return bool(value); }
};

/// Help prevent confusion between different bools being passed around.
struct RequireNoncopyableGenerics_t {
private:
bool value;
public:
RequireNoncopyableGenerics_t(const ASTContext &ctx)
: RequireNoncopyableGenerics_t(ctx.LangOpts) {}
RequireNoncopyableGenerics_t(const LangOptions &opts)
: value(opts.hasFeature(Feature::NoncopyableGenerics)) {}

explicit operator bool() const { return value; }
};

class ModuleInterfaceCheckerImpl: public ModuleInterfaceChecker {
friend class ModuleInterfaceLoader;
ASTContext &Ctx;
Expand All @@ -507,26 +494,22 @@ class ModuleInterfaceCheckerImpl: public ModuleInterfaceChecker {
std::string BackupInterfaceDir;
ModuleInterfaceLoaderOptions Opts;
RequireOSSAModules_t RequiresOSSAModules;
RequireNoncopyableGenerics_t RequireNCGenerics;

public:
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx, StringRef cacheDir,
StringRef prebuiltCacheDir,
StringRef BackupInterfaceDir,
ModuleInterfaceLoaderOptions opts,
RequireOSSAModules_t requiresOSSAModules,
RequireNoncopyableGenerics_t requireNCGenerics)
RequireOSSAModules_t requiresOSSAModules)
: Ctx(Ctx), CacheDir(cacheDir), PrebuiltCacheDir(prebuiltCacheDir),
BackupInterfaceDir(BackupInterfaceDir),
Opts(opts), RequiresOSSAModules(requiresOSSAModules),
RequireNCGenerics(requireNCGenerics) {}
Opts(opts), RequiresOSSAModules(requiresOSSAModules) {}
explicit ModuleInterfaceCheckerImpl(ASTContext &Ctx, StringRef cacheDir,
StringRef prebuiltCacheDir,
ModuleInterfaceLoaderOptions opts,
RequireOSSAModules_t requiresOSSAModules,
RequireNoncopyableGenerics_t requireNCGenerics):
RequireOSSAModules_t requiresOSSAModules):
ModuleInterfaceCheckerImpl(Ctx, cacheDir, prebuiltCacheDir, StringRef(),
opts, requiresOSSAModules, requireNCGenerics) {}
opts, requiresOSSAModules) {}
std::vector<std::string>
getCompiledModuleCandidatesForInterface(StringRef moduleName,
StringRef interfacePath) override;
Expand Down Expand Up @@ -602,7 +585,6 @@ class ModuleInterfaceLoader : public SerializedModuleLoaderBase {
bool SerializeDependencyHashes, bool TrackSystemDependencies,
ModuleInterfaceLoaderOptions Opts,
RequireOSSAModules_t RequireOSSAModules,
RequireNoncopyableGenerics_t RequireNCGenerics,
bool silenceInterfaceDiagnostics);

/// Unconditionally build \p InPath (a swiftinterface file) to \p OutPath (as
Expand Down Expand Up @@ -657,8 +639,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
const ClangImporterOptions &clangImporterOpts,
const CASOptions &casOpts,
bool suppressRemarks,
RequireOSSAModules_t requireOSSAModules,
RequireNoncopyableGenerics_t requireNCGenerics);
RequireOSSAModules_t requireOSSAModules);
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
SwiftInterfaceInfo &interfaceInfo,
StringRef interfacePath,
Expand All @@ -671,8 +652,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
ModuleInterfaceLoaderOptions LoaderOpts, bool buildModuleCacheDirIfAbsent,
StringRef moduleCachePath, StringRef prebuiltCachePath,
StringRef backupModuleInterfaceDir, bool serializeDependencyHashes,
bool trackSystemDependencies, RequireOSSAModules_t requireOSSAModules,
RequireNoncopyableGenerics_t requireNCGenerics);
bool trackSystemDependencies, RequireOSSAModules_t requireOSSAModules);

template<typename ...ArgTypes>
static InFlightDiagnostic diagnose(StringRef interfacePath,
Expand Down
2 changes: 0 additions & 2 deletions include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class SerializedModuleLoaderBase : public ModuleLoader {
ModuleLoadingBehavior transitiveBehavior,
bool isFramework,
bool isRequiredOSSAModules,
bool isRequiredNoncopyableGenerics,
StringRef SDKName,
StringRef packageName,
llvm::vfs::FileSystem *fileSystem,
Expand Down Expand Up @@ -212,7 +211,6 @@ class SerializedModuleLoaderBase : public ModuleLoader {
bool isFramework);

bool isRequiredOSSAModules() const;
bool isRequiredNoncopyableGenerics() const;

/// Check whether the module with a given name can be imported without
/// importing it.
Expand Down
8 changes: 1 addition & 7 deletions include/swift/Serialization/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ enum class Status {
/// The module file was built with a different SDK than the one in use
/// to build the client.
SDKMismatch,

/// The module file was built with a different NoncopyableGenerics feature
/// mode than the compiler loading it.
NoncopyableGenericsMismatch,
};

/// Returns the string for the Status enum.
Expand Down Expand Up @@ -262,8 +258,6 @@ struct SearchPath {
/// refers directly into this buffer.
/// \param requiresOSSAModules If true, necessitates the module to be
/// compiled with -enable-ossa-modules.
/// \param requiresNoncopyableGenerics requires the module to have been built
/// with the feature \c NoncopyableGenerics enabled.
/// \param requiredSDK If not empty, only accept modules built with
/// a compatible SDK. The StringRef represents the canonical SDK name.
/// \param[out] extendedInfo If present, will be populated with additional
Expand All @@ -272,7 +266,7 @@ struct SearchPath {
/// \param[out] dependencies If present, will be populated with list of
/// input files the module depends on, if present in INPUT_BLOCK.
ValidationInfo validateSerializedAST(
StringRef data, bool requiresOSSAModules, bool requiresNoncopyableGenerics,
StringRef data, bool requiresOSSAModules,
StringRef requiredSDK,
ExtendedValidationInfo *extendedInfo = nullptr,
SmallVectorImpl<SerializationOptions::FileDependency> *dependencies =
Expand Down
29 changes: 25 additions & 4 deletions lib/APIDigester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static PrintOptions getTypePrintOpts(CheckerOptions CheckerOpts) {
PrintOptions Opts;
Opts.SynthesizeSugarOnTypes = true;
Opts.UseOriginallyDefinedInModuleNames = true;
Opts.PrintInverseRequirements = true; // Only inverses are relevant for ABI stability
if (!CheckerOpts.Migrator) {
// We should always print fully qualified type names for checking either
// API or ABI stability.
Expand Down Expand Up @@ -1222,8 +1223,15 @@ Requirement getCanonicalRequirement(Requirement &Req) {
}
}

// Get an inverse requirement with the subject type canonicalized.
InverseRequirement getCanonicalInverseRequirement(InverseRequirement &Req) {
return {Req.subject->getCanonicalType(), Req.protocol, Req.loc};
}

static
StringRef printGenericSignature(SDKContext &Ctx, ArrayRef<Requirement> AllReqs,
StringRef printGenericSignature(SDKContext &Ctx,
ArrayRef<Requirement> AllReqs,
ArrayRef<InverseRequirement> Inverses,
bool Canonical) {
llvm::SmallString<32> Result;
llvm::raw_svector_ostream OS(Result);
Expand All @@ -1243,6 +1251,17 @@ StringRef printGenericSignature(SDKContext &Ctx, ArrayRef<Requirement> AllReqs,
else
Req.print(OS, Opts);
}
for (auto Inv: Inverses) {
if (!First) {
OS << ", ";
} else {
First = false;
}
if (Canonical)
getCanonicalInverseRequirement(Inv).print(OS, Opts);
else
Inv.print(OS, Opts);
}
OS << ">";
return Ctx.buffer(OS.str());
}
Expand All @@ -1251,8 +1270,10 @@ static StringRef printGenericSignature(SDKContext &Ctx, Decl *D, bool Canonical)
llvm::SmallString<32> Result;
llvm::raw_svector_ostream OS(Result);
if (auto *PD = dyn_cast<ProtocolDecl>(D)) {
return printGenericSignature(Ctx, PD->getRequirementSignature().getRequirements(),
Canonical);
SmallVector<Requirement, 2> reqs;
SmallVector<InverseRequirement, 2> inverses;
PD->getRequirementSignature().getRequirementsWithInverses(PD, reqs, inverses);
return printGenericSignature(Ctx, reqs, inverses, Canonical);
}
PrintOptions Opts = getTypePrintOpts(Ctx.getOpts());
if (auto *GC = D->getAsGenericContext()) {
Expand All @@ -1269,7 +1290,7 @@ static StringRef printGenericSignature(SDKContext &Ctx, Decl *D, bool Canonical)

static
StringRef printGenericSignature(SDKContext &Ctx, ProtocolConformance *Conf, bool Canonical) {
return printGenericSignature(Ctx, Conf->getConditionalRequirements(), Canonical);
return printGenericSignature(Ctx, Conf->getConditionalRequirements(), {}, Canonical);
}

static std::optional<uint8_t>
Expand Down
47 changes: 25 additions & 22 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7424,6 +7424,13 @@ void Requirement::print(ASTPrinter &printer, const PrintOptions &opts) const {
PrintAST(printer, opts).printRequirement(*this);
}

void InverseRequirement::print(raw_ostream &os,
const PrintOptions &opts,
bool forInherited) const {
StreamPrinter printer(os);
PrintAST(printer, opts).printRequirement(*this, forInherited);
}

std::string GenericSignatureImpl::getAsString() const {
return GenericSignature(const_cast<GenericSignatureImpl *>(this))
.getAsString();
Expand Down Expand Up @@ -7727,17 +7734,15 @@ static void getSyntacticInheritanceClause(const ProtocolDecl *proto,
InvertibleProtocolSet inverses = InvertibleProtocolSet::full();

for (auto *inherited : proto->getInheritedProtocols()) {
if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
if (auto ip = inherited->getInvertibleProtocolKind()) {
inverses.remove(*ip);
continue;
}
if (auto ip = inherited->getInvertibleProtocolKind()) {
inverses.remove(*ip);
continue;
}

for (auto ip : InvertibleProtocolSet::full()) {
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
if (inherited->inheritsFrom(proto))
inverses.remove(ip);
}
for (auto ip : InvertibleProtocolSet::full()) {
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));
if (inherited->inheritsFrom(proto))
inverses.remove(ip);
}

Results.emplace_back(TypeLoc::withoutLoc(inherited->getDeclaredInterfaceType()),
Expand All @@ -7746,19 +7751,17 @@ static void getSyntacticInheritanceClause(const ProtocolDecl *proto,
/*isPreconcurrency=*/false);
}

if (ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
for (auto ip : inverses) {
InvertibleProtocolSet singleton;
singleton.insert(ip);
for (auto ip : inverses) {
InvertibleProtocolSet singleton;
singleton.insert(ip);

auto inverseTy = ProtocolCompositionType::get(
ctx, ArrayRef<Type>(), singleton,
/*hasExplicitAnyObject=*/false);
Results.emplace_back(TypeLoc::withoutLoc(inverseTy),
/*isUnchecked=*/false,
/*isRetroactive=*/false,
/*isPreconcurrency=*/false);
}
auto inverseTy = ProtocolCompositionType::get(
ctx, ArrayRef<Type>(), singleton,
/*hasExplicitAnyObject=*/false);
Results.emplace_back(TypeLoc::withoutLoc(inverseTy),
/*isUnchecked=*/false,
/*isRetroactive=*/false,
/*isPreconcurrency=*/false);
}
}

Expand Down
13 changes: 0 additions & 13 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,6 @@ struct CollectGenericParams {
auto protocolType = synthesizeType(SC, conf.Protocol);
Requirement req = {RequirementKind::Conformance, type, protocolType};

// If it's an invertible protocol and NoncopyableGenerics is disabled
// then skip the requirement.
if (req.getProtocolDecl()->getInvertibleProtocolKind())
if (!SC.Context.LangOpts.hasFeature(Feature::NoncopyableGenerics))
return;

AddedRequirements.push_back(req);
}

Expand Down Expand Up @@ -736,13 +730,6 @@ namespace {
Requirement req(RequirementKind::Conformance,
generator.build(*this),
proto->getDeclaredInterfaceType());

// If it's an invertible protocol and NoncopyableGenerics is disabled
// then skip the requirement.
if (req.getProtocolDecl()->getInvertibleProtocolKind())
if (!Context.LangOpts.hasFeature(Feature::NoncopyableGenerics))
return;

addedRequirements.push_back(req);
}

Expand Down
Loading