Skip to content

Commit c295db4

Browse files
committed
[cxx-interop] Don't expose unsupported top-level async or @_transparent functions
1 parent 1099cca commit c295db4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,12 @@ class DeclAndTypePrinter::Implementation
11101110

11111111
void visitFuncDecl(FuncDecl *FD) {
11121112
if (outputLang == OutputLanguageMode::Cxx) {
1113+
// Don't expose async functions or transparent functions
1114+
// because they're currently unsupported
1115+
if (FD->hasAsync() || FD->isTransparent()) {
1116+
return;
1117+
}
1118+
11131119
// Emit the underlying C signature that matches the Swift ABI
11141120
// in the generated C++ implementation prologue for the module.
11151121
auto funcABI = getModuleProloguePrinter()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -typecheck -module-name Functions -clang-header-expose-public-decls -emit-clang-header-path %t/functions.h
3+
// RUN: %FileCheck %s < %t/functions.h
4+
5+
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
6+
7+
// CHECK-NOT: SWIFT_EXTERN double $s9Functions10async_funcyS2dYaF(double x) SWIFT_NOEXCEPT SWIFT_CALL; // async_func(_:)
8+
// CHECK-NOT: SWIFT_EXTERN bool $s9Functions16transparent_funcyS2bF(bool x) SWIFT_NOEXCEPT SWIFT_CALL; // transparent_func(_:)
9+
10+
// CHECK: namespace Functions {
11+
// CHECK-EMPTY:
12+
// CHECK-EMPTY:
13+
// CHECK-EMPTY:
14+
// CHECK-EMPTY:
15+
// CHECK-EMPTY:
16+
// CHECK-EMPTY:
17+
// CHECK-NEXT: } // namespace Functions
18+
19+
// CHECK-NOT: inline double async_func(double x) noexcept SWIFT_WARN_UNUSED_RESULT {
20+
// CHECK-NOT: return _impl::$s9Functions10async_funcyS2dYaF(x);
21+
// CHECK-NOT: }
22+
23+
// CHECK-NOT: inline bool transparent_func(bool x) noexcept SWIFT_WARN_UNUSED_RESULT {
24+
// CHECK-NOT: return _impl::$s9Functions16transparent_funcyS2bF(x);
25+
// CHECK-NOT: }
26+
27+
public func async_func(_ x: Double) async -> Double { return 2 * x }
28+
29+
@_transparent
30+
public func transparent_func(_ x: Bool) -> Bool { return !x }

0 commit comments

Comments
 (0)