-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-2338] Compiler Crash on Implementing Optional convenience init of CGMutablePath #44945
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
Comments
@milseman, @slavapestov, essentially the same case as the Dispatch ones, but also happens in Release? Though SILGen just goes off the rails here.
|
Yes, this seems related, and is a good reason to try to prioritize the fix for Swift 3.0, if we can fit it in. |
It's not a regression, so I'm fine with it landing later. |
(Most CF types don't have initializers at all. CG is special because of the import-as-member proposal.) |
So, previously if instead this code was:
It also wouldn't work? Then I agree. |
Yep, it's a class type, so you can't assign to |
I'll fix the SILGen crash, but is this supposed to work at all? It would be nice to be able to assign to self in class convenience initializers also, as long as the class is final. We can't subclass foreign classes, can we? |
Comment by Glenn Howes (JIRA) @slavapestov are you asking if the following is supposed to be valid code? Why shouldn't it be? extension CGMutablePath
{
public func addSVGPath(svgPath: String) -> Bool
{
return true
}
public convenience init?(svgPath: String)
{
self.init()
if !self.addSVGPath(svgPath: svgPath)
{
return nil
}
}
} |
Doing this for non-foreign classes (and allowing self-assignment) requires deciding what factory initializers mean in Swift. Just doing it for foreign classes (only with |
Actually @belkadan, this is similar to what the dispatch overlay does, so the fact that it crashes must be a bug. |
I opened: #4335 This fixes the SILGen assert (by fixing how we import the init). There may be other bugs deeper down, though. I'll investigate further. |
While that PR will fix the provided code, actually trying to use it triggers an IRGen assert: Assertion failed: (!theClass->isForeign()), function emitObjCHeapMetadataRef, file ...swift/lib/IRGen/GenMeta.cpp, line 339. When trying to IRGen this: So, there's more layers here. I'll see how this differs from Dispatch |
This is the "we need to not even try to allocate foreign classes" bit. I think Slava worked around this for Dispatch by special-casing RuntimeOnly foreign classes, whose metadata you can get by run-time lookup, but I don't think that's the correct answer even there. |
So CGMutablePath does not have Objective-C metadata at all? Interesting... |
CF types do not have public class symbols, no. |
(or guaranteed runtime names) |
We could emit a fake allocation of some kind. The only thing that's done to it is alloc, dealloc, and possibly retain and release. |
There's no reason to do any allocation at all. We have a mechanism for this already: factory initializers. |
Right, I agree we should do it properly if possible. Do you think it would be hard to teach SILGen to emit user-defined convenience inits as factory inits, in the case where they delegate to another factory init? Does this create any issues for PrintAsObjC and such? |
This will not be supported in Swift 3, because we don't have the concept of user factory inits. This will emit an error in Swift-3, and hopefully we'll get support soon after. #4419 |
Slava's approach is what I was thinking, except I was going to make it based on whether the type was an AST-foreign type rather than whether the thing it delegated to was a factory init. (Normal convenience initializers are still inherited, while factory inits are not.) |
This properly emits error: convenience initializers are not supported in extensions of CF types |
Environment
OSX 10.11.6 (15G31), Xcode tools 8.0 (8S193k), Apple Swift version 3.0 (swiftlang-800.0.42.1 clang-800.0.36.1)
Additional Detail from JIRA
md5: f6596743c7cce37ddcb47a3028c32f0c
relates to:
Issue Description:
From the command line, enter the following:
This also crashes the compiler in the current Xcode 8 beta (8.0 beta 5 (8S193k)), but I thought it would be simpler to provide the command line equivalent.
The text was updated successfully, but these errors were encountered: