mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
- `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
a static_cast on rebranch because `Optional` is now a `std::optional`.
This commit is contained in:
@@ -1681,12 +1681,12 @@ ProtocolConformanceRef ModuleDecl::lookupConformance(Type type,
|
||||
ProtocolDecl *protocol,
|
||||
bool allowMissing) {
|
||||
// If we are recursively checking for implicit conformance of a nominal
|
||||
// type to Sendable, fail without evaluating this request. This
|
||||
// type to a KnownProtocol, fail without evaluating this request. This
|
||||
// squashes cycles.
|
||||
LookupConformanceInModuleRequest request{{this, type, protocol}};
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable)) {
|
||||
if (auto kp = protocol->getKnownProtocolKind()) {
|
||||
if (auto nominal = type->getAnyNominal()) {
|
||||
GetImplicitSendableRequest icvRequest{nominal};
|
||||
ImplicitKnownProtocolConformanceRequest icvRequest{nominal, *kp};
|
||||
if (getASTContext().evaluator.hasActiveRequest(icvRequest) ||
|
||||
getASTContext().evaluator.hasActiveRequest(request))
|
||||
return ProtocolConformanceRef::forInvalid();
|
||||
@@ -1795,16 +1795,21 @@ static ProtocolConformanceRef getBuiltinMetaTypeTypeConformance(
|
||||
Type type, const AnyMetatypeType *metatypeType, ProtocolDecl *protocol) {
|
||||
ASTContext &ctx = protocol->getASTContext();
|
||||
|
||||
// Only metatypes of Copyable types are Copyable.
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable) &&
|
||||
!metatypeType->getInstanceType()->isNoncopyable()) {
|
||||
return ProtocolConformanceRef(
|
||||
ctx.getBuiltinConformance(type, protocol,
|
||||
BuiltinConformanceKind::Synthesized));
|
||||
if (!ctx.LangOpts.hasFeature(swift::Feature::NoncopyableGenerics) &&
|
||||
protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
|
||||
// Only metatypes of Copyable types are Copyable.
|
||||
if (metatypeType->getInstanceType()->isNoncopyable()) {
|
||||
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
|
||||
} else {
|
||||
return ProtocolConformanceRef(
|
||||
ctx.getBuiltinConformance(type, protocol,
|
||||
BuiltinConformanceKind::Synthesized));
|
||||
}
|
||||
}
|
||||
|
||||
// All metatypes are Sendable
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable)) {
|
||||
// All metatypes are Sendable and Copyable
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable) ||
|
||||
protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
|
||||
return ProtocolConformanceRef(
|
||||
ctx.getBuiltinConformance(type, protocol,
|
||||
BuiltinConformanceKind::Synthesized));
|
||||
@@ -1876,9 +1881,10 @@ LookupConformanceInModuleRequest::evaluate(
|
||||
// constraint and the superclass conforms to the protocol.
|
||||
if (auto archetype = type->getAs<ArchetypeType>()) {
|
||||
|
||||
// All archetypes conform to Copyable since they represent a generic.
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable))
|
||||
return ProtocolConformanceRef(protocol);
|
||||
// Without noncopyable generics, all archetypes are Copyable
|
||||
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics))
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable))
|
||||
return ProtocolConformanceRef(protocol);
|
||||
|
||||
// The generic signature builder drops conformance requirements that are made
|
||||
// redundant by a superclass requirement, so check for a concrete
|
||||
@@ -1972,7 +1978,8 @@ LookupConformanceInModuleRequest::evaluate(
|
||||
if (!nominal->lookupConformance(protocol, conformances)) {
|
||||
if (protocol->isSpecificProtocol(KnownProtocolKind::Sendable)) {
|
||||
// Try to infer Sendable conformance.
|
||||
GetImplicitSendableRequest cvRequest{nominal};
|
||||
ImplicitKnownProtocolConformanceRequest
|
||||
cvRequest{nominal, KnownProtocolKind::Sendable};
|
||||
if (auto conformance = evaluateOrDefault(
|
||||
ctx.evaluator, cvRequest, nullptr)) {
|
||||
conformances.clear();
|
||||
@@ -2001,16 +2008,27 @@ LookupConformanceInModuleRequest::evaluate(
|
||||
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
|
||||
}
|
||||
} else if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
|
||||
// Only move-only nominals are not Copyable
|
||||
if (nominal->isMoveOnly()) {
|
||||
return ProtocolConformanceRef::forInvalid();
|
||||
|
||||
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics)) {
|
||||
// Return an abstract conformance to maintain legacy compatability.
|
||||
// We only need to do this until we are properly dealing with or
|
||||
// omitting Copyable conformances in modules/interfaces.
|
||||
|
||||
if (nominal->isNoncopyable())
|
||||
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
|
||||
else
|
||||
return ProtocolConformanceRef(protocol);
|
||||
}
|
||||
|
||||
// Try to infer Copyable conformance.
|
||||
ImplicitKnownProtocolConformanceRequest
|
||||
cvRequest{nominal, KnownProtocolKind::Copyable};
|
||||
if (auto conformance = evaluateOrDefault(
|
||||
ctx.evaluator, cvRequest, nullptr)) {
|
||||
conformances.clear();
|
||||
conformances.push_back(conformance);
|
||||
} else {
|
||||
// Specifically do not create a concrete conformance to Copyable. At
|
||||
// this stage, we don't even want Copyable to appear in swiftinterface
|
||||
// files, which will happen for a marker protocol that's registered
|
||||
// in a nominal type's conformance table. We can reconsider this
|
||||
// decision later once there's a clearer picture of noncopyable generics
|
||||
return ProtocolConformanceRef(protocol);
|
||||
return ProtocolConformanceRef::forMissingOrInvalid(type, protocol);
|
||||
}
|
||||
} else {
|
||||
// Was unable to infer the missing conformance.
|
||||
|
||||
Reference in New Issue
Block a user