Skip to content

[cxx-interop] Re-implement template mangling. #62989

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 5 commits into from
Feb 22, 2023

Conversation

zoecarver
Copy link
Contributor

Instead of mangling class template specializations with the prefix "__CxxTemplateInst," simply set the decl name as the class templates plus the types that it is specialized on (so vector<Int> rather than __CxxTemplateInstNSt3__16vectorIi...).

This is mainly to improve diagnostics. As a side effect of this change, if anyone copies the name of a class template specialization from an error/warning and uses it in source code, the compiler will error (that class templates aren't available in swift) rather than silently passing only to cause serialization failures down the road.

@zoecarver
Copy link
Contributor Author

There are still about 30 failing tests and I should also write some new tests, so I'm keeping this as a draft.

if (!Lexer::isIdentifier(baseName) && !Lexer::isOperator(baseName))
return DeclNameRef();
// if (!Lexer::isIdentifier(baseName) && !Lexer::isOperator(baseName))
// return DeclNameRef();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will need to find a better condition here. I will probably just make this an assert and put it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't forgotten about this, just want to see how we're doing on tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually don't know how helpful this behavior is. I am going to remove this from the patch and if the code owners feel that we need further validation of names then let's add this as an assert after the fact.

@zoecarver zoecarver marked this pull request as ready for review February 12, 2023 23:03
@zoecarver zoecarver force-pushed the class-template-name-mangling branch from ca47396 to 611e6f5 Compare February 12, 2023 23:05
@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver zoecarver force-pushed the class-template-name-mangling branch from 611e6f5 to 3de5e89 Compare February 13, 2023 18:08
@zoecarver
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver zoecarver force-pushed the class-template-name-mangling branch from 3de5e89 to 1862e69 Compare February 13, 2023 19:33
@xedin xedin removed their request for review February 13, 2023 21:09
@zoecarver
Copy link
Contributor Author

@swift-ci please test macOS

@zoecarver
Copy link
Contributor Author

@swift-ci please test Windows

@zoecarver
Copy link
Contributor Author

@swift-ci please test macOS

Instead of mangling class template specializations with the prefix "__CxxTemplateInst," simply set the decl name as the class templates plus the types that it is specialized on (so `vector<Int>` rather than `__CxxTemplateInstNSt3__16vectorIi...`).

This is mainly to improve diagnostics. As a side effect of this change, if anyone copies the name of a class template specializaiton from an error/warning and uses it in source code, the compiler will error (that class templates aren't available in swift) rather than silently passing only to cause serailization failures down the road.
@zoecarver zoecarver force-pushed the class-template-name-mangling branch from 1862e69 to ab15240 Compare February 21, 2023 02:03
@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci please test macOS

@zoecarver zoecarver merged commit 75f53a9 into swiftlang:main Feb 22, 2023
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.

1 participant