Skip to content

Commit 92b4fc5

Browse files
committed
Centralize and clean up setting of "used @preconcurrency" state.
1 parent 6bd354a commit 92b4fc5

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
@@ -721,10 +721,13 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
721721
auto import = findImportFor(nominal, fromDC);
722722

723723
// When the type is explicitly non-Sendable...
724+
auto sourceFile = fromDC->getParentSourceFile();
724725
if (isExplicitlyNonSendable) {
725726
// @preconcurrency imports downgrade the diagnostic to a warning in Swift 6,
726727
if (import && import->options.contains(ImportFlags::Preconcurrency)) {
727-
// FIXME: Note that this @preconcurrency import was "used".
728+
if (sourceFile)
729+
sourceFile->setImportUsedPreconcurrency(*import);
730+
728731
return DiagnosticBehavior::Warning;
729732
}
730733

@@ -736,7 +739,9 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
736739
// @preconcurrency suppresses the diagnostic in Swift 5.x, and
737740
// downgrades it to a warning in Swift 6 and later.
738741
if (import && import->options.contains(ImportFlags::Preconcurrency)) {
739-
// FIXME: Note that this @preconcurrency import was "used".
742+
if (sourceFile)
743+
sourceFile->setImportUsedPreconcurrency(*import);
744+
740745
return nominalModule->getASTContext().LangOpts.isSwiftVersionAtLeast(6)
741746
? DiagnosticBehavior::Warning
742747
: DiagnosticBehavior::Ignore;
@@ -774,14 +779,6 @@ static bool diagnoseSingleNonSendableType(
774779

775780
bool wasSuppressed = diagnose(type, behavior);
776781

777-
// If this type was imported from another module, try to find the
778-
// corresponding import.
779-
Optional<AttributedImport<swift::ImportedModule>> import;
780-
SourceFile *sourceFile = fromContext.fromDC->getParentSourceFile();
781-
if (nominal && nominal->getParentModule() != module) {
782-
import = findImportFor(nominal, fromContext.fromDC);
783-
}
784-
785782
if (behavior == DiagnosticBehavior::Ignore || wasSuppressed) {
786783
// Don't emit any other diagnostics.
787784
} else if (type->is<FunctionType>()) {
@@ -805,6 +802,14 @@ static bool diagnoseSingleNonSendableType(
805802
diag::non_sendable_nominal, nominal->getDescriptiveKind(),
806803
nominal->getName());
807804

805+
// This type was imported from another module; try to find the
806+
// corresponding import.
807+
Optional<AttributedImport<swift::ImportedModule>> import;
808+
SourceFile *sourceFile = fromContext.fromDC->getParentSourceFile();
809+
if (sourceFile) {
810+
import = findImportFor(nominal, fromContext.fromDC);
811+
}
812+
808813
// If we found the import that makes this nominal type visible, remark
809814
// that it can be @preconcurrency import.
810815
// Only emit this remark once per source file, because it can happen a
@@ -823,14 +828,6 @@ static bool diagnoseSingleNonSendableType(
823828
}
824829
}
825830

826-
// If we found an import that makes this nominal type visible, and that
827-
// was a @preconcurrency import, note that we have made use of the
828-
// attribute.
829-
if (import && import->options.contains(ImportFlags::Preconcurrency) &&
830-
sourceFile) {
831-
sourceFile->setImportUsedPreconcurrency(*import);
832-
}
833-
834831
return behavior == DiagnosticBehavior::Unspecified && !wasSuppressed;
835832
}
836833

0 commit comments

Comments
 (0)