Skip to content

[cxx-interop] Fix template parameter printing scheme for const types #79237

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 8 commits into from
Mar 1, 2025

Conversation

j-hui
Copy link
Contributor

@j-hui j-hui commented Feb 8, 2025

This patch changes the class template printer to disambiguate const-qualified template arguments by wrapping them with __cxxConst<>, rather than suffixing them with _const.

This is necessary to accommodate template arguments that aren't just identifiers (i.e., Foo<Int_const> is ok, but Foo<Bar<T>_const> and Foo<((Bar) -> Baz)_const> are not syntactically valid). With this patch, we would produce Foo<__cxxConst<Int>>, Foo<__cxxConst<Bar<T>>, and Foo<__cxxConst<((Bar) -> Baz)>> instead.

This patch also disambiguates volatile-qualified template arguments with __cxxVolatile<>, and changes the printing scheme for std::nullptr_t from nil to __cxxNullPtrT (since nil is not a syntactically valid type name).

rdar://143769901

@j-hui
Copy link
Contributor Author

j-hui commented Feb 8, 2025

@swift-ci please test

@j-hui j-hui force-pushed the fix-class-template-printer branch from 4a360c2 to 6906d27 Compare February 28, 2025 07:25
@j-hui
Copy link
Contributor Author

j-hui commented Feb 28, 2025

@swift-ci please smoke test

@j-hui j-hui requested a review from Xazax-hun February 28, 2025 07:28
@j-hui j-hui marked this pull request as ready for review February 28, 2025 08:02
@j-hui
Copy link
Contributor Author

j-hui commented Feb 28, 2025

@swift-ci please test

@j-hui
Copy link
Contributor Author

j-hui commented Feb 28, 2025

Oops, I realized I had left a stray ) in the output printer...

(Also my local tests were "succeeding" because they were unsupported 🙃)

@j-hui
Copy link
Contributor Author

j-hui commented Feb 28, 2025

@swift-ci Please test

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.

The ClangImporter part of this change LGTM!

I haven't reviewed the macro changes.

@j-hui j-hui merged commit 1405520 into swiftlang:main Mar 1, 2025
5 checks passed
@j-hui j-hui deleted the fix-class-template-printer branch March 1, 2025 03:42
@j-hui j-hui added the c++ interop Feature: Interoperability with C++ label Mar 13, 2025
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