Skip to content

[cxx-interop] Fix a regression making std::string unsafe #80305

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 1 commit into from
Mar 26, 2025

Conversation

Xazax-hun
Copy link
Contributor

@Xazax-hun Xazax-hun commented Mar 26, 2025

Currently, we only get warnings for using unsafe types in expressions but not in the function signature. The tests did not use the std::string object in the function body. As a result, we regressed and std::string was considered unsafe.

The reason is that the annotation only mode for calculating escapability of a type did not do what we intended. std::basic_string is conditionally escapable if the template argument is escapable. We considered 'char' to have unknown escapability in annotation only mode. The annotation only mode was introduced to avoid suddenly importing certain types as not escapable when they have pointer fields and break backward compatibility.

The solution is to make annotation only mode to still consider char and co as escapable types and only fall back to unknown when the inference otherwise would have deduced non-escapable (for unannotated types).

Currently, we only get warnings for using unsafe types in expressions
but not in the function signature. The tests did not use the std::string
object in the function body. As a result, we regressed and std::string
was considered unsafe.

The reason is that the annotation only mode for calculating escapability
of a type did not do what we intended. std::basic_string is
conditionally escapable if the template argument is escapable. We
considered 'char' to have unknown escapability in annotation only mode.
The annotation only mode was introduced to avoid suddenly importing
certain types as not escapable when they have pointer fields and break
backward compatibility.

The solution is to make annotation only mode to still consider char and
co as escapable types and only fall back to unknown when the inference
otherwise would have deduced non-escapable (for unannotated typed).
@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Mar 26, 2025
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun Xazax-hun enabled auto-merge March 26, 2025 15:38
@Xazax-hun Xazax-hun merged commit 0792933 into main Mar 26, 2025
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/string-unsafe branch March 26, 2025 20:16
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.

2 participants