Skip to content

Conversation

@hnrklssn
Copy link
Member

This creates safe overloads for any methods in the protocol annotated with bounds information.
To support code sharing for both clang::FunctionDecl and clang::ObjCMethodDecl, swiftifyImpl is templated.
Updates _SwiftifyImportProtocol to make the added overloads in the protocol public.

rdar://144335990

...with bounds attributes

This creates safe overloads for any methods in the protocol annotated
with bounds information. Updates _SwiftifyImportProtocol to make the
added overloads in the protocol public.

rdar://144335990
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

This updates SwiftifyImportProtocolPrinter such that it no longer emits
anything for methods without bounds or lifetime info. Previously we
would not attach the macro if no methods in the protocol contained
bounds or lifetime info. However if one of the methods did, we would
still emit `.method(signature: "func foo()", paramInfo: [])` for the
methods without bounds of lifetime info. This would result in overloads
being generated, like so:
```
@_alwaysEmitIntoClient @_disfavoredOverload public
func foo() {
  return unsafe foo()
}
```

As part of this change, SwiftifyImportPrinter is now an abstract parent
type for SwiftifyImportProtocolPrinter, and the new
SwiftifyImportFunctionPrinter. Instead of SwiftifyImportProtocolPrinter
inheriting the function printing, `printMethod` instead creates a new
SwiftifyImportFunctionPrinter each time, with a new output string. If it
output anything interesting the result is forwarded, otherwise it is
discarded.
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test windows platform

1 similar comment
@hnrklssn
Copy link
Member Author

@swift-ci please smoke test windows platform

@hnrklssn
Copy link
Member Author

@swift-ci please smoke test

@hnrklssn
Copy link
Member Author

hnrklssn commented Nov 5, 2025

For a second I was questioning whether [Swiftify] make protocol extension methods public was the right way to do things.
After looking into it a bit, my understanding is that if you can name an objc method, you can call it, so their Swift equivalent should always be public IIUC. Not sure why they aren't explicitly public in the imported protocol, but Swift still seems to be able to call those methods, so maybe there's some compiler magic? @egorzhdan @DougGregor

@hnrklssn
Copy link
Member Author

hnrklssn commented Nov 7, 2025

ping @egorzhdan @j-hui @DougGregor

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