-
Notifications
You must be signed in to change notification settings - Fork 269
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
(Fixed in Swift 1.2) Some methods (eg initWithNibName:bundle) vtabled in release mode #286
Comments
@jasperblues Interesting... Appears to be an optimization issue (which is why it would happen on release and not debug). While debugging I noticed the useInitializer closure for the addCityViewController (which is the starting point of the issue) was actually calling the useInitializer closure from the cityDao! Weird! So I figured that maybe some funky stuff was going on with the addresses of these closures. As a test, I moved the addCityViewController useInitializer controller to a local variable:
Looking at the address space in the debugger (breakpoint at
Notice how the block variable does not have a location. After stepping into the
Now the parametersBlock has an address space. This should be the same as the A workaround, although something that should NOT be used as an end all be all solution would be to turn off compiler optimization. Set the release optimization level to -Onone. EDIT trimmed out debugger console output to highlight, what I believe to be, the problem. |
@mowens Thanks for the analysis. I just tried the following: dynamic override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
} . . override the failing init with a dynamic one that calls super. It did not work :( |
Workaround: It seems Swift has uncovered an issue with checkParametersCount. I commented this out and everything works ok. As a short-term patch, I'll wrap this in an #if DEBUG Edit: Actually we'll leave those checks as debug only too. They don't add much besides CPU cycles in release mode. |
Fixed in 2.3.2 Since the main issue is resolved, we'll close this now. Will still investigate why the argument checker doesn't like Swift in release mode though. @jdbunford Sorry this took a while. |
@jasperblues I'm not entirely sure it is a problem with Breakpoint 1: Right before stepping into Breakpoint 2: Right before stepping into Breakpoint 3: What the? Next execution is in the Breakpoint 4: Stepping over the I think there is a deeper underlying issues with the Swift optimization here. If we skip the |
@mowens You're right. After reading your first analysis I incorrectly assumed that the sample app would either crash spectacularly or work. It appeared to work. So I imagined:
. . . seems a bit crazy in retrospect. Of course it still crashes, but just for the controller that uses the optimized |
@mowens It might be worth raising a Radr issue for this? |
@jasperblues created #19337398 under Apple Bug Reporter. I will update once more information is available |
Thanks @mowens ! Sent from my iPhone
|
From Apple bug report:
Sounds promising! I'll try and find some time to verify this on the latest beta build |
@mowens That's great news! Thanks so much for taking care of this. Hey would you like to be featured on the Typhoon website as a contributor? We add a picture and short-bio of folks who've made significant contributions. |
@jasperblues Sad news. I still received a crash on the release configuration. I wasn't able to debug too much into it last night but I will look into it in more detail shortly. Seems like there are some issues resolving symbols of release builds in Xcode Beta which was making it more difficult to determine if the crash point is the same as before or not. Anyways, I'll keep you posted. As for being listed on the Typhoon website as a contributor, that sounds great :) I'd love to be featured. Thanks man! |
@mowens Damn, that's too bad. Hope its resolved soon. At least encouraging that its being given attention. Can you send us a pic and brief bio? |
@jasperblues GREAT NEWS! Swift 1.2 has fixed the release mode optimizations 👍 I finally had time to really look into the Swift 1.2 code in regards to the Typhoon-Swift project. Turns out the original crash in release mode for 1.2 was cased by some bad Swift code due to the 1.2 upgrade. I have created a branch with the updated code that now works great under 1.2 :) https://github.com/appsquickly/Typhoon-Swift-Example/tree/feature/swift-1.2 For parties that are interested there are 2 commits on this branch. The first commit just updates the Pod dependencies. The second commit contains the Swift 1.2 code changes. I am going to keep this as a feature branch until 1.2 is out of beta. |
@mowens AWESOME! Thanks so much for taking care of this. Swift + 💉💉💉💉💉💉 = 🎉 🎉 🎉 🎉 🎉 🎉 |
@jasperblues No problem 👍 I also sent you an email with my pic and bio from mike.owens11@gmail.com |
I've run into a problem that I assume is linked to this and also only occurs in releases. Basically the wrong values are being injected and coming from absolutely random (but consistent) locations. For example, an inline string value was being replaced with a value from a TyphoonConfig instance. Thanks for posting the workaround, looks like my releases are working now! You wouldn't believe how long I spent looking through Typhoon and my code trying to figure out where it was going weird. 👍 |
@dereekb could you post your code that is causing the issue? |
There is nothing particularly special about it, and the project is bigger than I'd like to post. The injection that messed up wasn't anything in particular: public class VISAppContextAssembly : TyphoonAssembly {
public dynamic func appContext() -> AnyObject {
return TyphoonDefinition.withClass(VISAppContext.self) { ... }
}
public dynamic func destinationKeyAccessor() -> AnyObject {
return TyphoonDefinition.withFactory(self.appContext(), selector: "makeKeyAccessorWithType:", parameters: { $0.injectParameterWith("destination") })
}
} public class VISAppContext : NSObject {
...
@objc(makeKeyAccessorWithType:)
public dynamic func makeKeyAccessor(keyType:String!) -> VISAppContextKeyAccessor {
NSLog("Making accessor with type \(keyType)")
return VISAppContextKeyAccessor(appContext:self, keyType:keyType)
}
} I restructured this Typhoon definition multiple times, and the injected value was first consistently a string that was defined in a config, and then a CGRect that was defined inline in another injection for UIWindow, so I am pretty certain it was just Swift optimization bugs. I'll try and reproduce it in another smaller app and post that here if you'd like to see it. I also have a lot of debug outputs that show the values being injected because I was going to bring up the issue here. This was the only definition that messed up in the whole project though, and messed up in a separate assembly and this assembly, which was why I thought it might have been Typhoon related at first. |
I've been leaving this open for folks using Swift prior to version 1.2. I think we can close it soon. |
Hi
Steps to reproduce:
Here is a copy of the exception being raised on startup.
2014-12-01 11:29:38.369 PocketForecast[38575:636356] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Method 'initWithNibName:bundle:' has 2 parameters, but 1 was injected. Inject with 'nil' if necessary'
The wrong parameters seem to be being injected into the initialiser...
Could this be a SWIFT closure problem? Strange it only happens in RELEASE builds.
FYI I am also seeing the same problem with my own SWIFT application using Typhoon both 2.3.0 & 2.3.1
The text was updated successfully, but these errors were encountered: