mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +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:
@@ -501,6 +501,9 @@ public:
|
||||
/// .swiftsourceinfo file (ie. the file exists and has been read).
|
||||
bool hasSourceInfo() const { return Core->hasSourceInfo(); }
|
||||
|
||||
/// \c true if this module was built with complete checking for concurrency.
|
||||
bool isConcurrencyChecked() const { return Core->isConcurrencyChecked(); }
|
||||
|
||||
/// Associates this module file with the AST node representing it.
|
||||
///
|
||||
/// Checks that the file is compatible with the AST module it's being loaded
|
||||
|
||||
@@ -152,6 +152,9 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
|
||||
case options_block::MODULE_ABI_NAME:
|
||||
extendedInfo.setModuleABIName(blobData);
|
||||
break;
|
||||
case options_block::IS_CONCURRENCY_CHECKED:
|
||||
extendedInfo.setIsConcurrencyChecked(true);
|
||||
break;
|
||||
default:
|
||||
// Unknown options record, possibly for use by a future version of the
|
||||
// module format.
|
||||
@@ -1217,6 +1220,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
|
||||
Bits.IsImplicitDynamicEnabled = extInfo.isImplicitDynamicEnabled();
|
||||
Bits.IsAllowModuleWithCompilerErrorsEnabled =
|
||||
extInfo.isAllowModuleWithCompilerErrorsEnabled();
|
||||
Bits.IsConcurrencyChecked = extInfo.isConcurrencyChecked();
|
||||
MiscVersion = info.miscVersion;
|
||||
ModuleABIName = extInfo.getModuleABIName();
|
||||
|
||||
|
||||
@@ -341,8 +341,11 @@ private:
|
||||
/// Whether this module is compiled while allowing errors.
|
||||
unsigned IsAllowModuleWithCompilerErrorsEnabled: 1;
|
||||
|
||||
/// \c true if this module was built with complete checking for concurrency.
|
||||
unsigned IsConcurrencyChecked: 1;
|
||||
|
||||
// Explicitly pad out to the next word boundary.
|
||||
unsigned : 3;
|
||||
unsigned : 5;
|
||||
} Bits = {};
|
||||
static_assert(sizeof(ModuleBits) <= 8, "The bit set should be small");
|
||||
|
||||
@@ -534,6 +537,8 @@ public:
|
||||
/// Returns \c true if a corresponding .swiftsourceinfo has been found *and
|
||||
/// read*.
|
||||
bool hasSourceInfo() const;
|
||||
|
||||
bool isConcurrencyChecked() const { return Bits.IsConcurrencyChecked; }
|
||||
};
|
||||
|
||||
template <typename T, typename RawData>
|
||||
|
||||
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
|
||||
/// describe what change you made. The content of this comment isn't important;
|
||||
/// it just ensures a conflict if two people change the module format.
|
||||
/// Don't worry about adhering to the 80-column limit for this line.
|
||||
const uint16_t SWIFTMODULE_VERSION_MINOR = 624; // new BodyKind for AbstractFunctionDecl
|
||||
const uint16_t SWIFTMODULE_VERSION_MINOR = 625; // is concurrency checked?
|
||||
|
||||
/// A standard hash seed used for all string hashes in a serialized module.
|
||||
///
|
||||
@@ -797,6 +797,7 @@ namespace options_block {
|
||||
IS_IMPLICIT_DYNAMIC_ENABLED,
|
||||
IS_ALLOW_MODULE_WITH_COMPILER_ERRORS_ENABLED,
|
||||
MODULE_ABI_NAME,
|
||||
IS_CONCURRENCY_CHECKED,
|
||||
};
|
||||
|
||||
using SDKPathLayout = BCRecordLayout<
|
||||
@@ -843,6 +844,10 @@ namespace options_block {
|
||||
MODULE_ABI_NAME,
|
||||
BCBlob
|
||||
>;
|
||||
|
||||
using IsConcurrencyCheckedLayout = BCRecordLayout<
|
||||
IS_CONCURRENCY_CHECKED
|
||||
>;
|
||||
}
|
||||
|
||||
/// The record types within the input block.
|
||||
|
||||
@@ -812,6 +812,7 @@ void Serializer::writeBlockInfoBlock() {
|
||||
BLOCK_RECORD(options_block, RESILIENCE_STRATEGY);
|
||||
BLOCK_RECORD(options_block, IS_ALLOW_MODULE_WITH_COMPILER_ERRORS_ENABLED);
|
||||
BLOCK_RECORD(options_block, MODULE_ABI_NAME);
|
||||
BLOCK_RECORD(options_block, IS_CONCURRENCY_CHECKED);
|
||||
|
||||
BLOCK(INPUT_BLOCK);
|
||||
BLOCK_RECORD(input_block, IMPORTED_MODULE);
|
||||
@@ -1026,6 +1027,11 @@ void Serializer::writeHeader(const SerializationOptions &options) {
|
||||
ABIName.emit(ScratchRecord, M->getABIName().str());
|
||||
}
|
||||
|
||||
if (M->isConcurrencyChecked()) {
|
||||
options_block::IsConcurrencyCheckedLayout IsConcurrencyChecked(Out);
|
||||
IsConcurrencyChecked.emit(ScratchRecord);
|
||||
}
|
||||
|
||||
if (options.SerializeOptionsForDebugging) {
|
||||
options_block::SDKPathLayout SDKPath(Out);
|
||||
options_block::XCCLayout XCC(Out);
|
||||
|
||||
@@ -728,6 +728,8 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
|
||||
M.setHasIncrementalInfo();
|
||||
if (!loadedModuleFile->getModuleABIName().empty())
|
||||
M.setABIName(Ctx.getIdentifier(loadedModuleFile->getModuleABIName()));
|
||||
if (loadedModuleFile->isConcurrencyChecked())
|
||||
M.setIsConcurrencyChecked();
|
||||
M.setUserModuleVersion(loadedModuleFile->getUserModuleVersion());
|
||||
auto diagLocOrInvalid = diagLoc.getValueOr(SourceLoc());
|
||||
loadInfo.status = loadedModuleFile->associateWithFileContext(
|
||||
|
||||
Reference in New Issue
Block a user