Skip to content
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

[SR-8814] GenericSignatureBuilder should re-introduce conformance requirements when adding a superclass requirement #51322

Closed
swift-ci opened this issue Sep 21, 2018 · 10 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 21, 2018

Previous ID SR-8814
Radar rdar://problem/44736411
Original Reporter Augard (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode (10A255), macOS 10.13.6 (17G2307)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: 3ceba1c7e1776ae34423d56b0b58a883

is duplicated by:

  • SR-10128 Compiler crashes when generic type constraint is the associated type of another protocol which the class also conforms to which and has a default implementation
  • SR-10182 Segmentation Fault after updating to Xcode 10.2
  • SR-10462 LLDB Segmentation fault
  • SR-10741 Compiler crashes with protocols and generics + default extension (Assertion failed: (!isInvalid())
  • SR-10773 Regression: Segmentation fault: 11 compiling code in swift 5.0.1
  • SR-11108 Conformance checking doesn't consider 'where' clause for vars
  • SR-11913 Protocol requirements implemented solely in an extension crash the compiler
  • SR-12238 Segmentation Fault: 11 when conforming to protocol using a same generic and associated type names and a protocol extension.
  • SR-12352 Segmentation Fault With Generic Protocol Extensions
  • SR-12416 SILGen crash conforming class to Sequence
  • SR-12542 Compiler crash generating protocol witness
  • SR-12607 5.2 Crasher
  • SR-12624 Segmentation Fault 11

relates to:

  • SR-10656 Compiler crashes when using protocols with associated type

Issue Description:

Our app is failing to archive in new Xcode 10 and Swift 4. (-0)

CompileSwift normal arm64 (in target: Equa bank)CompileSwift normal arm64 (in target: Equa bank)    
cd /Users/lukas/Projects/Equa\ Bank/mequa-ios    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c 
-filelist /var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/sources-e3a4a7 -supplementary-output-file-map 
/var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/supplementaryOutputs-46e152 -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk -I /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/AFDateHelper -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/Cluster -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/DeallocationChecker -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/DeviceKit -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/DynamicBlurView -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/FSCalendar -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/Realm -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/RealmSwift -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/SZTextView -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/SkyFloatingLabelTextField -F /Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Crashlytics/iOS -F /Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Fabric/iOS -g -module-cache-path /Users/lukas/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 4 -O -D COCOAPODS -serialize-debugging-options -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/Equa\ Prod-generated-files.hmap -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/Equa\ Prod-own-target-headers.hmap -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/Equa\ Prod-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/Equa\ Prod-project-headers.hmap -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release\ Production-iphoneos/include -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Headers/Public -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Headers/Public/Crashlytics -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Headers/Public/Fabric -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Headers/Public/GoogleMaps -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/FSCalendar/FSCalendar -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Headers/Public -Xcc -I/Users/lukas/Projects/Equa\ Bank/mequa-ios/Pods/Headers/Public/PowerAuth2 -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/DerivedSources/arm64 -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa\ bank.build/Release\ Production-iphoneos/Equa\ bank.build/DerivedSources -Xcc -DCOCOAPODS=1 -Xcc -working-directory/Users/lukas/Projects/Equa\ Bank/mequa-ios -import-objc-header /Users/lukas/Projects/Equa\ Bank/mequa-ios/Equabank/SupportingFiles/Objc-Bridge-Header.h -pch-output-dir /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/PrecompiledHeaders -module-name Equa_Prod -num-threads 12 -output-filelist /var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/outputs-7f0dd5
0  swift                    0x0000000103dff64a PrintStackTraceSignalHandler(void*) + 421  swift                    0x0000000103dfedfe SignalHandler(int) + 3022  libsystem_platform.dylib 0x00007fff55092f5a _sigtramp + 263  libsystem_platform.dylib 0x00007ffeefbf79b0 _sigtramp + 25956378724  swift                    0x0000000100f77eb3 (anonymous namespace)::SILTypeSubstituter::substSILFunctionType(swift::CanTypeWrapper<swift::SILFunctionType>) + 3875  swift                    0x0000000100bb6417 swift::tryDevirtualizeApply(swift::ApplySite, swift::ClassHierarchyAnalysis*, swift::OptRemark::Emitter*) + 35756  swift                    0x0000000100d49623 (anonymous namespace)::Devirtualizer::run() + 7397  swift                    0x0000000100c700c9 swift::SILPassManager::execute() + 39778  swift                    0x0000000100092d32 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 477309  swift                    0x0000000100083dc5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 771710 swift                    0x0000000100029a35 main + 134911 libdyld.dylib            0x00007fff54d84015 start + 112 libdyld.dylib            0x0000000000000067 start + 2871509075Stack dump:0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -filelist /var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/sources-e3a4a7 -supplementary-output-file-map /var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/supplementaryOutputs-46e152 -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk -I /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/AFDateHelper -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/Cluster -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/DeallocationChecker -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/DeviceKit -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/DynamicBlurView -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/FSCalendar -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/Realm -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/RealmSwift -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/SZTextView -F /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/SkyFloatingLabelTextField -F /Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Crashlytics/iOS -F /Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Fabric/iOS -g -module-cache-path /Users/lukas/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 4 -O -D COCOAPODS -serialize-debugging-options -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/Equa Prod-generated-files.hmap -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/Equa Prod-own-target-headers.hmap -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/Equa Prod-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/Equa Prod-project-headers.hmap -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/BuildProductsPath/Release Production-iphoneos/include -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Headers/Public -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Headers/Public/Crashlytics -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Headers/Public/Fabric -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Headers/Public/GoogleMaps -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/FSCalendar/FSCalendar -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Headers/Public -Xcc -I/Users/lukas/Projects/Equa Bank/mequa-ios/Pods/Headers/Public/PowerAuth2 -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/DerivedSources/arm64 -Xcc -I/Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/IntermediateBuildFilesPath/Equa bank.build/Release Production-iphoneos/Equa bank.build/DerivedSources -Xcc -DCOCOAPODS=1 -Xcc -working-directory/Users/lukas/Projects/Equa Bank/mequa-ios -import-objc-header /Users/lukas/Projects/Equa Bank/mequa-ios/Equabank/SupportingFiles/Objc-Bridge-Header.h -pch-output-dir /Users/lukas/Library/Developer/Xcode/DerivedData/Equa_bank-copjuamabgqmrhdvprfmhnlvobyc/Build/Intermediates.noindex/ArchiveIntermediates/Production/PrecompiledHeaders -module-name Equa_Prod -num-threads 12 -output-filelist /var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/outputs-7f0dd5 1. Contents of /var/folders/bw/s7y418kn7fz67tzkzst5_2jh0000gn/T/sources-e3a4a7:
---
/Users/lukas/Projects/Equa Bank/mequa-ios/Equabank/Features/Near You/Views/EBMapView.swift
...
---
2. While running pass #&#8203;720577 SILFunctionTransform "Devirtualizer" on SILFunction "@$S9Equa_Prod17BaseFormViewModelPAAE25indexPathForFirstInputRow10Foundation05IndexH0VSgvgAA25NewStandingOrderPaymentVMC_Tg5". for getter for indexPathForFirstInputRow at /Users/lukas/Projects/Equa Bank/mequa-ios/Equabank/Shared/Base Controllers/BaseFormVM.swift:87:9error: Segmentation fault: 11
@belkadan
Copy link
Contributor

belkadan commented Sep 21, 2018

Can you share the project? If not publicly here, possibly just with Apple via https://bugreport.apple.com?

@eeckstein, does this look familiar?

@eeckstein
Copy link
Member

eeckstein commented Sep 21, 2018

No.
This could also be a bug in SILGen or any other optimization pass prior to devirtualization.
A (reduced) test case would be great.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Sep 24, 2018

Comment by Lukas Foldyna (JIRA)

import UIKit

protocol TableRowID {
 init?(rawValue: Int)
 var rawValue: Int { get }
 var order: Int { get }
}


extension TableRowID {
 var order: Int {
     return rawValue
 }
}




protocol TableRow {
 static var identifiers: [String] { get }
 var identifier: String { get }
 var height: CGFloat { get }
 var estimatedHeight: CGFloat { get }
}


extension TableRow {
 var identifier: String {
     return Self.identifiers.first ?? ""
 }
 
 var estimatedHeight: CGFloat {
     return height
 }
}


protocol InputViewCell {
 var id: TableRowID { get }
 var inputResponder: UIResponder? { get }
 
 func setup(row: TableRow, id: TableRowID, delegate: Any)
}






protocol TableSectioning: MutableCollection {
 associatedtype ID: TableRowID & Hashable
 
 var rows: [ID: TableRow] { get }
 func row(at index: Int) -> TableRow?
}


struct TableSection<ID>: TableSectioning where ID: TableRowID & Hashable {
 typealias DictionaryType = [ID: TableRow]
 
 internal(set) var rows: DictionaryType
 internal var orderIndex: [Int: ID] = [:]
 
 init(rows: DictionaryType = [:]) {
     self.rows = rows
     
     rows.keys.forEach { orderIndex[$0.order] = $0 }
 }
 
 func row(at index: Int) -> TableRow? {
     guard let id = orderIndex[index] else { return nil }
     return rows[id]
 }
 
 // MARK: - Collection
 typealias Index = DictionaryType.Index
 typealias Element = DictionaryType.Element
 
 var startIndex: Index { return rows.startIndex }
 var endIndex: Index { return rows.endIndex }
 
 subscript(index: Index) -> DictionaryType.Iterator.Element {
     get {
         return rows[index]
     }
     set {
         rows[newValue.key] = newValue.value
         orderIndex[newValue.key.order] = newValue.key
     }
 }
 
 public subscript(key: DictionaryType.Key) -> DictionaryType.Value? {
     get {
         return rows[key]
     }
     set {
         rows[key] = newValue
         orderIndex[key.order] = key
     }
 }
 
 func index(after i: DictionaryType.Index) -> DictionaryType.Index {
     return rows.index(after: i)
 }
 
 // MARK: - Sequence
 typealias Iterator = AnyIterator<(key: ID, value: TableRow)>
 
 func makeIterator() -> Iterator {
     var iterator = rows.makeIterator()
     
     return AnyIterator {
         return iterator.next()
     }
 }
}




protocol TableViewModel {
 associatedtype Sectioning: TableSectioning
 
 var sections: [Sectioning] { get }
}


extension TableViewModel {
 func tableRow(for indexPath: IndexPath) -> TableRow? {
     return sections[indexPath.section].row(at: indexPath.row)
 }
}



protocol InputRow: class, TableRow {
 typealias InputValue = AnyObject
 
 var value: InputValue? { get set }
 var isValid: Bool { get }
}


protocol TextInputRow: InputRow {
 var title: String { get set }
 var text: String? { get set }
}


extension TextInputRow {
 var value: Self.InputValue? {
     get {
         return text as Self.InputValue
     }
     set {
         text = newValue as? String
     }
 }
 
 var isTextInLimit: Bool {
     return true
 }
}




protocol BaseFormViewModel: TableViewModel where ID: TableRowID & Hashable {
 associatedtype ID
 typealias Values = [ID: InputRow.InputValue]
 
 func id(at indexPath: IndexPath) -> ID?
 func indexPath(with id: ID) -> IndexPath?


 func inputValue(with id: ID) -> InputRow.InputValue?


 var indexPathForFirstInputRow: IndexPath? { get }
}


extension BaseFormViewModel {
 func inputRow(with id: Self.Sectioning.ID) -> InputRow? {
     for section in sections {
         guard let row = section.rows[id] as? InputRow else { continue }
         return row
     }
     return nil
 }
 
 func inputValue(with id: Self.Sectioning.ID) -> InputRow.InputValue? {
     return inputRow(with: id)?.value
 }
 
 var indexPathForFirstInputRow: IndexPath? {
     var sectionIndex = 0
     for section in sections {
         for index in 0..<section.count {
             guard let _ = section.row(at: index) as? TextInputRow else { continue }
             return IndexPath(row: index, section: sectionIndex)
         }
         sectionIndex += 1
     }
     return nil
 }
}


class DefaultFormViewModel<I>: BaseFormViewModel where I: TableRowID & Hashable {
 typealias ID = I
 typealias Sectioning = TableSection<ID>
 
 internal(set) var sections: [Sectioning] = [] {
     didSet {
         setupIndex()
     }
 }
 private(set) var inputIndex: [ID: IndexPath] = [:]
 private(set) var pathIndex: [IndexPath: ID] = [:]


 
 func setupIndex() {
     inputIndex.removeAll()
     pathIndex.removeAll()
     
     var sectionIndex = 0
     for section in sections {
         for index in 0..<section.count {
             guard let key = section.orderIndex[index] else { continue }
             let indexPath = IndexPath(row: index, section: sectionIndex)
             inputIndex[key] = indexPath
             pathIndex[indexPath] = key
         }
         sectionIndex += 1
     }
 }
 
 func inputValue(with id: ID) -> InputRow.InputValue? {
     return inputRow(with: id)?.value
 }
 
 func id(at indexPath: IndexPath) -> ID? {
     return pathIndex[indexPath]
 }
 
 func indexPath(with id: ID) -> IndexPath? {
     return inputIndex[id]
 }
}


class BaseFormVC<VM: BaseFormViewModel>: UIViewController, UITextViewDelegate, UITextFieldDelegate {
 private var formSentIndicator: Bool = false
 
 weak var tableView: UITableView!
 
 // MARK: - Model
 internal var viewModel: VM?
 
 // MARK: - First responder
 internal func makeFirstInputFirstResponder() {
     guard let indexPath = viewModel?.indexPathForFirstInputRow,
         let cell = tableView.cellForRow(at: indexPath) else { return }
     
     if let cell = cell as? InputViewCell {
         cell.inputResponder?.becomeFirstResponder()
     }
 }
 
 internal func makeInputFirstResponder(with id: VM.ID) {
     guard !formSentIndicator,
         let indexPath = viewModel?.indexPath(with: id) else { return }
     if let cell = tableView.cellForRow(at: indexPath) as? InputViewCell {
         cell.inputResponder?.becomeFirstResponder()
     } else {
         tableView.scrollToRow(at: indexPath, at: .top, animated: true)
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
             if let cell = self.tableView.cellForRow(at: indexPath) as? InputViewCell {
                 cell.inputResponder?.becomeFirstResponder()
             }
         }
     }
 }
 
}




struct Payment {
 var amount: Double
 var message: String
}


protocol NewPaymentVM: BaseFormViewModel {
 associatedtype Value = Payment
 
 var payment: Value { get }
}


protocol PaymentController where Self: UIViewController {
 var payment: Payment? { get set }
}


class NewPaymentVC<RPVM>: BaseFormVC<RPVM>, PaymentController where RPVM: NewPaymentVM {
 var payment: Payment? = nil {
     didSet {
         setupViewModel()
     }
 }
 
 override func viewDidAppear(_ animated: Bool) {
     super.viewDidAppear(animated)
     
     makeFirstInputFirstResponder()
 }
 
 internal func setupViewModel() {
     
 }
}




enum NewDirectDebitInputType: Int, TableRowID {
 case amount
 case message
}


class NewDirectDebitPaymentVM: DefaultFormViewModel<NewDirectDebitInputType>, NewPaymentVM {
 var payment: Payment


 init(payment: Payment) {
     self.payment = payment


     super.init()
 }
}


class NewDirectDebitPaymentVC: NewPaymentVC<NewDirectDebitPaymentVM> {
 override func setupViewModel() {
     guard let payment = payment else { return }
     let viewModel = NewDirectDebitPaymentVM(payment: payment)
     self.viewModel = viewModel
 }
 
 internal override func makeFirstInputFirstResponder() {
     if let limit = viewModel?.inputValue(with: .amount) as? Double, limit > 0 {
         makeInputFirstResponder(with: .message)
     } else {
         super.makeFirstInputFirstResponder()
     }
 }
}

@eeckstein
Copy link
Member

eeckstein commented Sep 24, 2018

Thanks! I can reproduce the crash.

@eeckstein
Copy link
Member

eeckstein commented Sep 24, 2018

@swift-ci create

@slavapestov
Copy link
Member

slavapestov commented Oct 2, 2018

Reduced test case:

extension C : P {}

class C<T> where T : Hashable {}

protocol P {
  associatedtype T : Hashable
  func f()
}

extension P {
  func f() {}
}

If you run it with -emit-silgen you'll see that the 'T : Hashable' requirement is incorrectly dropped from the protocol witness thunk's generic signature.

@slavapestov
Copy link
Member

slavapestov commented Oct 10, 2018

So I made a bit of progress, but it’s still a mystery.

My latest test case requires this setup:

protocol Q {}
protocol P {
  associatedtype T : Q
}

class C<T> : P where T : Q {}

Here is the bad case I’ve been looking at:

func foo<U, T>(_: U, _: T) where U : C<T>, U : P {}

Here, T and U.T are in the same equivalence class. The conformance U : P has two sources:

  • Inferred

  • Explicit -> Protocol requirement (via Self.T in P)

The second one responds with true to isDerivedRequirement(), so it becomes the best one, so it gets dropped.

Now this version of foo() works — but for the wrong reason:

func foo<U, T>(_: U, _: T) where U : P, U : C<T> {}

When we add same-type requirements between a type parameter and a concrete type, we make sure to concretize any nested types in concretizeNestedTypeFromConcreteParent(). However, we don’t do anything of the sort when adding a superclass constraint. So in the above case, T and U.T are different equivalence classes. T : Q does not have a derived source, so we retain it in the minimized signature. However U.T is redundant for the same reason as above.

I suspect not concretizing nested types that already exist when a superclass constraint is added is causing us other problems elsewhere, too.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 5, 2019

Comment by Jonathan (JIRA)

@belkadan I don't know enough about the compiler to know if this is actually a duplicate of https://bugs.swift.org/browse/SR-10182, but SR-10182 didn't cause a crash in Swift 4/Xcode 10, only in Xcode 10.2, unlike this ticket, so not sure it should be marked as a duplicate?

Also it is still causing a segmentation fault in the Xcode 11 beta.

@gwynne
Copy link
Contributor

gwynne commented Dec 19, 2019

My repro from SR-11913 (which Slava duped here):

public protocol Something {
    associatedtype McGuffin: BinaryInteger
    func whatever() throws -> [String]
}

extension Something {
    func whatever() throws -> [String] { [] }
}

class Thing<McGuffin: BinaryInteger>: Something {}

Still happens in 11.3

@slavapestov
Copy link
Member

slavapestov commented Jun 22, 2020

#32488

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants