Skip to content

Add an implicit dependency on the '_SwiftConcurrencyShims' library #62883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/swift/Frontend/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ class CompilerInstance {
/// i.e. if it can be found.
bool canImportSwiftConcurrency() const;

/// Whether the Swift Concurrency Shims support Clang library can be imported
/// i.e. if it can be found.
bool canImportSwiftConcurrencyShims() const;

/// Verify that if an implicit import of the `StringProcessing` module if
/// expected, it can actually be imported. Emit a warning, otherwise.
void verifyImplicitStringProcessingImport();
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ constexpr static const StringLiteral STDLIB_NAME = "Swift";
constexpr static const StringLiteral SWIFT_ONONE_SUPPORT = "SwiftOnoneSupport";
/// The name of the Concurrency module, which supports that extension.
constexpr static const StringLiteral SWIFT_CONCURRENCY_NAME = "_Concurrency";
/// The name of the Concurrency Shims Clang module
constexpr static const StringLiteral SWIFT_CONCURRENCY_SHIMS_NAME = "_SwiftConcurrencyShims";
/// The name of the Distributed module, which supports that extension.
constexpr static const StringLiteral SWIFT_DISTRIBUTED_NAME = "Distributed";
/// The name of the StringProcessing module, which supports that extension.
Expand Down
9 changes: 9 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ bool CompilerInstance::canImportSwiftConcurrency() const {
return getASTContext().canImportModule(modulePath);
}

bool CompilerInstance::canImportSwiftConcurrencyShims() const {
ImportPath::Module::Builder builder(
getASTContext().getIdentifier(SWIFT_CONCURRENCY_SHIMS_NAME));
auto modulePath = builder.get();
return getASTContext().canImportModule(modulePath);
}

void CompilerInstance::verifyImplicitStringProcessingImport() {
if (Invocation.shouldImportSwiftStringProcessing() &&
!canImportSwiftStringProcessing()) {
Expand Down Expand Up @@ -935,6 +942,8 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
case ImplicitStdlibKind::Stdlib:
if (canImportSwiftConcurrency())
pushImport(SWIFT_CONCURRENCY_NAME);
if (canImportSwiftConcurrencyShims())
pushImport(SWIFT_CONCURRENCY_SHIMS_NAME);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/overload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func f4(_ j: Wibble) { } // expected-error{{cannot find type 'Wibble' in scope}}
f4(5)

func f1() {
var c : Class // expected-error{{cannot find type 'Class' in scope}}
var c : Klass // expected-error{{cannot find type 'Klass' in scope}}
markUsed(c.x) // make sure error does not cascade here
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of the test here is to avoid propagating the original error. Once this additional Clang module is brought in, the name Class somehow conflicts with name-resolution logic as affected by the newly-added implicit Clang module dependency. Renaming this variable allows us to keep testing the original thing and not worry about it being affected by brought-in clang declarations...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

}

Expand Down
4 changes: 3 additions & 1 deletion test/DebugInfo/InlineBridgingHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
// RUN: -emit-ir -g %s -o - | %FileCheck %s

// The Swift CU must come first.
// CHECK: !llvm.dbg.cu = !{![[SWIFT_CU:[0-9]+]], ![[CLANG_CU:[0-9]+]]}
// CHECK: !llvm.dbg.cu = !{![[SWIFT_CU:[0-9]+]], ![[CLANG_CU:[0-9]+]], ![[CONCURRENCY_SHIMS_CU:[0-9]+]]}
// CHECK: ![[SWIFT_CU]] = distinct !DICompileUnit(language: DW_LANG_Swift
// CHECK: ![[CLANG_CU]] = distinct !DICompileUnit(
// CHECK-SAME: language: {{DW_LANG_ObjC|DW_LANG_C}}
// CHECK: ![[CONCURRENCY_SHIMS_CU]] = distinct !DICompileUnit(
// CHECK-SAME: language: {{DW_LANG_ObjC|DW_LANG_C}}
// CHECK: DISubprogram(name: "Foo"{{.*}} unit: ![[CLANG_CU]],

Foo()
1 change: 1 addition & 0 deletions test/ScanDependencies/can_import_placeholder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ import SomeExternalModule
// CHECK-DAG: "swift": "SwiftOnoneSupport"
// CHECK-DAG: "swift": "_Concurrency"
// CHECK-DAG: "swift": "_StringProcessing"
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"
// CHECK: ],
1 change: 1 addition & 0 deletions test/ScanDependencies/module_deps_cache_reuse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import SubE
// CHECK-DAG: "swift": "_Concurrency"
// CHECK-DAG: "swift": "_StringProcessing"
// CHECK-DAG: "swift": "_cross_import_E"
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"
// CHECK: ],

// CHECK: "extraPcmArgs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ import SubEWrapper
// CHECK-DAG: "swift": "_Concurrency"
// CHECK-DAG: "swift": "_StringProcessing"
// CHECK-DAG: "swift": "_cross_import_E"
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"
// CHECK: ],
1 change: 1 addition & 0 deletions test/ScanDependencies/module_deps_external.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import SomeExternalModule
// CHECK-DAG: "swift": "SwiftOnoneSupport"
// CHECK-DAG: "swift": "_Concurrency"
// CHECK-DAG: "swift": "_StringProcessing"
// CHECK-DAG: "clang": "_SwiftConcurrencyShims"
// CHECK: ],

// CHECK: "extraPcmArgs": [
Expand Down
3 changes: 2 additions & 1 deletion test/ScanDependencies/prescan_deps.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import SubE
// CHECK-NEXT: "SubE",
// CHECK-NEXT: "Swift",
// CHECK-NEXT: "SwiftOnoneSupport",
// CHECK-NEXT: "_Concurrency"
// CHECK-NEXT: "_Concurrency",
// CHECK-NEXT: "_SwiftConcurrencyShims",
// CHECK-NEXT: "_StringProcessing"
// CHECK-NEXT: ]
2 changes: 1 addition & 1 deletion test/SourceKit/DocSupport/doc_swift_module1.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %empty-directory(%t.mod)
// RUN: %swift -emit-module -o %t.mod/cake1.swiftmodule %S/Inputs/cake1.swift -disable-implicit-string-processing-module-import -parse-as-library
// RUN: %swift -emit-module -o %t.mod/cake1.swiftmodule %S/Inputs/cake1.swift -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -parse-as-library
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were subtly affected by the presence of the new module as well, so I just disabled overall implicit concurrency loading and modified the expected outputs accordingly. The tests are still exercising/verifying the functionality they were before.

// RUN: %sourcekitd-test -req=doc-info -module cake1 -- -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -I %t.mod > %t.response
// RUN: %diff -u %s.response %t.response
Loading