Skip to content

Commit 53779e3

Browse files
committed
Centralize and clean up setting of "used @preconcurrency" state.
1 parent 363f203 commit 53779e3

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,13 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
726726
auto import = findImportFor(nominal, fromDC);
727727

728728
// When the type is explicitly non-Sendable...
729+
auto sourceFile = fromDC->getParentSourceFile();
729730
if (isExplicitlyNonSendable) {
730731
// @preconcurrency imports downgrade the diagnostic to a warning in Swift 6,
731732
if (import && import->options.contains(ImportFlags::Preconcurrency)) {
732-
// FIXME: Note that this @preconcurrency import was "used".
733+
if (sourceFile)
734+
sourceFile->setImportUsedPreconcurrency(*import);
735+
733736
return DiagnosticBehavior::Warning;
734737
}
735738

@@ -741,7 +744,9 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
741744
// @preconcurrency suppresses the diagnostic in Swift 5.x, and
742745
// downgrades it to a warning in Swift 6 and later.
743746
if (import && import->options.contains(ImportFlags::Preconcurrency)) {
744-
// FIXME: Note that this @preconcurrency import was "used".
747+
if (sourceFile)
748+
sourceFile->setImportUsedPreconcurrency(*import);
749+
745750
return nominalModule->getASTContext().LangOpts.isSwiftVersionAtLeast(6)
746751
? DiagnosticBehavior::Warning
747752
: DiagnosticBehavior::Ignore;
@@ -779,14 +784,6 @@ static bool diagnoseSingleNonSendableType(
779784

780785
bool wasSuppressed = diagnose(type, behavior);
781786

782-
// If this type was imported from another module, try to find the
783-
// corresponding import.
784-
Optional<AttributedImport<swift::ImportedModule>> import;
785-
SourceFile *sourceFile = fromContext.fromDC->getParentSourceFile();
786-
if (nominal && nominal->getParentModule() != module) {
787-
import = findImportFor(nominal, fromContext.fromDC);
788-
}
789-
790787
if (behavior == DiagnosticBehavior::Ignore || wasSuppressed) {
791788
// Don't emit any other diagnostics.
792789
} else if (type->is<FunctionType>()) {
@@ -810,6 +807,14 @@ static bool diagnoseSingleNonSendableType(
810807
diag::non_sendable_nominal, nominal->getDescriptiveKind(),
811808
nominal->getName());
812809

810+
// This type was imported from another module; try to find the
811+
// corresponding import.
812+
Optional<AttributedImport<swift::ImportedModule>> import;
813+
SourceFile *sourceFile = fromContext.fromDC->getParentSourceFile();
814+
if (sourceFile) {
815+
import = findImportFor(nominal, fromContext.fromDC);
816+
}
817+
813818
// If we found the import that makes this nominal type visible, remark
814819
// that it can be @preconcurrency import.
815820
// Only emit this remark once per source file, because it can happen a
@@ -828,14 +833,6 @@ static bool diagnoseSingleNonSendableType(
828833
}
829834
}
830835

831-
// If we found an import that makes this nominal type visible, and that
832-
// was a @preconcurrency import, note that we have made use of the
833-
// attribute.
834-
if (import && import->options.contains(ImportFlags::Preconcurrency) &&
835-
sourceFile) {
836-
sourceFile->setImportUsedPreconcurrency(*import);
837-
}
838-
839836
return behavior == DiagnosticBehavior::Unspecified && !wasSuppressed;
840837
}
841838

0 commit comments

Comments
 (0)