|
19 | 19 |
|
20 | 20 | using namespace swift;
|
21 | 21 |
|
22 |
| -std::optional<DiagnosticBehavior> |
23 |
| -swift::getConcurrencyDiagnosticBehaviorLimit(NominalTypeDecl *nominal, |
24 |
| - const DeclContext *fromDC, |
25 |
| - bool ignoreExplicitConformance) { |
26 |
| - ModuleDecl *importedModule = nullptr; |
| 22 | +ModuleDecl *swift::moduleImportForPreconcurrency( |
| 23 | + NominalTypeDecl *nominal, const DeclContext *fromDC) { |
| 24 | + // If the declaration itself has the @preconcurrency attribute, |
| 25 | + // respect it. |
27 | 26 | if (nominal->getAttrs().hasAttribute<PreconcurrencyAttr>()) {
|
28 |
| - // If the declaration itself has the @preconcurrency attribute, |
29 |
| - // respect it. |
30 |
| - importedModule = nominal->getParentModule(); |
31 |
| - } else { |
32 |
| - // Determine whether this nominal type is visible via a @preconcurrency |
33 |
| - // import. |
34 |
| - auto import = nominal->findImport(fromDC); |
35 |
| - auto sourceFile = fromDC->getParentSourceFile(); |
| 27 | + return nominal->getParentModule(); |
| 28 | + } |
36 | 29 |
|
37 |
| - if (!import || !import->options.contains(ImportFlags::Preconcurrency)) |
38 |
| - return std::nullopt; |
| 30 | + // Determine whether this nominal type is visible via a @preconcurrency |
| 31 | + // import. |
| 32 | + auto import = nominal->findImport(fromDC); |
| 33 | + auto sourceFile = fromDC->getParentSourceFile(); |
39 | 34 |
|
40 |
| - if (sourceFile) |
41 |
| - sourceFile->setImportUsedPreconcurrency(*import); |
| 35 | + if (!import || !import->options.contains(ImportFlags::Preconcurrency)) |
| 36 | + return nullptr; |
42 | 37 |
|
43 |
| - importedModule = import->module.importedModule; |
44 |
| - } |
| 38 | + if (sourceFile) |
| 39 | + sourceFile->setImportUsedPreconcurrency(*import); |
| 40 | + |
| 41 | + return import->module.importedModule; |
| 42 | +} |
| 43 | + |
| 44 | +std::optional<DiagnosticBehavior> |
| 45 | +swift::getConcurrencyDiagnosticBehaviorLimit(NominalTypeDecl *nominal, |
| 46 | + const DeclContext *fromDC, |
| 47 | + bool ignoreExplicitConformance) { |
| 48 | + ModuleDecl *importedModule = moduleImportForPreconcurrency(nominal, fromDC); |
| 49 | + if (!importedModule) |
| 50 | + return std::nullopt; |
45 | 51 |
|
46 | 52 | // When the type is explicitly non-Sendable, @preconcurrency imports
|
47 | 53 | // downgrade the diagnostic to a warning in Swift 6.
|
|
0 commit comments