Skip to content

Conversation

@fahadnayyar
Copy link
Contributor

Update C++ interop documentation to describe Swift initializer support for C++ SWIFT_SHARED_REFERENCE type's constructors and static factories annotated with SWIFT_NAME.

@fahadnayyar fahadnayyar marked this pull request as ready for review June 11, 2025 01:03
…of SWIFT_SHARED_REFERENCE types as Swift Initializer
@fahadnayyar fahadnayyar force-pushed the cxx-frt-ctor-static-factory-docs branch from b8a4ffc to d61979c Compare June 11, 2025 04:31
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.

@fahadnayyar
Copy link
Contributor Author

CC: @j-hui
If you can also please take a look.

@fahadnayyar
Copy link
Contributor Author

CC: @ravikandhadai

In this case, Swift will import the static `make` function as a Swift initializer:
```swift
let object = SharedObject(id: 42)
Copy link
Contributor

Choose a reason for hiding this comment

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

The id label shouldn't be there, i.e.,

Suggested change
let object = SharedObject(id: 42)
let object = SharedObject(42)

But I think you should give more examples here. Also, doSomething() isn't really necessary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@j-hui Let's add more examples of using the SWIFT_NAME technique in a follow-up patch. We can experiment with this feature on some adopter projects or dummy examples before documenting.

let object = SharedObject(42)
```

Note that if a C++ constructor and a user-annotated static factory (using `SWIFT_NAME`) have identical parameter signatures, Swift favors the static factory when resolving initializer calls.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@j-hui @Xazax-hun : I'm torn between keeping this note and deleting it because it seems like I'm sharing too much information. What do you think?

@fahadnayyar
Copy link
Contributor Author

including this in PR-1106

@fahadnayyar fahadnayyar closed this Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants