Skip to content

Commit 1d16403

Browse files
committed
[interop][SwiftToCxx] experimentally expose Swift's Array type
This is done without annotations on the stdlib yet while @_expose is still experimental
1 parent 6e7b3ab commit 1d16403

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,8 @@ static bool hasExposeAttr(const ValueDecl *VD) {
25132513
if (isa<NominalTypeDecl>(VD) && VD->getModuleContext()->isStdlibModule()) {
25142514
if (VD == VD->getASTContext().getStringDecl())
25152515
return true;
2516+
if (VD == VD->getASTContext().getArrayDecl())
2517+
return true;
25162518
return false;
25172519
}
25182520
if (VD->getAttrs().hasAttribute<ExposeAttr>())
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -parse-as-library %platform-module-dir/Swift.swiftmodule/%module-target-triple.swiftinterface -enable-library-evolution -disable-objc-attr-requires-foundation-module -typecheck -module-name Swift -parse-stdlib -enable-experimental-cxx-interop -emit-clang-header-path %t/Swift.h -experimental-skip-all-function-bodies
5+
6+
// RUN: %target-swift-frontend -typecheck %t/use-array.swift -typecheck -module-name UseArray -enable-experimental-cxx-interop -emit-clang-header-path %t/UseArray.h
7+
8+
// RUN: %target-interop-build-clangxx -fno-exceptions -std=gnu++20 -c %t/array-execution.cpp -I %t -o %t/swift-stdlib-execution.o
9+
// RUN: %target-build-swift %t/use-array.swift -o %t/swift-stdlib-execution -Xlinker %t/swift-stdlib-execution.o -module-name UseArray -Xfrontend -entry-point-function-name -Xfrontend swiftMain
10+
// RUN: %target-codesign %t/swift-stdlib-execution
11+
// RUN: %target-run %t/swift-stdlib-execution | %FileCheck %s
12+
13+
// REQUIRES: executable_test
14+
15+
//--- use-array.swift
16+
@_expose(Cxx)
17+
public func createArray(_ val: CInt) -> [CInt] {
18+
return [val, val]
19+
}
20+
21+
@_expose(Cxx)
22+
public func passthroughArray(_ val: [CInt]) -> Array<CInt> {
23+
return val
24+
}
25+
26+
@_expose(Cxx)
27+
public func printArray(_ val: Array<CInt>) {
28+
print(val)
29+
}
30+
31+
//--- array-execution.cpp
32+
33+
#include <cassert>
34+
#include "Swift.h"
35+
#include "UseArray.h"
36+
37+
int main() {
38+
using namespace Swift;
39+
40+
{
41+
Array<int> val = UseArray::createArray(2);
42+
UseArray::printArray(UseArray::passthroughArray(val));
43+
}
44+
// CHECK: [2, 2]
45+
return 0;
46+
}

test/Interop/SwiftToCxx/stdlib/string/string-to-nsstring.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
// RUN: %target-swift-frontend -typecheck %t/create_string.swift -typecheck -module-name StringCreator -enable-experimental-cxx-interop -emit-clang-header-path %t/StringCreator.h
77

8-
// RUN: %target-interop-build-clangxx -fobjc-arc -c %t/string-to-nsstring.mm -I %t -o %t/swift-stdlib-execution.o
8+
// RUN: %target-interop-build-clangxx -std=gnu++20 -fobjc-arc -c %t/string-to-nsstring.mm -I %t -o %t/swift-stdlib-execution.o
99
// RUN: %target-build-swift %t/use_foundation.swift %t/create_string.swift -o %t/swift-stdlib-execution -Xlinker %t/swift-stdlib-execution.o -module-name StringCreator -Xfrontend -entry-point-function-name -Xfrontend swiftMain -lc++
1010
// RUN: %target-codesign %t/swift-stdlib-execution
1111
// RUN: %target-run %t/swift-stdlib-execution
1212

13-
// RUN: %target-interop-build-clangxx -fobjc-arc -c %t/string-to-nsstring-one-arc-op.mm -I %t -Xclang -emit-llvm -S -o - -O1 | %FileCheck --check-prefix=CHECKARC %s
13+
// RUN: %target-interop-build-clangxx -std=gnu++20 -fobjc-arc -c %t/string-to-nsstring-one-arc-op.mm -I %t -Xclang -emit-llvm -S -o - -O1 | %FileCheck --check-prefix=CHECKARC %s
1414

1515
// REQUIRES: executable_test
1616
// REQUIRES: objc_interop

test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22
// RUN: %target-swift-frontend -parse-as-library %platform-module-dir/Swift.swiftmodule/%module-target-triple.swiftinterface -enable-library-evolution -disable-objc-attr-requires-foundation-module -typecheck -module-name Swift -parse-stdlib -enable-experimental-cxx-interop -emit-clang-header-path %t/Swift.h -experimental-skip-all-function-bodies
33
// RUN: %FileCheck %s < %t/Swift.h
44

5-
// RUN: %check-interop-cxx-header-in-clang(%t/Swift.h -Wno-unused-private-field -Wno-unused-function)
5+
// RUN: %check-generic-interop-cxx-header-in-clang(%t/Swift.h -Wno-unused-private-field -Wno-unused-function)
66

77
// CHECK: namespace Swift {
88

9+
// CHECK: template<class T_0_0>
10+
// CHECK: template<class T_0_0>
11+
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0>
12+
// CHECK-NEXT: class Array final {
13+
// CHECK-NEXT: public:
14+
// CHECK-NEXT: inline ~Array() {
15+
// CHECK: }
16+
// CHECK-NEXT: inline Array(const Array &other) {
17+
// CHECK: }
18+
919
// CHECK: class String final {
1020
// CHECK-NEXT: public:
1121
// CHECK-NEXT: inline ~String() {

0 commit comments

Comments
 (0)