Skip to content

Commit abfccd1

Browse files
committed
expose @_transparent; don't expose @_alwaysEmitIntoClient and async
1 parent c295db4 commit abfccd1

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

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

11111111
void visitFuncDecl(FuncDecl *FD) {
11121112
if (outputLang == OutputLanguageMode::Cxx) {
1113-
// Don't expose async functions or transparent functions
1113+
// Don't expose async functions or @_alwaysEmitIntoClient functions
11141114
// because they're currently unsupported
1115-
if (FD->hasAsync() || FD->isTransparent()) {
1115+
if (FD->hasAsync() || FD->getAttrs().hasAttribute<AlwaysEmitIntoClientAttr>()) {
11161116
return;
11171117
}
11181118

test/Interop/SwiftToCxx/functions/swift-no-expose-unsupported-func.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
66

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(_:)
7+
// CHECK-NOT: SWIFT_EXTERN bool $s9Functions24alwaysEmitIntoClientFuncyS2bF(bool x) SWIFT_NOEXCEPT SWIFT_CALL; // alwaysEmitIntoClientFunc(_:)
8+
// CHECK-NOT: SWIFT_EXTERN double $s9Functions9asyncFuncyS2dYaF(double x) SWIFT_NOEXCEPT SWIFT_CALL; // asyncFunc(_:)
99

1010
// CHECK: namespace Functions {
1111
// CHECK-EMPTY:
@@ -16,15 +16,15 @@
1616
// CHECK-EMPTY:
1717
// CHECK-NEXT: } // namespace Functions
1818

19-
// CHECK-NOT: inline double async_func(double x) noexcept SWIFT_WARN_UNUSED_RESULT {
20-
// CHECK-NOT: return _impl::$s9Functions10async_funcyS2dYaF(x);
19+
// CHECK-NOT: inline bool alwaysEmitIntoClientFunc(bool x) noexcept SWIFT_WARN_UNUSED_RESULT {
20+
// CHECK-NOT: return _impl::$s9Functions24alwaysEmitIntoClientFuncyS2bF(x);
2121
// CHECK-NOT: }
2222

23-
// CHECK-NOT: inline bool transparent_func(bool x) noexcept SWIFT_WARN_UNUSED_RESULT {
24-
// CHECK-NOT: return _impl::$s9Functions16transparent_funcyS2bF(x);
23+
// CHECK-NOT: inline double asyncFunc(double x) noexcept SWIFT_WARN_UNUSED_RESULT {
24+
// CHECK-NOT: return _impl::$s9Functions9asyncFuncyS2dYaF(x);
2525
// CHECK-NOT: }
2626

27-
public func async_func(_ x: Double) async -> Double { return 2 * x }
27+
public func asyncFunc(_ x: Double) async -> Double { return 2 * x }
2828

29-
@_transparent
30-
public func transparent_func(_ x: Bool) -> Bool { return !x }
29+
@_alwaysEmitIntoClient
30+
public func alwaysEmitIntoClientFunc(_ x: Bool) -> Bool { return !x }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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: SWIFT_EXTERN ptrdiff_t $s9Functions24transparentPrimitiveFuncyS2iF(ptrdiff_t x) SWIFT_NOEXCEPT SWIFT_CALL; // transparentPrimitiveFunc(_:)
8+
9+
// CHECK: inline swift::Int transparentPrimitiveFunc(swift::Int x) noexcept SWIFT_WARN_UNUSED_RESULT {
10+
// CHECK-NEXT: return _impl::$s9Functions24transparentPrimitiveFuncyS2iF(x);
11+
// CHECK-NEXT: }
12+
13+
@_transparent
14+
public func transparentPrimitiveFunc(_ x: Int) -> Int { return x * x }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend %S/swift-transparent-functions-cxx-bridging.swift -typecheck -module-name Functions -clang-header-expose-public-decls -emit-clang-header-path %t/functions.h
4+
5+
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-functions-execution.o
6+
// RUN: %target-interop-build-swift %S/swift-transparent-functions-cxx-bridging.swift -o %t/swift-functions-execution -Xlinker %t/swift-functions-execution.o -module-name Functions -Xfrontend -entry-point-function-name -Xfrontend swiftMain
7+
8+
// RUN: %target-codesign %t/swift-functions-execution
9+
// RUN: %target-run %t/swift-functions-execution
10+
11+
// REQUIRES: executable_test
12+
13+
#include <cassert>
14+
#include "functions.h"
15+
16+
int main() {
17+
using namespace Functions;
18+
19+
assert(transparentPrimitiveFunc(12) == 144);
20+
21+
return 0;
22+
}

0 commit comments

Comments
 (0)