Skip to content

Commit eb417c8

Browse files
committed
[cxx-interop] Don't import exit from Darwin module, use the one from _SwiftConcurrency.h.
1 parent fbb4901 commit eb417c8

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,13 +3210,14 @@ namespace {
32103210
d->getName() == "cos" || d->getName() == "exit";
32113211
return false;
32123212
};
3213-
if (decl->getOwningModule() &&
3214-
(decl->getOwningModule()
3215-
->getTopLevelModule()
3216-
->getFullModuleName() == "std" ||
3217-
decl->getOwningModule()
3218-
->getTopLevelModule()
3219-
->getFullModuleName() == "_SwiftConcurrencyShims")) {
3213+
auto topLevelModuleEq =
3214+
[](const clang::FunctionDecl *d, StringRef n) -> bool {
3215+
return d->getOwningModule() &&
3216+
d->getOwningModule()
3217+
->getTopLevelModule()
3218+
->getFullModuleName() == n;
3219+
};
3220+
if (topLevelModuleEq(decl, "std")) {
32203221
if (isAlternativeCStdlibFunctionFromTextualHeader(decl)) {
32213222
return nullptr;
32223223
}
@@ -3228,6 +3229,13 @@ namespace {
32283229
return nullptr;
32293230
}
32303231
}
3232+
// Use the exit function from _SwiftConcurrency.h as it is platform
3233+
// agnostic.
3234+
if ((topLevelModuleEq(decl, "Darwin") ||
3235+
topLevelModuleEq(decl, "SwiftGlibc")) &&
3236+
decl->getDeclName().isIdentifier() && decl->getName() == "exit") {
3237+
return nullptr;
3238+
}
32313239
}
32323240

32333241
auto dc =
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library)
2+
//
3+
// REQUIRES: executable_test
4+
// REQUIRES: concurrency
5+
// REQUIRES: libdispatch
6+
// REQUIRES: concurrency_runtime
7+
8+
import StdlibUnittest
9+
10+
import CxxStdlib
11+
import Cxx
12+
13+
import _Concurrency
14+
import Dispatch
15+
16+
@main struct Main {
17+
static func main() async {
18+
var ConcurrencyTestSuite = TestSuite("Concurrency")
19+
20+
ConcurrencyTestSuite.test("Task.sleep") {
21+
let start = DispatchTime.now()
22+
await Task.sleep(100_000_000)
23+
let stop = DispatchTime.now()
24+
expectTrue(stop >= (start + .nanoseconds(100_000_000)))
25+
}
26+
27+
ConcurrencyTestSuite.test("Task.sleep (non-blocking)") {
28+
let task = detach {
29+
std.string("Hello, Swift!")
30+
}
31+
32+
await Task.sleep(100_000_000)
33+
expectEqual(await task.get(), "Hello, Swift!")
34+
}
35+
36+
await runAllTestsAsync()
37+
}
38+
}
39+

0 commit comments

Comments
 (0)