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
[SR-5255] Make this initialization pattern efficient #47830
Comments
@swift-ci create |
This is "just" factory initializers. I'm pretty sure we don't implement it properly, either—I have no idea what it means to assign to |
According to @slavapestov we do implement it properly; you two can duke it out if you like. |
Whether or not we implement it properly, I don't think we should optimize it. There is a correct design for this feature and this isn't it. |
A library publishes a protocol that happens to do self-assignment. An application happens to make a class type conform to that protocol. They don't know about one another's internals. This will come up, and IMO it should not be needlessly inefficient. |
I agree with Dave. Whether or not we expose some additional sugar for this, the underlying architectural change, where non-@objc convenience initializers do not get an initializing entry point, is something we should do before ABI stability. It's not an optimization as much as a sensible refactoring. |
I forgot to point out that this isn't sound under our initializer inheritance rules.
|
Comment by Ky (JIRA) Whoops this wasn't resolved before ABI Stability |
We did do the refactoring-optimization Slava talked about, and we've banned this particular incantation to avoid the unsoundness. So I think we're down to factory inits. (The code's still not 100% efficient; for some reason it's not inlining the call to
|
THANKS! |
Additional Detail from JIRA
md5: 2ca3c2e2a8c54b11f6162787e7ac565b
relates to:
Issue Description:
This pattern works:
Unfortunately, it creates calls to
swift_deallocPartialClassInstance
as the already-allocatedBase
has to be thrown out so the appropriate derived class can be allocated. A peephole optimization could be used to eliminate this extra allocation/deallocation.The text was updated successfully, but these errors were encountered: