Skip to content

Conversation

susmonteiro
Copy link
Contributor

CxxRecordSemantics determines how C++ APIs are imported to Swift, e.g., as owned, reference or iterator types. Since this is orthogonal to importing a type as copyable or move-only, we separate CxxRecordSemantics from CxxValueSemantics.

@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

}

llvm_unreachable("Could not classify C++ type.");
return CxxRecordSemanticsKind::Owned;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Owned might not be the right default here. Owned means that it cannot dangle. Maybe we need to introduce a placeholder here, like Value?

};

enum class CxxRecordSemanticsKind {
Trivial,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit conflicted what to do with Trivial. Do you know what do we use this for? Because I think this might be more of a description of how the class is being copied/moved, passed around as an implementation detail rather than a semantic property.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wonder if we can replace Trivial with Value to indicate a value type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we would replace both Trivial and Owned with Value?

The only place we use this distinction is in SwiftDeclSynthesizer::findExplicitDestroy, when we emit a diagnostic for an illegal destroy operation. But I think I can work around that

@susmonteiro susmonteiro force-pushed the susmonteiro/cxxrecord-semantics branch 2 times, most recently from 382c581 to 3d7d38c Compare September 12, 2025 14:22
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

@susmonteiro
Copy link
Contributor Author

@swift-ci please test windows

@susmonteiro susmonteiro force-pushed the susmonteiro/cxxrecord-semantics branch from 3d7d38c to 2640c71 Compare September 16, 2025 13:40
@susmonteiro
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, thanks!

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@susmonteiro
Copy link
Contributor Author

@swift-ci please test windows

@susmonteiro susmonteiro merged commit f648dbb into swiftlang:main Sep 17, 2025
3 checks passed
@susmonteiro susmonteiro deleted the susmonteiro/cxxrecord-semantics branch September 30, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ interop Feature: Interoperability with C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants