mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Implement customizable Sendable conformance diagnostics.
Rework Sendable checking to be completely based on "missing" conformances, so that we can individually diagnose missing Sendable conformances based on both the module in which the conformance check happened as well as where the type was declared. The basic rules here are to only diagnose if either the module where the non-Sendable type was declared or the module where it was checked was compiled with a mode that consistently diagnoses `Sendable`, either by virtue of being Swift 6 or because `-warn-concurrency` was provided on the command line. And have that diagnostic be an error in Swift 6 or warning in Swift 5.x. There is much tuning to be done here.
This commit is contained in:
@@ -1665,23 +1665,30 @@ SourceLoc swift::extractNearestSourceLoc(const ProtocolConformanceRef conformanc
|
||||
}
|
||||
|
||||
bool ProtocolConformanceRef::hasMissingConformance(ModuleDecl *module) const {
|
||||
return forEachMissingConformance(module,
|
||||
[](BuiltinProtocolConformance *builtin) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
bool ProtocolConformanceRef::forEachMissingConformance(
|
||||
ModuleDecl *module,
|
||||
llvm::function_ref<bool(BuiltinProtocolConformance *missing)> fn) const {
|
||||
if (!isConcrete())
|
||||
return false;
|
||||
|
||||
// Is this a missing Sendable conformance?
|
||||
const ProtocolConformance *concreteConf = getConcrete();
|
||||
const RootProtocolConformance *rootConf = concreteConf->getRootConformance();
|
||||
// Is this a missing conformance?
|
||||
ProtocolConformance *concreteConf = getConcrete();
|
||||
RootProtocolConformance *rootConf = concreteConf->getRootConformance();
|
||||
if (auto builtinConformance = dyn_cast<BuiltinProtocolConformance>(rootConf)){
|
||||
if (builtinConformance->isMissing() && builtinConformance->getProtocol()->isSpecificProtocol(
|
||||
KnownProtocolKind::Sendable)) {
|
||||
if (builtinConformance->isMissing() && fn(builtinConformance))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check conformances that are part of this conformance.
|
||||
auto subMap = concreteConf->getSubstitutions(module);
|
||||
for (auto conformance : subMap.getConformances()) {
|
||||
if (conformance.hasMissingConformance(module))
|
||||
if (conformance.forEachMissingConformance(module, fn))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user