-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-7064] 4.1 Regression: Runtime crash when compiler optimises code from RxSwift library #49612
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
fixed in #14829 |
Comment by Worth Baker (JIRA) @eeckstein we're still seeing this regression (or a very similar issue) in the release versions of Xcode 9.3 / Swift 4.1. Note the following code snippet - tapping the button in the viewController is a 100% crasher when run with Swift release optimizations ( [-O] ) turned on: import UIKit
import RxSwift
class ViewController: UIViewController {
private let disposeBag = DisposeBag()
private let publishSubject = PublishSubject<Void>()
private let buttonPublishSubject = PublishSubject<Void>()
override func viewDidLoad() {
super.viewDidLoad()
// Add button
let button = UIButton(type: .system)
button.frame = view.bounds
button.setTitle("I'll crash your app.", for: .normal)
button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
view.addSubview(button)
// Setup observables
buttonPublishSubject
.subscribe(onNext: publishSubject.onNext) // ___CRASH___
// .bind(to: publishSubject) // using `bind` avoids the crasher
// .subscribe(onNext: { self.publishSubject.onNext($0) }) // also does not crash
.disposed(by: disposeBag)
publishSubject
.observeOn(MainScheduler.instance)
.subscribe(onNext: {
print("button tapped")
})
.disposed(by: disposeBag)
}
@objc
func buttonTapped(_ sender: Any) {
self.buttonPublishSubject.onNext(())
}
} And here's the stack trace: * thread #​1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xc00000023a806ee8)
frame #​0: 0x00000001047b240c RxSwift`PublishSubject.on(event=<unavailable>, self=0xc00000023a806ee8) at PublishSubject.swift:0 [opt]
frame #​1: 0x00000001047b3630 RxSwift`protocol witness for ObserverType.on(_:) in conformance PublishSubject<A> at PublishSubject.swift:0 [opt]
* frame #​2: 0x00000001047abcd8 RxSwift`ObserverType.onNext(element=() @ 0x000000016bc2d1c0, self=0xc00000023a806ee8) at ObserverType.swift:27 [opt]
frame #​3: 0x00000001041d5c94 RxSwict_9.3_CrashTests`partial apply for ObserverType.onNext(_:) at ViewController.swift:0 [opt]
frame #​4: 0x00000001047a89d4 RxSwift`closure #​2 in ObservableType.subscribe(event=, onNext=0x00000001041d5bf8 RxSwict_9.3_CrashTests`partial apply forwarder for (extension in RxSwift):RxSwift.ObserverType.onNext(A.E) -> () at ViewController.swift, onError=nil, disposable=<unavailable>, onCompleted=nil) at ObservableType+Extensions.swift:93 [opt]
frame #​5: 0x00000001047a8c58 RxSwift`partial apply for closure #​2 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) at ObservableType+Extensions.swift:0 [opt]
frame #​6: 0x0000000104757e20 RxSwift`AnonymousObserver.onCore(event=<unavailable>, self=<unavailable>) at AnonymousObserver.swift:24 [opt]
frame #​7: 0x00000001047ab7fc RxSwift`ObserverBase.on(event=, self=0x00000001d405c9e0) at ObserverBase.swift:0 [opt]
frame #​8: 0x00000001047aba58 RxSwift`protocol witness for ObserverType.on(_:) in conformance ObserverBase<A> at ObserverBase.swift:0 [opt]
frame #​9: 0x00000001047abed0 RxSwift`partial apply at ObserverType.swift:0 [opt]
frame #​10: 0x00000001047c8690 RxSwift`thunk for @escaping @callee_guaranteed (@in Event<A>) -> () at ShareReplayScope.swift:0 [opt]
frame #​11: 0x00000001047b2564 RxSwift`PublishSubject.on(_:) [inlined] reabstraction thunk helper <A> from @escaping @callee_guaranteed (@in RxSwift.Event<A>) -> (@out ()) to @escaping @callee_guaranteed (@in RxSwift.Event<A>) -> () at PublishSubject.swift:0 [opt]
frame #​12: 0x00000001047b255c RxSwift`PublishSubject.on(_:) [inlined] RxSwift.dispatch<A>(RxSwift.Bag<(RxSwift.Event<A>) -> ()>, RxSwift.Event<A>) -> () at Bag+Rx.swift:15 [opt]
frame #​13: 0x00000001047b2548 RxSwift`PublishSubject.on(event=, self=<unavailable>) at PublishSubject.swift:64 [opt]
frame #​14: 0x00000001047b3630 RxSwift`protocol witness for ObserverType.on(_:) in conformance PublishSubject<A> at PublishSubject.swift:0 [opt]
frame #​15: 0x00000001047abcd8 RxSwift`ObserverType.onNext(element=() @ 0x000000010482a9c8, self=0x00000001d40d75a0) at ObserverType.swift:27 [opt]
frame #​16: 0x00000001041d4f00 RxSwict_9.3_CrashTests`@objc ViewController.buttonTapped(_:) [inlined] RxSwict_9_3_CrashTests.ViewController.buttonTapped(sender=Any @ 0x000000016bc2d530, self=0x000000010552c000) -> () at ViewController.swift:48 [opt]
frame #​17: 0x00000001041d4e88 RxSwict_9.3_CrashTests`@objc ViewController.buttonTapped(_:) at ViewController.swift:47 [opt]
frame #​18: 0x000000018c1e1608 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 96
frame #​19: 0x000000018c1e1588 UIKit`-[UIControl sendAction:to:forEvent:] + 80
frame #​20: 0x000000018c1cc2f0 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 440
frame #​21: 0x000000018c1e0e7c UIKit`-[UIControl touchesEnded:withEvent:] + 576
frame #​22: 0x000000018c1e099c UIKit`-[UIWindow _sendTouchesForEvent:] + 2544
frame #​23: 0x000000018c1dbe6c UIKit`-[UIWindow sendEvent:] + 3208
frame #​24: 0x000000018c1ad378 UIKit`-[UIApplication sendEvent:] + 340
frame #​25: 0x000000018cafa85c UIKit`__dispatchPreprocessedEventFromEventQueue + 2364
frame #​26: 0x000000018cafcde8 UIKit`__handleEventQueueInternal + 4760
frame #​27: 0x000000018cafd150 UIKit`__handleEventQueueInternal + 5632
frame #​28: 0x000000018caf5d04 UIKit`__handleHIDEventFetcherDrain + 152
frame #​29: 0x0000000182d1e2e8 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
frame #​30: 0x0000000182d1e268 CoreFoundation`__CFRunLoopDoSource0 + 88
frame #​31: 0x0000000182d1daf0 CoreFoundation`__CFRunLoopDoSources0 + 204
frame #​32: 0x0000000182d1b6c8 CoreFoundation`__CFRunLoopRun + 1048
frame #​33: 0x0000000182c3bfb8 CoreFoundation`CFRunLoopRunSpecific + 436
frame #​34: 0x0000000184ad3f84 GraphicsServices`GSEventRunModal + 100
frame #​35: 0x000000018c2102e8 UIKit`UIApplicationMain + 208
frame #​36: 0x00000001041d5398 RxSwict_9.3_CrashTests`main at AppDelegate.swift:12 [opt]
frame #​37: 0x000000018275e56c libdyld.dylib`start + 4 We've confirmed that the crash does not occur when built with Xcode 9.2, nor when compiler optimizations are set to Debug ([-Onone]). Please advise if more information is needed or if a separate ticket should be opened. Thanks! |
Comment by Worth Baker (JIRA) @eeckstein created a workspace that includes RxSwift and can reproduce the crash - decompress the ZIP, open the Xcode workspace, and build/run the "Crashing Scheme (Release)" scheme *on an iOS device (the crash will not occur in the iOS simulator). Thanks! RxSwift_Crash-Swift_4_1.zip |
worthbak (JIRA User) Thanks for reporting! We'll take a look |
Reproduced. This is most likely a different issue than the original one. Still investigating... |
Fixed on master with #15829 |
Comment by Worth Baker (JIRA) Nice - thanks @eeckstein! |
Comment by Romain (JIRA) Hello @eeckstein, sorry to bother you. Just reporting that this behaviour seems to still be reproductible with Xcode 9.3.1 - Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1). Well, I reproduced it with the RxSwift_Crash-Swift_4_1 archive linked above, if someone else can confirm this. Thank you very much! |
Thanks for reporting! |
Comment by Romain (JIRA) All right thank you very much! |
Attachment: Download
Environment
Apple Swift version 4.1 (swiftlang-902.0.41 clang-902.0.31) – Xcode 9.3b3
Additional Detail from JIRA
md5: d21e98eb0eac7f79557312a51c8fdd25
is duplicated by:
Issue Description:
I've noticed a runtime crash when running fairly typical code with the popular RxSwift library.
It only occurs on optimised (Release) builds and therefore appears to be an issue with the Swift compiler's optimisation process.
I've included a small project which demonstrates the issue. From what I can tell it looks as though the optimiser may be stripping away a getter somewhere in shouldn't be.
Steps to reproduce:
Open the 'BugWorkspace.xcworkspace' in Xcode 9.3b3
Ensure the 'BugApp-Optimised' scheme is selected
Run in the simulator (or device)
Tap anywhere on the screen
Crash
Backtrace:
View Controller to reproduce issue:
The text was updated successfully, but these errors were encountered: