Skip to content

Ensure that bridged types are indirectly returned on Windows ARM64 #76589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions include/swift/AST/ASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class BridgedDeclBaseName {
BridgedIdentifier Ident;

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedDeclBaseName() : Ident() {}

#ifdef USED_IN_CPP_SOURCE
BridgedDeclBaseName(swift::DeclBaseName baseName) : Ident(baseName.Ident) {}

Expand All @@ -107,6 +111,10 @@ class BridgedDeclNameRef {
void *_Nonnull opaque;

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedDeclNameRef() : opaque() {}

#ifdef USED_IN_CPP_SOURCE
BridgedDeclNameRef(swift::DeclNameRef name) : opaque(name.getOpaqueValue()) {}

Expand Down Expand Up @@ -163,6 +171,10 @@ class BridgedASTContext {
swift::ASTContext * _Nonnull Ctx;

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedASTContext() : Ctx() {}

#ifdef USED_IN_CPP_SOURCE
SWIFT_UNAVAILABLE("Use init(raw:) instead")
BridgedASTContext(swift::ASTContext &ctx) : Ctx(&ctx) {}
Expand Down Expand Up @@ -390,6 +402,10 @@ class BridgedDiagnosticArgument {
int64_t storage[3];

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedDiagnosticArgument() {}

#ifdef USED_IN_CPP_SOURCE
BridgedDiagnosticArgument(const swift::DiagnosticArgument &arg) {
*reinterpret_cast<swift::DiagnosticArgument *>(&storage) = arg;
Expand All @@ -407,6 +423,10 @@ class BridgedDiagnosticFixIt {
int64_t storage[7];

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedDiagnosticFixIt() {}

#ifdef USED_IN_CPP_SOURCE
BridgedDiagnosticFixIt(const swift::DiagnosticInfo::FixIt &fixit){
*reinterpret_cast<swift::DiagnosticInfo::FixIt *>(&storage) = fixit;
Expand Down Expand Up @@ -1406,6 +1426,10 @@ class BridgedStmtConditionElement {
void *_Nonnull Raw;

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedStmtConditionElement() {}

#ifdef USED_IN_CPP_SOURCE
BridgedStmtConditionElement(swift::StmtConditionElement elem)
: Raw(elem.getOpaqueValue()) {}
Expand Down
13 changes: 13 additions & 0 deletions include/swift/Basic/BasicBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
// Pure bridging mode does not permit including any C++/llvm/swift headers.
// See also the comments for `BRIDGING_MODE` in the top-level CMakeLists.txt file.
//
//
// Note: On Windows ARM64, how a C++ struct/class value type is
// returned is sensitive to conditions including whether a
// user-defined constructor exists, etc. See
// https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values
// So, if a C++ struct/class type is returned as a value between Swift
// and C++, we need to be careful to match the return convention
// matches between the non-USED_IN_CPP_SOURCE (Swift) side and the
// USE_IN_CPP_SOURCE (C++) side.
#include "swift/Basic/BridgedSwiftObject.h"
#include "swift/Basic/Compiler.h"

Expand Down Expand Up @@ -227,6 +236,10 @@ class BridgedOwnedString {
size_t Length;

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedOwnedString() {}

#ifdef USED_IN_CPP_SOURCE
BridgedOwnedString(const std::string &stringToCopy);

Expand Down
4 changes: 4 additions & 0 deletions include/swift/Parse/ParseBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class BridgedLegacyParser {
swift::Parser *_Nonnull const handle;

public:
// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLegacyParser() : handle(nullptr) {}

#ifdef USED_IN_CPP_SOURCE
BridgedLegacyParser(swift::Parser &P) : handle(&P) {}

Expand Down
48 changes: 48 additions & 0 deletions include/swift/SIL/SILBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ struct BridgedResultInfo {
swift::TypeBase * _Nonnull type;
BridgedResultConvention convention;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedResultInfo() {}

#ifdef USED_IN_CPP_SOURCE
inline static BridgedResultConvention
castToResultConvention(swift::ResultConvention convention) {
Expand All @@ -100,6 +104,10 @@ struct OptionalBridgedResultInfo {
swift::TypeBase * _Nullable type = nullptr;
BridgedResultConvention convention = BridgedResultConvention::Indirect;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
OptionalBridgedResultInfo() {}

#ifdef USED_IN_CPP_SOURCE
OptionalBridgedResultInfo(std::optional<swift::SILResultInfo> resultInfo) {
if (resultInfo) {
Expand All @@ -114,6 +122,10 @@ struct OptionalBridgedResultInfo {
struct BridgedResultInfoArray {
BridgedArrayRef resultInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedResultInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedResultInfoArray(llvm::ArrayRef<swift::SILResultInfo> results)
: resultInfoArray(results) {}
Expand Down Expand Up @@ -217,6 +229,10 @@ struct BridgedParameterInfo {
struct BridgedParameterInfoArray {
BridgedArrayRef parameterInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedParameterInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedParameterInfoArray(llvm::ArrayRef<swift::SILParameterInfo> parameters)
: parameterInfoArray(parameters) {}
Expand All @@ -235,6 +251,10 @@ struct BridgedParameterInfoArray {
struct BridgedYieldInfoArray {
BridgedArrayRef yieldInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedYieldInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedYieldInfoArray(llvm::ArrayRef<swift::SILYieldInfo> yields)
: yieldInfoArray(yields) {}
Expand All @@ -255,6 +275,10 @@ struct BridgedLifetimeDependenceInfo {
SwiftUInt targetIndex;
bool immortal;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLifetimeDependenceInfo() {}

#ifdef USED_IN_CPP_SOURCE
BridgedLifetimeDependenceInfo(swift::LifetimeDependenceInfo info)
: inheritLifetimeParamIndices(info.getInheritIndices()),
Expand All @@ -273,6 +297,10 @@ struct BridgedLifetimeDependenceInfo {
struct BridgedLifetimeDependenceInfoArray {
BridgedArrayRef lifetimeDependenceInfoArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLifetimeDependenceInfoArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedLifetimeDependenceInfoArray(
llvm::ArrayRef<swift::LifetimeDependenceInfo> lifetimeDependenceInfo)
Expand Down Expand Up @@ -373,6 +401,10 @@ struct BridgedType {
struct EnumElementIterator {
uint64_t storage[4];

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
EnumElementIterator() {}

#ifdef USED_IN_CPP_SOURCE
EnumElementIterator(swift::EnumDecl::ElementRange::iterator i) {
static_assert(sizeof(EnumElementIterator) >= sizeof(swift::EnumDecl::ElementRange::iterator));
Expand All @@ -386,6 +418,10 @@ struct BridgedType {
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE EnumElementIterator getNext() const;
};

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedType() {}

#ifdef USED_IN_CPP_SOURCE
BridgedType(swift::SILType t) : opaqueValue(t.getOpaqueValue()) {}

Expand Down Expand Up @@ -573,6 +609,10 @@ enum class BridgedMemoryBehavior {
struct BridgedLocation {
uint64_t storage[3];

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedLocation() {}

#ifdef USED_IN_CPP_SOURCE
BridgedLocation(const swift::SILDebugLocation &loc) {
*reinterpret_cast<swift::SILDebugLocation *>(&storage) = loc;
Expand Down Expand Up @@ -804,6 +844,10 @@ struct BridgedTypeArray {
struct BridgedSILTypeArray {
BridgedArrayRef typeArray;

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
BridgedSILTypeArray() {}

#ifdef USED_IN_CPP_SOURCE
BridgedSILTypeArray(llvm::ArrayRef<swift::SILType> silTypes)
: typeArray(silTypes) {}
Expand All @@ -826,6 +870,10 @@ struct BridgedGenericSpecializationInformation {
struct OptionalBridgedSILDebugVariable {
uint64_t storage[16];

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
OptionalBridgedSILDebugVariable() {}

#ifdef USED_IN_CPP_SOURCE
using OptionalSILDebugVariable = std::optional<swift::SILDebugVariable>;

Expand Down
4 changes: 4 additions & 0 deletions include/swift/SILOptimizer/OptimizerBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ struct BridgedCalleeAnalysis {
struct CalleeList {
uint64_t storage[3];

// Ensure that this struct value type will be indirectly returned on
// Windows ARM64
CalleeList() {}

#ifdef USED_IN_CPP_SOURCE
CalleeList(swift::CalleeList list) {
*reinterpret_cast<swift::CalleeList *>(&storage) = list;
Expand Down