New "segmentation fault 11" in Swift 5.6

This code used to compile and function correctly (prior to Swift 5.6) but now with Swift 5.6 I get a "segmentation fault 11" error:

///
import SwiftUI

///
public protocol DisplayableValue {
    
}

///
public protocol SingleValueDisplay: View {
    
    ///
    associatedtype DisplayedValue
    
    ///
    init (_ singleValue: DisplayedValue)
    
    ///
    var displayedValue: DisplayedValue { get }
}

///
public protocol RawDisplayableValue: DisplayableValue {
    
    ///
    associatedtype RawDisplay: SingleValueDisplay
        where RawDisplay.DisplayedValue == Self
}

///
public protocol RawTextDisplayableValue: RawDisplayableValue
    where Self: CustomStringConvertible,
          RawDisplay == RawTextDisplay<Self> { }

///
public struct RawTextDisplay <Value: CustomStringConvertible>: SingleValueDisplay {
    
    ///
    public var displayedValue: Value
    
    ///
    public init (_ singleValue: Value) {
        self.displayedValue = singleValue
    }
    
    ///
    public var body: some View {
        Text(displayedValue.description)
    }
}

What's the proper way to file this as a bug?

Thanks for the bug report. This hits a known issue in 5.6. You can work around it by building with the "-Xfrontend -requirement-machine=off" compiler flag (in Xcode, this is the OTHER_SWIFT_FLAGS build setting).

On main this appears to hit a different problem, so I'll take a look.

4 Likes

Thanks Slava! Is this possible to do if this code lives in a Swift package?


I know I can do this in any apps which import the package, but it would be nice to be able to build the package on its own from Xcode.

Unfortunately any app that uses the RawTextDisplayableValue protocol will need the same flag.

The only other workaround I can suggest is to change the return type of 'var body' in RawTextDisplay from 'some View' to 'AnyView', but that might not be appropriate.

Awesome, I prefer the AnyView workaround because the code isn't that performance sensitive, nor will changing it back to some View whenever that becomes possible cause problems at any of the usage sites. Thanks a lot.

1 Like

Do you mind filing a bug with your test case on bugs.swift.org so I can track the fix for the second issue (which is not present on 5.6)?

2 Likes

No problem, here it is:

https://bugs.swift.org/browse/SR-16040

4 Likes

Thanks, I have a fix up for the issue on main: AST: TypeMatcher needs to recurse into OpaqueTypeArchetypeTypes by slavapestov · Pull Request #41958 · apple/swift · GitHub

3 Likes