-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cxx-interop] Support importing swift::String
Whenever the String Swift type is exported to C++, we create swift::String on the C++ side. However, we did not support importing swift::String back into Swift. This PR addresses this problem. Unfortunately, we cannot just set swift::String as the ClangNode of Swift's String type. Types with ClangNodes are using the foreign representation, but in this case we want to use the native type whenever possible (e.g., for codegen). To work this around, this PR updates ClangTypeConverter to make sure we have the correct Clang types when we emit function calls to C++ APIs that use swift::String in their interface.
- Loading branch information
Gabor Horvath
committed
Sep 30, 2024
1 parent
bf6bb65
commit fb3b479
Showing
6 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/Interop/SwiftToCxxToSwift/import-swift-stdlib-types-back-to-swift-execution.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: split-file %s %t | ||
|
||
// RUN: %target-swift-frontend -typecheck %t/swiftMod.swift -typecheck -module-name SwiftMod -emit-clang-header-path %t/swiftMod.h -I %t -enable-experimental-cxx-interop -Xcc -DFIRSTPASS | ||
|
||
// RUN: %target-interop-build-swift %t/swiftMod.swift -o %t/swift-execution -module-name SwiftMod -I %t -g -DSECOND_PASS -Xcc -DSWIFT_CXX_INTEROP_HIDE_SWIFT_ERROR | ||
|
||
// RUN: %target-codesign %t/swift-execution | ||
// RUN: %target-run %t/swift-execution | %FileCheck %s | ||
|
||
// REQUIRES: executable_test | ||
|
||
//--- header.h | ||
#ifndef FIRSTPASS | ||
|
||
#include "swiftMod.h" | ||
|
||
inline swift::String createString() { | ||
return swift::String("Foobar"); | ||
} | ||
|
||
#endif | ||
|
||
//--- module.modulemap | ||
module SwiftToCxxTest { | ||
header "header.h" | ||
requires cplusplus | ||
} | ||
|
||
//--- swiftMod.swift | ||
import SwiftToCxxTest | ||
|
||
public func f() -> String? { "" } | ||
|
||
#if SECOND_PASS | ||
|
||
let str = createString() | ||
print(str) | ||
|
||
#endif | ||
|
||
// CHECK: Foobar |