-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Import nullability of templated function parameters correctly #82161
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
Conversation
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
I'm wondering what happens when a function returns a pointer type, whether it be nullable, non-null, or unannotated. That said, importing return types seem to be handled separately, so maybe that's beyond the scope of this patch.
@@ -2731,8 +2749,6 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList( | |||
} | |||
|
|||
bool knownNonNull = !nonNullArgs.empty() && nonNullArgs[index]; | |||
// Specialized templates need to match the args/result exactly. | |||
knownNonNull |= clangDecl->isFunctionTemplateSpecialization(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this removed, you might have fixed some of the crashes for the commented-out cases in template-instantiation-irgen.swift
, e.g.,
swift/test/Interop/Cxx/templates/template-instantiation-irgen.swift
Lines 58 to 59 in e79760b
// FIXME: this crashes because this round-trips to UnsafeMutablePointer<FRT?> | |
// func takesMutPtrToFRT(x: UnsafeMutablePointer<FRT>) { takesValue(x) } |
Could you see if those are fixed by your patch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah great point, thanks! Let me uncomment some of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(related: rdar://142850017)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, thanks!
111a028
to
16b1d5b
Compare
@swift-ci please smoke test |
0b7c2a9
to
74e0d79
Compare
74e0d79
to
496571b
Compare
@swift-ci please smoke test |
…rectly This teaches ClangImporter to respect the `_Nonnull`/`_Nullable` arguments on templated function parameters. Previously Swift would only import a non-annotated function overload. Using an overload that has either `_Nonnull` or `_Nullable` would result in a compiler error. The non-annotated overload would get imported with incorrect nullability: Swift would always assume non-null pointers, which was inconsistent with non-templated function parameters, which are mapped to implicitly unwrapped optionals. With this change all three possible overloads are imported, and all of them get the correct nullability in Swift. rdar://151939344
496571b
to
607dd4a
Compare
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
@swift-ci please smoke test Linux |
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
This teaches ClangImporter to respect the
_Nonnull
/_Nullable
arguments on templated function parameters.Previously Swift would only import a non-annotated function overload. Using an overload that has either
_Nonnull
or_Nullable
would result in a compiler error. The non-annotated overload would get imported with incorrect nullability: Swift would always assume non-null pointers, which was inconsistent with non-templated function parameters, which are mapped to implicitly unwrapped optionals.With this change all three possible overloads are imported, and all of them get the correct nullability in Swift.
rdar://151939344