rules_swift
rules_swift copied to clipboard
Crash in release build using new Swift 5.7 features.
Here are sample app which crashes only in release build using Bazel (-c opt). Everything works fine in debug build.
In optimised build it crashes with EXC_BAD_ACCESS or dyld: missing symbol called.
Actually I though it is Xcode beta issue, so I've tried to reproduce this issue in Xcode build with different combinations of optimisations -O/-Osize and compilation mode singlefile/wholemodule. But it is working fine in Xcode build in all cases.
App crashes when accessing parametrised protocol variable in another protocol (any Protocol<Value>). It only happens in iOS 15 and lower. It works fine in all cases in iOS 16.
import SwiftUI
protocol SomeProto: AnyObject {
var proto: any SomeGenericProto<Int> { get set }
func getElements() -> [Int]
}
class SomeImpl: SomeProto {
var proto: any SomeGenericProto<Int> = SomeGenericImpl(elements: [1,2,3])
func getElements() -> [Int] {
proto.getElements()
}
}
protocol SomeGenericProto<Element> {
associatedtype Element
func getElements() -> [Element]
}
final class SomeGenericImpl<Element>: SomeGenericProto {
private let elements: [Element]
init(elements: [Element]) {
self.elements = elements
}
func getElements() -> [Element] {
elements
}
}
struct ContentView: View {
var someValue: any SomeProto = SomeImpl()
var body: some View {
VStack {
Text("Hello, world!" + "\(someValue.getElements().last ?? 0)")
}
.padding()
}
}
I don't see an issue running your sample project on a 15.5 simulator, can you be more specific on how to repro? I'm testing with Xcode 14 beta 5
Here is what I'm doing.
- Do
bazel build //ios-app:ios-app -c opt - Go to
bazel-out/applebin_ios-ios_sim_arm64-opt.../bin/ios-app/ios-app_archive-root/Payload/ - Do
xcrun simctl install booted ios-app.appor just drag and drop file to simulator app Resulting installed app crashes on start
I copied your code into a fresh Xcode project and also made it crash:
If you can verify this also crashes, then it sounds like we should submit a bug report upstream.
Yes you are right. It is crashing. I somehow missed it out. But for me its crashing only with optimisation level -Osize and working fine with -O in Xcode. Anyway need to report this one further.
However build with Bazel it seems crashes in all cases except debug. Why it is crashing without --features=swift.opt_uses_osize set?
Yea I thought that was interesting too, I didn't debug further. You can try to reduce the other various flags that bazel is passing to sidestep it. I was thinking at some point it had something to do with -dead_strip, which is passed with -c opt, but I was able to repro with -c dbg --swiftcopt=-O as well.