Skip to content
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

[cxx-interop] Implicitly import Cxx module #60603

Merged
merged 2 commits into from
Oct 20, 2022
Merged

Conversation

egorzhdan
Copy link
Contributor

This lifts the requirement for the user to explicitly add import Cxx in Swift code that relies on protocols from the Cxx module, such as CxxSequence.

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Aug 17, 2022
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@stevapple
Copy link
Contributor

Should we rename it to _Cxx to align with other implicitly imported "standard" libraries?

@egorzhdan
Copy link
Contributor Author

@stevapple underscored names are generally used for something the developer wouldn't need to reference directly from Swift code. This module could be referenced directly, for example, if someone needs to provide a utility extension to one of the protocols from Cxx module:

// Util.swift
import Cxx

extension CxxSequence where RawIterator: ... {
  func doSomething() { ... }
}

Note that we don't always implicitly import Cxx, we only do that for C++ modules that are being imported into Swift, so without import Cxx the above snippet wouldn't compile.

@stevapple
Copy link
Contributor

Ah, makes sense👌

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

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

Thanks for fixing all these tests!

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@ktoso
Copy link
Contributor

ktoso commented Oct 18, 2022

Hooray, makes a lot of sense +1

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

This lifts the requirement for the user to explicitly add `import Cxx` in Swift code that relies on protocols from the `Cxx` module, such as `CxxSequence`.
`Swift` is the name of the Swift standard library module. Creating another module with this name breaks assumptions in the compiler and caused these two tests to fail.
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test macOS

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.

4 participants