[cxx-interop] Add a new mode that no longer renames unsafe functions - #91384
Open
Xazax-hun wants to merge 1 commit into
Open
[cxx-interop] Add a new mode that no longer renames unsafe functions#91384Xazax-hun wants to merge 1 commit into
Xazax-hun wants to merge 1 commit into
Conversation
With the introduction of @unsafe(always) we have a new tool to handle functions that are very hard to use correctly. This PR introduces an experimental language feature. When this feature is on we will no longer rename methods to be __methodUnsafe but import them as @unsafe(always). This PR does not change any of the heuristics for renaming/adding @unsafe(always) just yet. This PR will import the functions over both spellings and add an unavailable note to the renamed one to guide users to use the original name. There are a couple of caveats/corner cases: * The renamed declarations might still be referenced from the overlays. For this reason those declarations are not marked unavaliable/deprecated. * We did not clone the unsafe attributes for inherited functions. * Added some lookup and cloning logic to properly handle alternate declarations. * If a C++ function is already deprecated, the deprecation message from C++ wins. * Had to avoid some duplicate work for default arguments in alternate declarations.
Xazax-hun
requested review from
DougGregor,
beccadax,
egorzhdan,
hamishknight,
hborla,
hnrklssn,
ian-twilightcoder,
j-hui,
patrykstefanski,
slavapestov,
susmonteiro and
xedin
as code owners
August 11, 2026 14:31
Contributor
Author
|
@swift-ci please smoke test |
egorzhdan
approved these changes
Aug 11, 2026
| // RUN: %target-swift-emit-silgen %s -I %S/Inputs -cxx-interoperability-mode=default -enable-experimental-feature ImportUnsafeCxxMethodsAsAlwaysUnsafe | %FileCheck %s | ||
|
|
||
| // REQUIRES: swift_feature_ImportUnsafeCxxMethodsAsAlwaysUnsafe | ||
|
|
Contributor
There was a problem hiding this comment.
Minor: existing tests for default arguments are under test/Interop/Cxx/function, should we move this test there too for consistency?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the introduction of @unsafe(always) we have a new tool to handle functions that are very hard to use correctly. This PR introduces an experimental language feature. When this feature is on we will no longer rename methods to be __methodUnsafe but import them as @unsafe(always). This PR does not change any of the heuristics for renaming/adding @unsafe(always) just yet.
This PR will import the functions over both spellings and add an unavailable note to the renamed one to guide users to use the original name.
There are a couple of caveats/corner cases: