-
Notifications
You must be signed in to change notification settings - Fork 488
CompilerPlugin.resolveMacro robust solution for getting module and typename #3258
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
base: main
Are you sure you want to change the base?
CompilerPlugin.resolveMacro robust solution for getting module and typename #3258
Conversation
|
Can you define "far more efficient"? Have you measured the performance difference? Do you have any metrics to share? |
@grynspan Hi Jonathan! Shortly, While profiling our app using But internally, So using |
|
It sounds like the correct fix may be to short-circuit metatype checks, as they cannot conform to Swift protocols, rather than advising teams (within the Swift project and outside it) to adopt unstable and unsupported functions. 🙂 @mikeash is that something that could be optimized? |
The only possible solution I can come up with is introducing new overloads for |
|
The standard library could check if |
This will cause code duplication between print_unlocked and adHoc_print_unlocked function? Or I didn't quite get your perspective on that |
|
The point is that this problem can be resolved inside the Swift stdlib and/or runtime rather than needing to be applied ad hoc to a variety of projects. A fix in Swift itself would benefit all these projects simultaneously. It might even benefit you in other ways if a fix can be implemented inside the runtime because it could apply to all conformance checks, not just those around stringification. The exact details of the fix aren't really the salient point. I don't anticipate a significant increase in code size in Swift here regardless of how the fix is implemented. |
I don't quite get why this function is unstable or unsupported? It is public and moreover it is inlined into client code inside DefaultStringInterpolation by In my opinion, this is more appropriate function to use. As for me _typeName function seems for semantically correct that String(describing:) |
|
Symbols in the Swift standard library whose names start with underscores are, de jure unstable and unsupported. That's why their names start with underscores. |
Description
This PR fixes FIXME for getting type and module name.
String(reflecting: type)eventually calls_typeName(_:qualified: true).Motivation
_typeName(_:qualified: true)is far more efficient. And also is more robust and suitable to retrieve module and type name.Verification
CompilerPluginTests passed locally.
Same optimization/replacement was made here: swiftlang/swift#77369.
Checklist