[interop][SwiftToCxx] emit Swift's stdlib inside of 'swift' namespace

This commit is contained in:
Alex Lorenz
2023-03-09 17:25:20 -08:00
parent 8bb85cb362
commit 0dc90d38c1
39 changed files with 148 additions and 136 deletions

View File

@@ -163,6 +163,10 @@ swift::cxx_translation::getNameForCxx(const ValueDecl *VD,
if (customNamesOnly)
return StringRef();
if (auto *mod = dyn_cast<ModuleDecl>(VD)) {
if (mod->isStdlibModule())
return "swift";
}
if (VD->getModuleContext()->isStdlibModule()) {
// Incorporate argument labels into Stdlib API names.
// FIXME: This should be done more broadly.

View File

@@ -142,7 +142,7 @@ void ClangSyntaxPrinter::printModuleNamespaceStart(
const ModuleDecl &moduleContext) const {
os << "namespace ";
printBaseName(&moduleContext);
os << " __attribute__((swift_private))";
os << " SWIFT_PRIVATE_ATTR";
printSymbolUSRAttribute(&moduleContext);
os << " {\n";
}
@@ -155,7 +155,7 @@ void ClangSyntaxPrinter::printNamespace(
os << "namespace ";
namePrinter(os);
if (trivia == NamespaceTrivia::AttributeSwiftPrivate)
os << " __attribute__((swift_private))";
os << " SWIFT_PRIVATE_ATTR";
if (moduleContext)
printSymbolUSRAttribute(moduleContext);
os << " {\n\n";

View File

@@ -835,8 +835,8 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
os << "#endif\n";
os << "#ifdef __cplusplus\n";
os << "namespace ";
M.ValueDecl::getName().print(os);
os << " __attribute__((swift_private))";
ClangSyntaxPrinter(os).printBaseName(&M);
os << " SWIFT_PRIVATE_ATTR";
ClangSyntaxPrinter(os).printSymbolUSRAttribute(&M);
os << " {\n";
os << "namespace " << cxx_synthesis::getCxxImplNamespaceName() << " {\n";
@@ -854,7 +854,7 @@ EmittedClangHeaderDependencyInfo swift::printModuleContentsAsCxx(
// Construct a C++ namespace for the module.
ClangSyntaxPrinter(os).printNamespace(
[&](raw_ostream &os) { M.ValueDecl::getName().print(os); },
[&](raw_ostream &os) { ClangSyntaxPrinter(os).printBaseName(&M); },
[&](raw_ostream &os) { os << moduleOS.str(); },
ClangSyntaxPrinter::NamespaceTrivia::AttributeSwiftPrivate, &M);

View File

@@ -19,6 +19,7 @@
#include "PrintClangValueType.h"
#include "SwiftToClangInteropContext.h"
#include "swift/ABI/MetadataValues.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/Decl.h"
#include "swift/AST/GenericParamList.h"
#include "swift/AST/Module.h"
@@ -218,7 +219,8 @@ public:
llvm::function_ref<void()> body) {
if (!optionalKind || optionalKind == OTK_None)
return body();
os << "Swift::Optional<";
printBaseName(moduleContext->getASTContext().getStdlibModule());
os << "::Optional<";
body();
os << '>';
}
@@ -718,7 +720,7 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
// Print out the return type.
if (FD->hasThrows() && outputLang == OutputLanguageMode::Cxx)
os << "Swift::ThrowingResult<";
os << "swift::ThrowingResult<";
if (kind == FunctionSignatureKind::CFunctionProto) {
// First, verify that the C++ return type is representable.
{
@@ -1330,17 +1332,17 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
if (hasThrows) {
os << " if (opaqueError != nullptr)\n";
os << "#ifdef __cpp_exceptions\n";
os << " throw (Swift::Error(opaqueError));\n";
os << " throw (swift::Error(opaqueError));\n";
os << "#else\n";
if (resultTy->isVoid()) {
os << " return Swift::Expected<void>(Swift::Error(opaqueError));\n";
os << " return swift::Expected<void>(swift::Error(opaqueError));\n";
os << "#endif\n";
} else {
auto directResultType = signature.getDirectResultType();
printDirectReturnOrParamCType(
*directResultType, resultTy, moduleContext, os, cPrologueOS,
typeMapping, interopContext, [&]() {
os << " return Swift::Expected<";
os << " return swift::Expected<";
OptionalTypeKind retKind;
Type objTy;
std::tie(objTy, retKind) =
@@ -1348,7 +1350,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
auto s = printClangFunctionReturnType(objTy, retKind, const_cast<ModuleDecl *>(moduleContext),
OutputLanguageMode::Cxx);
os << ">(Swift::Error(opaqueError));\n";
os << ">(swift::Error(opaqueError));\n";
os << "#endif\n";
// Return the function result value if it doesn't throw.

View File

@@ -200,24 +200,27 @@ void swift::printSwiftToClangCoreScaffold(SwiftToClangInteropContext &ctx,
PrimitiveTypeMapping &typeMapping,
raw_ostream &os) {
ClangSyntaxPrinter printer(os);
printer.printNamespace("swift", [&](raw_ostream &) {
printer.printNamespace(
cxx_synthesis::getCxxImplNamespaceName(), [&](raw_ostream &) {
printer.printExternC([&](raw_ostream &os) {
printTypeMetadataResponseType(ctx, typeMapping, os);
os << "\n";
printValueWitnessTable(os);
os << "\n";
printPrimitiveGenericTypeTraits(os, astContext, typeMapping,
/*isCForwardDefinition=*/true);
});
os << "\n";
printer.printNamespace(
cxx_synthesis::getCxxSwiftNamespaceName(),
[&](raw_ostream &) {
printer.printNamespace(
cxx_synthesis::getCxxImplNamespaceName(), [&](raw_ostream &) {
printer.printExternC([&](raw_ostream &os) {
printTypeMetadataResponseType(ctx, typeMapping, os);
os << "\n";
printValueWitnessTable(os);
os << "\n";
printPrimitiveGenericTypeTraits(os, astContext, typeMapping,
/*isCForwardDefinition=*/true);
});
os << "\n";
});
os << "\n";
// C++ only supports inline variables from C++17.
ClangSyntaxPrinter(os).printIgnoredCxx17ExtensionDiagnosticBlock([&]() {
printPrimitiveGenericTypeTraits(os, astContext, typeMapping,
/*isCForwardDefinition=*/false);
});
os << "\n";
// C++ only supports inline variables from C++17.
ClangSyntaxPrinter(os).printIgnoredCxx17ExtensionDiagnosticBlock([&]() {
printPrimitiveGenericTypeTraits(os, astContext, typeMapping,
/*isCForwardDefinition=*/false);
});
});
},
ClangSyntaxPrinter::NamespaceTrivia::AttributeSwiftPrivate);
}

View File

@@ -71,7 +71,13 @@
#define SWIFT_SYMBOL_MODULE(moduleValue)
#endif
namespace swift {
#if __has_attribute(swift_private)
#define SWIFT_PRIVATE_ATTR __attribute__((swift_private))
#else
#define SWIFT_PRIVATE_ATTR
#endif
namespace swift SWIFT_PRIVATE_ATTR {
namespace _impl {
extern "C" void *_Nonnull swift_retain(void *_Nonnull) noexcept;
@@ -243,7 +249,7 @@ SWIFT_INLINE_THUNK void *_Nonnull getOpaquePointer(T &value) {
#pragma clang diagnostic pop
} // namespace swift
} // namespace swift SWIFT_PRIVATE_ATTR
#endif
#endif // SWIFT_CXX_INTEROPERABILITY_H

View File

@@ -189,7 +189,7 @@ public:
opaqueValue = other.opaqueValue;
}
template <class T> SWIFT_INLINE_THUNK Swift::Optional<T> as() {
template <class T> SWIFT_INLINE_THUNK swift::Optional<T> as() {
alignas(alignof(T)) char buffer[sizeof(T)];
const void *em = getErrorMetadata();
void *ep = getPointerToOpaquePointer();
@@ -207,10 +207,10 @@ public:
swift::_impl::implClassFor<T>::type::initializeWithTake(dest,
buffer);
});
return Swift::Optional<T>::init(result);
return swift::Optional<T>::init(result);
}
return Swift::Optional<T>::none();
return swift::Optional<T>::none();
}
private:
@@ -236,7 +236,7 @@ public:
has_val = false;
}
constexpr Expected(const Swift::Error& error_val) noexcept {
constexpr Expected(const swift::Error &error_val) noexcept {
new (&buffer) Error(error_val);
has_val = false;
}
@@ -264,7 +264,7 @@ public:
if (has_value())
reinterpret_cast<const T *>(buffer)->~T();
else
reinterpret_cast<Swift::Error *>(buffer)->~Error();
reinterpret_cast<swift::Error *>(buffer)->~Error();
}
/// assignment
@@ -313,22 +313,23 @@ public:
}
// Get error
constexpr Swift::Error const& error() const& {
constexpr swift::Error const &error() const & {
if (has_value())
abort();
return reinterpret_cast<const Swift::Error&>(buffer);
return reinterpret_cast<const swift::Error &>(buffer);
}
constexpr Swift::Error& error() & {
constexpr swift::Error &error() & {
if (has_value())
abort();
return reinterpret_cast<Swift::Error&>(buffer);
return reinterpret_cast<swift::Error &>(buffer);
}
constexpr bool has_value() const noexcept { return has_val; }
private:
alignas(_impl::max(alignof(T), alignof(Swift::Error))) char buffer[_impl::max(sizeof(T), sizeof(Swift::Error))];
alignas(_impl::max(alignof(T), alignof(swift::Error))) char buffer[_impl::max(
sizeof(T), sizeof(swift::Error))];
bool has_val;
};
@@ -341,12 +342,11 @@ public:
has_val = false;
}
Expected(const Swift::Error& error_val) noexcept {
Expected(const swift::Error &error_val) noexcept {
new (&buffer) Error(error_val);
has_val = false;
}
/// Copy
Expected(Expected const& other) noexcept {
if (other.has_value())
@@ -361,9 +361,7 @@ public:
// FIXME: Implement move semantics when move swift values is possible
[[noreturn]] Expected(Expected&&) noexcept { abort(); }
~Expected() noexcept {
reinterpret_cast<Swift::Error *>(buffer)->~Error();
}
~Expected() noexcept { reinterpret_cast<swift::Error *>(buffer)->~Error(); }
/// assignment
constexpr auto operator=(Expected&& other) noexcept = delete;
@@ -373,21 +371,21 @@ public:
constexpr explicit operator bool() const noexcept { return has_value(); }
// Get error
constexpr Swift::Error const& error() const& {
constexpr swift::Error const &error() const & {
if (has_value())
abort();
return reinterpret_cast<const Swift::Error&>(buffer);
return reinterpret_cast<const swift::Error &>(buffer);
}
constexpr Swift::Error& error() & {
constexpr swift::Error &error() & {
if (has_value())
abort();
return reinterpret_cast<Swift::Error&>(buffer);
return reinterpret_cast<swift::Error &>(buffer);
}
constexpr bool has_value() const noexcept { return has_val; }
private:
alignas(alignof(Swift::Error)) char buffer[sizeof(Swift::Error)];
alignas(alignof(swift::Error)) char buffer[sizeof(swift::Error)];
bool has_val;
};
@@ -400,10 +398,9 @@ using ThrowingResult = T;
#else
template<class T>
using ThrowingResult = Swift::Expected<T>;
template <class T> using ThrowingResult = swift::Expected<T>;
#define SWIFT_RETURN_THUNK(T, v) Swift::Expected<T>(v)
#define SWIFT_RETURN_THUNK(T, v) swift::Expected<T>(v)
#endif

View File

@@ -192,7 +192,7 @@ public func takeTrivialInout(_ x: inout Trivial) {
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: namespace UseCxxTy __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("UseCxxTy") {
// CHECK-NEXT: namespace UseCxxTy SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("UseCxxTy") {
// CHECK: SWIFT_INLINE_THUNK ns::NonTrivialTemplate<int> retNonTrivial() noexcept SWIFT_SYMBOL({{.*}}) SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: alignas(alignof(ns::NonTrivialTemplate<int>)) char storage[sizeof(ns::NonTrivialTemplate<int>)];
@@ -231,7 +231,7 @@ public func takeTrivialInout(_ x: inout Trivial) {
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: namespace UseCxxTy __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("UseCxxTy") {
// CHECK-NEXT: namespace UseCxxTy SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("UseCxxTy") {
// CHECK-EMPTY:
// CHECK-NEXT: SWIFT_INLINE_THUNK ns::NonTrivialTemplate<ns::TrivialinNS> retNonTrivial2() noexcept SWIFT_SYMBOL({{.*}}) SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: alignas(alignof(ns::NonTrivialTemplate<ns::TrivialinNS>)) char storage[sizeof(ns::NonTrivialTemplate<ns::TrivialinNS>)];

View File

@@ -30,7 +30,7 @@ public final actor ActorWithField {
}
}
// CHECK: namespace Actor __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Actor") {
// CHECK: namespace Actor SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Actor") {
// CHECK: SWIFT_EXTERN void * _Nonnull $s5Actor0A9WithFieldCACycfC(SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // init()
// CHECK: SWIFT_EXTERN void $s5Actor0A9WithFieldC6methodyyF(SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // method()

View File

@@ -21,14 +21,14 @@ public final class ClassWithIntField {
}
}
// CHECK: namespace Class __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Class") {
// CHECK: namespace Class SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Class") {
// CHECK: SWIFT_EXTERN void * _Nonnull $s5Class011passThroughA12WithIntFieldyAA0adeF0CADF(void * _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // passThroughClassWithIntField(_:)
// CHECK-NEXT: SWIFT_EXTERN void * _Nonnull $s5Class06returnA12WithIntFieldAA0acdE0CyF(void) SWIFT_NOEXCEPT SWIFT_CALL; // returnClassWithIntField()
// CHECK-NEXT: SWIFT_EXTERN void $s5Class04takeA12WithIntFieldyyAA0acdE0CF(void * _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // takeClassWithIntField(_:)
// CHECK-NEXT: SWIFT_EXTERN void $s5Class04takeA17WithIntFieldInoutyyAA0acdE0CzF(void * _Nonnull * _Nonnull x) SWIFT_NOEXCEPT SWIFT_CALL; // takeClassWithIntFieldInout(_:)
// CHECK: namespace Class __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Class") {
// CHECK: namespace Class SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Class") {
// CHECK: class SWIFT_SYMBOL("s:5Class0A12WithIntFieldC") ClassWithIntField;
// CHECK-NEXT: } // end namespace
@@ -43,7 +43,7 @@ public final class ClassWithIntField {
// CHECK-NEXT: } // namespace swift
// CHECK: namespace
// CHECK-SAME: Class __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Class") {
// CHECK-SAME: Class SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Class") {
// CHECK: namespace
// CHECK-SAME: _impl {
@@ -100,7 +100,7 @@ public final class ClassWithIntField {
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: namespace Class __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Class") {
// CHECK-NEXT: namespace Class SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Class") {
// CHECK: SWIFT_INLINE_THUNK ClassWithIntField passThroughClassWithIntField(const ClassWithIntField& x) noexcept SWIFT_SYMBOL("s:5Class011passThroughA12WithIntFieldyAA0adeF0CADF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return _impl::_impl_ClassWithIntField::makeRetained(_impl::$s5Class011passThroughA12WithIntFieldyAA0adeF0CADF(::swift::_impl::_impl_RefCountedClass::getOpaquePointer(x)));

View File

@@ -22,5 +22,5 @@ public func reprintedInImportedModule() -> Int {
return 42
}
// CHECK: namespace Core __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Core") {
// CHECK: namespace Core SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Core") {
// CHECK: swift::Int reprintedInImportedModule() noexcept SWIFT_SYMBOL("s:4Core25reprintedInImportedModuleSiyF") SWIFT_WARN_UNUSED_RESULT {

View File

@@ -6,7 +6,7 @@
// REQUIRES: PTRSIZE=64
// CHECK: namespace swift {
// CHECK: namespace swift SWIFT_PRIVATE_ATTR {
// CHECK: namespace _impl {

View File

@@ -7,7 +7,7 @@
// CHECK: #ifndef SWIFT_PRINTED_CORE
// CHECK-NEXT: #define SWIFT_PRINTED_CORE
// CHECK-NEXT: namespace swift {
// CHECK-NEXT: namespace swift SWIFT_PRIVATE_ATTR {
// CHECK-EMPTY:
// CHECK-NEXT: namespace _impl {
// CHECK-EMPTY:

View File

@@ -166,7 +166,7 @@ public struct S {
// CHECK-NEXT: #endif
// CHECK-NEXT: vwTable->initializeWithTake(destStorage, srcStorage, metadata._0);
// CHECK-NEXT: }
// CHECK: namespace Enums __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Enums") {
// CHECK: namespace Enums SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Enums") {
// CHECK: SWIFT_INLINE_THUNK E E::_impl_x::operator()(double val) const {
// CHECK-NEXT: auto result = E::_make();
// CHECK-NEXT: memcpy(result._getOpaquePointer(), &val, sizeof(val));

View File

@@ -5,7 +5,7 @@
public enum EmptyEnum {}
public enum SingleCaseEnum { case first }
// CHECK: namespace Enums __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Enums") {
// CHECK: namespace Enums SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Enums") {
// CHECK-NOT: EmptyEnum final {
// CHECK-NOT: SingleCaseEnum final {
// CHECK: } // namespace Enums

View File

@@ -5,5 +5,5 @@
// CHECK: namespace function_with_array
// FIXME: we don't actually emit a declaration for this, but for now at least
// check that we don't crash.
// CHECK: void f(const Swift::Array<swift::Int>&
// CHECK: void f(const swift::Array<swift::Int>&
public func f(_: [Int]) { }

View File

@@ -4,7 +4,7 @@
// RUN: %check-interop-cxx-header-in-clang(%t/cdecl.h)
// CHECK-LABEL: namespace CdeclFunctions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("CdeclFunctions") {
// CHECK-LABEL: namespace CdeclFunctions SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("CdeclFunctions") {
// CHECK: namespace _impl {
// CHECK: SWIFT_EXTERN int cfuncPassTwo(int x, int y) SWIFT_NOEXCEPT;

View File

@@ -4,7 +4,7 @@
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
// CHECK-LABEL: namespace Functions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-LABEL: namespace Functions SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-LABEL: namespace _impl {

View File

@@ -22,14 +22,14 @@
int main() {
// Test Empty Constructor
auto testIntEmpty = Swift::Expected<int>();
auto testIntEmpty = swift::Expected<int>();
// Test Error Constructor
Swift::Error e;
auto testIntError = Swift::Expected<int>(e);
swift::Error e;
auto testIntError = swift::Expected<int>(e);
// Test Value Constructor
auto testIntValue = Swift::Expected<int>(42);
auto testIntValue = swift::Expected<int>(42);
// Test Copy Constructor
auto testCopy = testIntEmpty;
@@ -37,9 +37,9 @@ int main() {
// TODO: Test Move Constructor
// Test Destructor
auto testDestEmpty = Swift::Expected<int>();
auto testDestInt = Swift::Expected<int>(42);
auto testDestError = Swift::Expected<int>(e);
auto testDestEmpty = swift::Expected<int>();
auto testDestInt = swift::Expected<int>(42);
auto testDestError = swift::Expected<int>(e);
testDestEmpty.~Expected();
testDestInt.~Expected();
testDestError.~Expected();

View File

@@ -28,12 +28,12 @@ int main() {
try {
Functions::emptyThrowFunction();
} catch (Swift::Error& e) {
} catch (swift::Error& e) {
printf("Exception\n");
}
try {
Functions::throwFunction();
} catch (Swift::Error& e) {
} catch (swift::Error& e) {
auto errorOpt = e.as<Functions::NaiveErrors>();
assert(errorOpt.isSome());
@@ -43,12 +43,12 @@ int main() {
}
try {
Functions::throwFunctionWithReturn();
} catch (Swift::Error& e) {
} catch (swift::Error& e) {
printf("Exception\n");
}
try {
Functions::testDestroyedError();
} catch(const Swift::Error &e) { }
} catch(const swift::Error &e) { }
return 0;
}

View File

@@ -7,7 +7,7 @@
// for experimental feature GenerateBindingsForThrowingFunctionsInCXX:
// REQUIRES: asserts
// CHECK-LABEL: namespace Functions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-LABEL: namespace Functions SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-LABEL: namespace _impl {
@@ -33,15 +33,15 @@ public enum NaiveErrors : Error {
@_expose(Cxx)
public func emptyThrowFunction() throws { print("passEmptyThrowFunction") }
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<void> emptyThrowFunction() SWIFT_SYMBOL("s:9Functions18emptyThrowFunctionyyKF") {
// CHECK: SWIFT_INLINE_THUNK swift::ThrowingResult<void> emptyThrowFunction() SWIFT_SYMBOL("s:9Functions18emptyThrowFunctionyyKF") {
// CHECK: void* opaqueError = nullptr;
// CHECK: void* _ctx = nullptr;
// CHECK: _impl::$s9Functions18emptyThrowFunctionyyKF(_ctx, &opaqueError);
// CHECK: if (opaqueError != nullptr)
// CHECK: #ifdef __cpp_exceptions
// CHECK: throw (Swift::Error(opaqueError));
// CHECK: throw (swift::Error(opaqueError));
// CHECK: #else
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
// CHECK: return swift::Expected<void>(swift::Error(opaqueError));
// CHECK: #endif
// CHECK: }
@@ -59,15 +59,15 @@ public struct DestroyedError : Error {
@_expose(Cxx)
public func testDestroyedError() throws { throw DestroyedError() }
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<void> testDestroyedError() SWIFT_SYMBOL("s:9Functions18testDestroyedErroryyKF") {
// CHECK: SWIFT_INLINE_THUNK swift::ThrowingResult<void> testDestroyedError() SWIFT_SYMBOL("s:9Functions18testDestroyedErroryyKF") {
// CHECK: void* opaqueError = nullptr;
// CHECK: void* _ctx = nullptr;
// CHECK: _impl::$s9Functions18testDestroyedErroryyKF(_ctx, &opaqueError);
// CHECK: if (opaqueError != nullptr)
// CHECK: #ifdef __cpp_exceptions
// CHECK: throw (Swift::Error(opaqueError));
// CHECK: throw (swift::Error(opaqueError));
// CHECK: #else
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
// CHECK: return swift::Expected<void>(swift::Error(opaqueError));
// CHECK: #endif
// CHECK: }
@@ -77,15 +77,15 @@ public func throwFunction() throws {
throw NaiveErrors.throwError
}
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<void> throwFunction() SWIFT_SYMBOL("s:9Functions13throwFunctionyyKF") {
// CHECK: SWIFT_INLINE_THUNK swift::ThrowingResult<void> throwFunction() SWIFT_SYMBOL("s:9Functions13throwFunctionyyKF") {
// CHECK: void* opaqueError = nullptr;
// CHECK: void* _ctx = nullptr;
// CHECK: _impl::$s9Functions13throwFunctionyyKF(_ctx, &opaqueError);
// CHECK: if (opaqueError != nullptr)
// CHECK: #ifdef __cpp_exceptions
// CHECK: throw (Swift::Error(opaqueError));
// CHECK: throw (swift::Error(opaqueError));
// CHECK: #else
// CHECK: return Swift::Expected<void>(Swift::Error(opaqueError));
// CHECK: return swift::Expected<void>(swift::Error(opaqueError));
// CHECK: #endif
// CHECK: }
@@ -98,15 +98,15 @@ public func throwFunctionWithPossibleReturn(_ a: Int) throws -> Int {
return 0
}
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<swift::Int> throwFunctionWithPossibleReturn(swift::Int a) SWIFT_SYMBOL("s:9Functions31throwFunctionWithPossibleReturnyS2iKF") SWIFT_WARN_UNUSED_RESULT {
// CHECK: SWIFT_INLINE_THUNK swift::ThrowingResult<swift::Int> throwFunctionWithPossibleReturn(swift::Int a) SWIFT_SYMBOL("s:9Functions31throwFunctionWithPossibleReturnyS2iKF") SWIFT_WARN_UNUSED_RESULT {
// CHECK: void* opaqueError = nullptr;
// CHECK: void* _ctx = nullptr;
// CHECK: auto returnValue = _impl::$s9Functions31throwFunctionWithPossibleReturnyS2iKF(a, _ctx, &opaqueError);
// CHECK: if (opaqueError != nullptr)
// CHECK: #ifdef __cpp_exceptions
// CHECK: throw (Swift::Error(opaqueError));
// CHECK: throw (swift::Error(opaqueError));
// CHECK: #else
// CHECK: return Swift::Expected<swift::Int>(Swift::Error(opaqueError));
// CHECK: return swift::Expected<swift::Int>(swift::Error(opaqueError));
// CHECK: #endif
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, returnValue);
// CHECK: }
@@ -118,14 +118,14 @@ public func throwFunctionWithReturn() throws -> Int {
return 0
}
// CHECK: SWIFT_INLINE_THUNK Swift::ThrowingResult<swift::Int> throwFunctionWithReturn() SWIFT_SYMBOL("s:9Functions23throwFunctionWithReturnSiyKF") SWIFT_WARN_UNUSED_RESULT {
// CHECK: SWIFT_INLINE_THUNK swift::ThrowingResult<swift::Int> throwFunctionWithReturn() SWIFT_SYMBOL("s:9Functions23throwFunctionWithReturnSiyKF") SWIFT_WARN_UNUSED_RESULT {
// CHECK: void* opaqueError = nullptr;
// CHECK: void* _ctx = nullptr;
// CHECK: auto returnValue = _impl::$s9Functions23throwFunctionWithReturnSiyKF(_ctx, &opaqueError);
// CHECK: #ifdef __cpp_exceptions
// CHECK: throw (Swift::Error(opaqueError));
// CHECK: throw (swift::Error(opaqueError));
// CHECK: #else
// CHECK: return Swift::Expected<swift::Int>(Swift::Error(opaqueError));
// CHECK: return swift::Expected<swift::Int>(swift::Error(opaqueError));
// CHECK: #endif
// CHECK: return SWIFT_RETURN_THUNK(swift::Int, returnValue);
// CHECK: }

View File

@@ -4,7 +4,7 @@
// RUN: %check-interop-cxx-header-in-clang(%t/functions.h)
// CHECK-LABEL: namespace Functions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-LABEL: namespace Functions SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-LABEL: namespace _impl {

View File

@@ -6,7 +6,7 @@
// CHECK-NOT: SWIFT_EXTERN bool $s9Functions24alwaysEmitIntoClientFuncyS2bF(bool x) SWIFT_NOEXCEPT SWIFT_CALL; // alwaysEmitIntoClientFunc(_:)
// CHECK: namespace Functions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Functions") {
// CHECK: namespace Functions SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: } // namespace Functions

View File

@@ -6,7 +6,7 @@
// CHECK-NOT: SWIFT_EXTERN double $s9Functions9asyncFuncyS2dYaF(double x) SWIFT_NOEXCEPT SWIFT_CALL; // asyncFunc(_:)
// CHECK: namespace Functions __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Functions") {
// CHECK: namespace Functions SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Functions") {
// CHECK-EMPTY:
// CHECK-EMPTY:
// CHECK-NEXT: } // namespace Functions

View File

@@ -39,7 +39,7 @@ public struct LaterGeneric<T> {
// CHECK: class SWIFT_SYMBOL("s:8Generics14ComesFirstEnumO") ComesFirstEnum final {
// CHECK: LaterGeneric<ComesFirstEnum> returnsLaterOpt() const SWIFT_SYMBOL("s:8Generics14ComesFirstEnumO15returnsLaterOptAA0F7GenericVyACGyF");
// CHECK: namespace Generics __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Generics") {
// CHECK: namespace Generics SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Generics") {
// CHECK-EMPTY:
// CHECK-NEXT: namespace _impl {
// CHECK-EMPTY:

View File

@@ -9,7 +9,7 @@
// CHECK-NEXT: #endif
// CHECK-NEXT: #define SWIFT_SYMBOL(usrValue) SWIFT_SYMBOL_MODULE_USR("Test", usrValue)
// CHECK-LABEL: namespace Test __attribute__((swift_private)) SWIFT_SYMBOL_MODULE({{.*}}) {
// CHECK-LABEL: namespace Test SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE({{.*}}) {
// CHECK: } // namespace Test
// CHECK-EMPTY:
// CHECK-NEXT: #undef SWIFT_SYMBOL

View File

@@ -32,7 +32,7 @@ public func printArray(_ val: Array<CInt>) {
#include "UseArray.h"
int main() {
using namespace Swift;
using namespace swift;
{
Array<int> val = UseArray::createArray(2);

View File

@@ -78,7 +78,7 @@ public func resetOpt<T>(_ val: inout Optional<T>) {
#include "UseOptional.h"
int main() {
using namespace Swift;
using namespace swift;
using namespace UseOptional;
{

View File

@@ -54,21 +54,21 @@ public func resetOpt<T>(_ val: inout Optional<T>) {
}
// CHECK: SWIFT_INLINE_THUNK Swift::Optional<int> createCIntOpt(int val) noexcept SWIFT_SYMBOL("s:11UseOptional13createCIntOptys5Int32VSgADF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return Swift::_impl::_impl_Optional<int>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
// CHECK: SWIFT_INLINE_THUNK swift::Optional<int> createCIntOpt(int val) noexcept SWIFT_SYMBOL("s:11UseOptional13createCIntOptys5Int32VSgADF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return swift::_impl::_impl_Optional<int>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
// CHECK-NEXT: _impl::swift_interop_returnDirect_UseOptional_[[CINTENC:[a-z0-9_]+]](result, _impl::$s11UseOptional13createCIntOptys5Int32VSgADF(val));
// CHECK-NEXT: });
// CHECK-NEXT: }
// CHECK: SWIFT_INLINE_THUNK Swift::Optional<Klass> createKlassOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional14createKlassOptyAA0D0CSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return Swift::_impl::_impl_Optional<Klass>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
// CHECK: SWIFT_INLINE_THUNK swift::Optional<Klass> createKlassOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional14createKlassOptyAA0D0CSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return swift::_impl::_impl_Optional<Klass>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
// CHECK-NEXT: _impl::swift_interop_returnDirect_UseOptional_[[CLASSENC:[a-z0-9_]+]](result, _impl::$s11UseOptional14createKlassOptyAA0D0CSgs5Int16VF(val));
// CHECK-NEXT: });
// CHECK-NEXT: }
// CHECK: SWIFT_INLINE_THUNK Swift::Optional<SmallStruct> createSmallStructOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return Swift::_impl::_impl_Optional<SmallStruct>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
// CHECK: SWIFT_INLINE_THUNK swift::Optional<SmallStruct> createSmallStructOpt(int16_t val) noexcept SWIFT_SYMBOL("s:11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF") SWIFT_WARN_UNUSED_RESULT {
// CHECK-NEXT: return swift::_impl::_impl_Optional<SmallStruct>::returnNewValue([&](char * _Nonnull result) SWIFT_INLINE_THUNK_ATTRIBUTES {
// CHECK-NEXT: _impl::swift_interop_returnDirect_UseOptional_uint32_t_0_4(result, _impl::$s11UseOptional20createSmallStructOptyAA0dE0VSgs5Int16VF(val));
// CHECK-NEXT: });
// CHECK-NEXT: }
@@ -78,24 +78,24 @@ public func resetOpt<T>(_ val: inout Optional<T>) {
// CHECK-NEXT: #ifdef __cpp_concepts
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0>
// CHECK-NEXT: #endif
// CHECK-NEXT: SWIFT_INLINE_THUNK void resetOpt(Swift::Optional<T_0_0>& val) noexcept SWIFT_SYMBOL("s:11UseOptional8resetOptyyxSgzlF") {
// CHECK-NEXT: SWIFT_INLINE_THUNK void resetOpt(swift::Optional<T_0_0>& val) noexcept SWIFT_SYMBOL("s:11UseOptional8resetOptyyxSgzlF") {
// CHECK-NEXT: #ifndef __cpp_concepts
// CHECK-NEXT: static_assert(swift::isUsableInGenericContext<T_0_0>, "type cannot be used in a Swift generic context");
// CHECK-NEXT: #endif
// CHECK-NEXT: return _impl::$s11UseOptional8resetOptyyxSgzlF(Swift::_impl::_impl_Optional<T_0_0>::getOpaquePointer(val), swift::TypeMetadataTrait<T_0_0>::getTypeMetadata());
// CHECK-NEXT: return _impl::$s11UseOptional8resetOptyyxSgzlF(swift::_impl::_impl_Optional<T_0_0>::getOpaquePointer(val), swift::TypeMetadataTrait<T_0_0>::getTypeMetadata());
// CHECK-NEXT: }
// CHECK: SWIFT_INLINE_THUNK void takeCIntOpt(const Swift::Optional<int>& val) noexcept SWIFT_SYMBOL("s:11UseOptional11takeCIntOptyys5Int32VSgF") {
// CHECK-NEXT: return _impl::$s11UseOptional11takeCIntOptyys5Int32VSgF(_impl::swift_interop_passDirect_UseOptional_[[CINTENC]](Swift::_impl::_impl_Optional<int>::getOpaquePointer(val)));
// CHECK: SWIFT_INLINE_THUNK void takeCIntOpt(const swift::Optional<int>& val) noexcept SWIFT_SYMBOL("s:11UseOptional11takeCIntOptyys5Int32VSgF") {
// CHECK-NEXT: return _impl::$s11UseOptional11takeCIntOptyys5Int32VSgF(_impl::swift_interop_passDirect_UseOptional_[[CINTENC]](swift::_impl::_impl_Optional<int>::getOpaquePointer(val)));
// CHECK-NEXT: }
// CHECK: SWIFT_INLINE_THUNK void takeKlassOpt(const Swift::Optional<Klass>& val) noexcept SWIFT_SYMBOL("s:11UseOptional12takeKlassOptyyAA0D0CSgF") {
// CHECK-NEXT: return _impl::$s11UseOptional12takeKlassOptyyAA0D0CSgF(_impl::swift_interop_passDirect_UseOptional_[[CLASSENC]](Swift::_impl::_impl_Optional<Klass>::getOpaquePointer(val)));
// CHECK: SWIFT_INLINE_THUNK void takeKlassOpt(const swift::Optional<Klass>& val) noexcept SWIFT_SYMBOL("s:11UseOptional12takeKlassOptyyAA0D0CSgF") {
// CHECK-NEXT: return _impl::$s11UseOptional12takeKlassOptyyAA0D0CSgF(_impl::swift_interop_passDirect_UseOptional_[[CLASSENC]](swift::_impl::_impl_Optional<Klass>::getOpaquePointer(val)));
// CHECK-NEXT: }
// CHECK: SWIFT_INLINE_THUNK void takeSmallStructOpt(const Swift::Optional<SmallStruct>& val) noexcept SWIFT_SYMBOL("s:11UseOptional18takeSmallStructOptyyAA0dE0VSgF") {
// CHECK-NEXT: return _impl::$s11UseOptional18takeSmallStructOptyyAA0dE0VSgF(_impl::swift_interop_passDirect_UseOptional_uint32_t_0_4(Swift::_impl::_impl_Optional<SmallStruct>::getOpaquePointer(val)));
// CHECK: SWIFT_INLINE_THUNK void takeSmallStructOpt(const swift::Optional<SmallStruct>& val) noexcept SWIFT_SYMBOL("s:11UseOptional18takeSmallStructOptyyAA0dE0VSgF") {
// CHECK-NEXT: return _impl::$s11UseOptional18takeSmallStructOptyyAA0dE0VSgF(_impl::swift_interop_passDirect_UseOptional_uint32_t_0_4(swift::_impl::_impl_Optional<SmallStruct>::getOpaquePointer(val)));
// CHECK-NEXT: }

View File

@@ -17,5 +17,5 @@ public func test() -> String {
return ""
}
// CHECK: namespace Swift __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Swift") {
// CHECK: namespace swift SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("swift") {
// CHECK: class SWIFT_SYMBOL("{{.*}}") String final {

View File

@@ -28,7 +28,7 @@ public func makeString(_ s: String, _ y: String) -> String {
#include "Stringer.h"
int main() {
using namespace Swift;
using namespace swift;
using namespace Stringer;
{

View File

@@ -23,7 +23,7 @@ public func printString(_ s: String) {
#include "Stringer.h"
int main() {
using namespace Swift;
using namespace swift;
using namespace Stringer;
{

View File

@@ -27,7 +27,7 @@ public func createString(_ ptr: UnsafePointer<CChar>) -> String {
#include "StringCreator.h"
int main() {
using namespace Swift;
using namespace swift;
auto emptyString = String::init();
NSString *nsStr = emptyString;
}
@@ -45,7 +45,7 @@ int main() {
#include "StringCreator.h"
int main() {
using namespace Swift;
using namespace swift;
auto emptyString = String::init();

View File

@@ -4,7 +4,7 @@
// RUN: %check-interop-cxx-header-in-clang(%t/Swift.h -DSWIFT_CXX_INTEROP_HIDE_STL_OVERLAY -Wno-unused-private-field -Wno-unused-function -Wc++98-compat-extra-semi)
// CHECK: namespace Swift __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Swift") {
// CHECK: namespace swift SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("swift") {
// CHECK: template<class T_0_0>
// CHECK-NEXT: #ifdef __cpp_concepts
@@ -107,7 +107,7 @@
// CHECK: SWIFT_INLINE_THUNK UTF8View(UTF8View &&) { abort(); }
// CHECK-NEXT: SWIFT_INLINE_THUNK String_Index getStartIndex() const SWIFT_SYMBOL({{.*}});
// CHECK-NEXT: SWIFT_INLINE_THUNK String_Index getEndIndex() const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK Swift::Optional<String_Index> indexOffsetByLimitedBy(const String_Index& i, swift::Int n, const String_Index& limit) const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK swift::Optional<String_Index> indexOffsetByLimitedBy(const String_Index& i, swift::Int n, const String_Index& limit) const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK swift::Int distanceFromTo(const String_Index& i, const String_Index& j) const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK uint8_t operator [](const String_Index& i) const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK String getDescription() const SWIFT_SYMBOL({{.*}});
@@ -124,4 +124,4 @@
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>
// CHECK-NEXT: #endif
// CHECK: } // namespace Swift
// CHECK: } // namespace swift

View File

@@ -100,7 +100,7 @@ public struct FirstSmallStruct {
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: namespace Structs __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Structs") {
// CHECK-NEXT: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
@frozen public struct FrozenStruct {
private let storedInt: Int32

View File

@@ -4,10 +4,10 @@
// RUN: %check-interop-cxx-header-in-clang(%t/structs.h -Wno-unused-private-field -Wno-unused-function)
// CHECK: namespace Structs __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: namespace _impl {
// CHECK: namespace Structs __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: class SWIFT_SYMBOL("s:7Structs18StructWithIntFieldV") StructWithIntField;
// CHECK-NEXT: } // end namespace
@@ -20,7 +20,7 @@
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: } // namespace swift
// CHECK: namespace Structs __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: namespace _impl {
// CHECK-EMPTY:
@@ -103,7 +103,7 @@
// CHECK-NEXT: #pragma clang diagnostic pop
// CHECK-NEXT: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: namespace Structs __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Structs") {
// CHECK-NEXT: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
public struct StructWithIntField {
let field: Int64

View File

@@ -2,7 +2,7 @@
// RUN: %target-swift-frontend %s -typecheck -module-name Structs -clang-header-expose-decls=all-public -emit-clang-header-path %t/structs.h
// RUN: %FileCheck %s < %t/structs.h
// CHECK: namespace Structs __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Structs") {
// CHECK: namespace Structs SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("Structs") {
// CHECK-NOT: class SWIFT_SYMBOL({{.*}}) ZeroSizedStruct final {

View File

@@ -32,6 +32,6 @@ public func testFunction() -> String {
return ""
}
// CHECK: namespace Swift __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("Swift") {
// CHECK: namespace SwiftMod __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("SwiftMod") {
// CHECK-NOT: namespace Swift {
// CHECK: namespace swift SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("swift") {
// CHECK: namespace SwiftMod SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("SwiftMod") {
// CHECK-NOT: namespace swift {

View File

@@ -103,7 +103,7 @@
// CHECK: } // namespace swift
// CHECK-EMPTY:
// CHECK-NEXT: #endif
// CHECK: namespace empty __attribute__((swift_private)) SWIFT_SYMBOL_MODULE("empty") {
// CHECK: namespace empty SWIFT_PRIVATE_ATTR SWIFT_SYMBOL_MODULE("empty") {
// CHECK: } // namespace empty
// CHECK: #endif