Sometimes crash when try to print description of a Swift Symbol
let symbol = try parseMangledSwiftSymbol("_$s7SwiftUI17_Rotation3DEffectV14animatableDataAA14AnimatablePairVySdAFy12CoreGraphics7CGFloatVAFyAiFyAiFyAFyA2IGAJGGGGGvpMV")
print(symbol.description) // Crash
This symbol comes from SwiftUICore. If I try to demangle it from terminal, it prints:
$ swift demangle s7SwiftUI17_Rotation3DEffectV14animatableDataAA14AnimatablePairVySdAFy12CoreGraphics7CGFloatVAFyAiFyAiFyAFyA2IGAJGGGGGvpMV
property descriptor for SwiftUI._Rotation3DEffect.animatableData : SwiftUI.AnimatablePair<Swift.Double, SwiftUI.AnimatablePair<CoreGraphics.CGFloat, SwiftUI.AnimatablePair<CoreGraphics.CGFloat, SwiftUI.AnimatablePair<CoreGraphics.CGFloat, SwiftUI.AnimatablePair<SwiftUI.AnimatablePair<CoreGraphics.CGFloat, CoreGraphics.CGFloat>, SwiftUI.AnimatablePair<CoreGraphics.CGFloat, CoreGraphics.CGFloat>>>>
I'm not able to reproduce this. An EXC_BAD_ACCESS is not something that's usually possible in Swift. It looks like something has corrupted the stack. Possibly stack overflow or some weird compiler issue. But I would expect a stack overflow to be reproducible.
Is this just something that's happened due to an unclean build or some specific build configuration?
@mattgallagher Sorry for the delay
I tried the code in main.swift, working as normal, but in my project, I may use it in async context.
The issue is reproducible when it switched to another thread.
Try this example:
Task.detached {
let symbol = try parseMangledSwiftSymbol("_$s7SwiftUI17_Rotation3DEffectV14animatableDataAA14AnimatablePairVySdAFy12CoreGraphics7CGFloatVAFyAiFyAiFyAFyA2IGAJGGGGGvpMV")
print(symbol.description) // Crash
}
RunLoop.main.run()
The workaround for this issue is to operate SwiftSymbol processing only on main thread
Task { @MainActor in
let symbol = try parseMangledSwiftSymbol("_$s7SwiftUI17_Rotation3DEffectV14animatableDataAA14AnimatablePairVySdAFy12CoreGraphics7CGFloatVAFyAiFyAiFyAFyA2IGAJGGGGGvpMV")
print(symbol.description) // Works
}
That's why you can't reproduce it, I think
Anyway, that's good, at least we found workaround and the reason that causes the issue
Thanks. I can reproduce the crash, now. I'll see if I can understand what's going on and fix it properly.
While this was easy to reproduce, it was a little annoying to work around (needed some tedious refactoring). However, it should now be fixed on master.