Bug report: [SR-15983] Xcode 13.3 (Swift 5.6) causes error: Segmentation fault: 11 build error - Swift
Overview
New Xcode 13.3 (Swift 5.6) causes error: Segmentation fault: 11 error when building SwiftUI-Gallery iOS app project.
- https://github.com/inamiy/Actomaton-Gallery/tree/main/Examples/SwiftUI-Gallery
 
As of 22fb93f, there was no such build error in Xcode 13.2 (Swift 5.5), but started to occur from Xcode 13.3.
Steps to reproduce
Bug-reproducing branch: https://github.com/inamiy/Actomaton-Gallery/tree/bug/Xcode13.3-segfault
- 22fb93f Segfault when building Xcode 13.3 (no error in Xcode 13.2)
 
- 8145848 Commented-out 
Physics module, and Xcode 13.3 build succeeds 
- 8924c6f Re-enable part of 
Physics module, and Xcode 13.3 build succeeds 
- 6231b40 Re-enable more part of 
Physics module, and Xcode 13.3 build fails due to segfault
- Fails for both Xcode IDE build and 
xcodebuild (see also make build-SwiftUI-Gallery) 
 
So the problematic code seems to live in 6231b40 but no other clues so far.
(One possible issue might be protocol extension with  associated type constraint i.e. where Obj == CircleObject ?)
// NOTE: ObjectWorldExample is a protocol with `Obj` as associatedtype 
extension ObjectWorldExample where Obj == CircleObject
{
    /// Default impl.
    func draggingEmptyArea(_ objects: inout [Obj], point: CGPoint) {}
    /// Default impl.
    func dragEndEmptyArea(_ objects: inout [Obj]) {}
    /// Default impl.
    func exampleTapToMakeObject(point: CGPoint) -> Obj?
    {
        CircleObject(position: Vector2(point))
    }
    var reducer: Reducer<World.Action, World.State<Obj>, World.Environment>
    {
        World
            .reducer(
                tick: World.tickForObjects(self.step),
                tap: { objects, point in
                    if let object = exampleTapToMakeObject(point: point) {
                        objects.append(object)
                    }
                },
                draggingObj: { $0.position = Vector2($1) },
                draggingEmptyArea: self.draggingEmptyArea,
                dragEndEmptyArea: self.dragEndEmptyArea
            )
    }
}
2022/03/16 0:07 Update
43b0a84 could fortunately fix this Swift 5.6 bug by loosing associatedtype constraint from where Obj == CircleObject to where Obj: Equatable with as? Obj downcasting.
Bug fixing diff: https://github.com/inamiy/Actomaton-Gallery/compare/22fb93f...865c73d
@@ -90,7 +90,7 @@ protocol ObjectWorldExample: Example
     func exampleTapToMakeObject(point: CGPoint) -> Obj?
 }
 
-extension ObjectWorldExample where Obj == CircleObject
+extension ObjectWorldExample where Obj: Equatable // where Obj == CircleObject
 {
     /// Default impl.
     func draggingEmptyArea(_ objects: inout [Obj], point: CGPoint) {}
@@ -101,7 +101,7 @@ extension ObjectWorldExample where Obj == CircleObject
     /// Default impl.
     func exampleTapToMakeObject(point: CGPoint) -> Obj?
     {
-        CircleObject(position: Vector2(point))
+        CircleObject(position: Vector2(point)) as? Obj
     }
 
     var reducer: Reducer<World.Action, World.State<Obj>, World.Environment>
While this workaround can cope the compiler bug from developer-side, the code will now become ugly (which I don't want to merge this PR), so I believe this bug needs to be fixed by Swift compiler team.
		                                  
		                                    bug