Skip to content
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

[Swiftify] Add return pointer support #78571

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hnrklssn
Copy link
Contributor

Instead of simply passing a parameter index to _SwiftifyInfo, the _SwiftifyExpr enum is introduced. It currently has two cases:

  • .param(index: Int), corresponding to the previous parameter index
  • .return, corresponding to the function's return value.

ClangImporter is also updated to pass this new information along to _SwiftifyImport, allowing overloads with buffer pointer return types to be generated. The swiftified return values may not yet map to Span types, because we don't currently track the lifetime information necessary to do so.

This also fixes a bug in the decision making for picking the swiftified type, where all pointers would map to [Mutable][Raw]Span when any pointer was marked nonescaping. This is incorrect both for the case where a nonescaping parameter is combined with an escaping parameter, as well as for return values, where being marked as nonescaping is not enough to soundly use Span-types.

Instead of simply passing a parameter index to _SwiftifyInfo, the
_SwiftifyExpr enum is introduced. It currently has two cases:
 - .param(index: Int), corresponding to the previous parameter index
 - .return, corresponding to the function's return value.

ClangImporter is also updated to pass this new information along to
_SwiftifyImport, allowing overloads with buffer pointer return types to
be generated. The swiftified return values currently return Span when
the return value is marked as nonescaping, despite this not being sound.
This is a bug that will be fixed in the next commit, as the issue is
greater than just for return values.
There was an assumption that all converted pointers were either
converted to Span-family pointers, or UnsafeBufferPointer-family
pointers. This was not consistently handled, resulting in violating the
`assert(nonescaping)` assert when the two were mixed. This patch removes
the Variant struct, and instead each swiftified pointer separately
tracks whether it should map to Span or UnsafeBufferPointer.
This also fixes return pointers being incorrectly mapped to Span when
marked as nonescaping.
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

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