Crash: KEY_TYPE_OF_DICTIONARY_VIOLATES_HASHABLE_REQUIREMENTS

Hi everyone,

frome time to time I see crash which Im not able to debug, because there is no line of my code where crash occured.

This is a crash log what Im getting from time to time of some users. In my device I never get this kind of crash.

0  libswiftCore.dylib             0x1172c _assertionFailure(_:_:flags:) + 208
1  libswiftCore.dylib             0x198624 KEY_TYPE_OF_DICTIONARY_VIOLATES_HASHABLE_REQUIREMENTS(_:) + 2980
2  libswiftCore.dylib             0xdb6c8 specialized _NativeDictionary.uncheckedRemove(at:isUnique:) + 534
3  libswiftCore.dylib             0xb250c Dictionary._Variant.setValue(_:forKey:) + 204
4  libswiftCore.dylib             0x5a620 Dictionary.subscript.setter + 520
5  SwiftUICore                    0xf62ec ForEachState.item(at:offset:) + 4340
6  SwiftUICore                    0xf5054 ForEachState.forEachItem(from:style:do:) + 1796
7  SwiftUICore                    0x2272f8 ForEachState.traitKeys.getter + 84
8  SwiftUICore                    0x227298 ForEachList.traitKeys.getter + 24
9  SwiftUICore                    0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76
10 SwiftUICore                    0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76
11 SwiftUICore                    0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76
12 SwiftUICore                    0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76
13 SwiftUICore                    0x2271fc DynamicViewList.WrappedList.traitKeys.getter + 88
27 SwiftUICore                    0x226d18 specialized static SectionAccumulator.processUnsectionedContent(list:contentSubgraph:) + 84
28 SwiftUI                        0x26afe0 ListSectionInfo.init(list:listAttribute:contentSubgraph:) + 132
29 SwiftUI                        0x269bb0 UpdateCollectionViewListCoordinator.updateValue() + 1528
30 SwiftUI                        0x785d4 partial apply for implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>(_:) + 32
31 AttributeGraph                 0xccac AG::Graph::UpdateStack::update() + 540
32 AttributeGraph                 0xc870 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424
33 AttributeGraph                 0xc444 AG::Subgraph::update(unsigned int) + 848
34 SwiftUICore                    0x805a8 GraphHost.flushTransactions() + 860
35 SwiftUI                        0x1ac84 closure #1 in _UIHostingView._renderForTest(interval:) + 24
36 SwiftUICore                    0x7ffa8 partial apply for closure #1 in ViewGraphDelegate.updateGraph<A>(body:) + 28
37 SwiftUICore                    0x7fd6c ViewRendererHost.updateViewGraph<A>(body:) + 120
38 SwiftUICore                    0x7fce8 ViewGraphDelegate.updateGraph<A>(body:) + 84
39 SwiftUI                        0x3e688 closure #1 in closure #1 in closure #1 in _UIHostingView.beginTransaction() + 172
40 SwiftUI                        0x3e5d4 partial apply for closure #1 in closure #1 in closure #1 in _UIHostingView.beginTransaction() + 24
41 SwiftUICore                    0x79720 closure #1 in static Update.ensure<A>(_:) + 56
42 SwiftUICore                    0x796a4 static Update.ensure<A>(_:) + 100
43 SwiftUI                        0x9c808 partial apply for closure #1 in closure #1 in _UIHostingView.beginTransaction() + 80
44 SwiftUICore                    0x7f5e0 thunk for @callee_guaranteed () -> () + 28
45 SwiftUICore                    0x6161c specialized closure #1 in static NSRunLoop.addObserver(_:) + 144
46 CoreFoundation                 0x218a4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36
47 CoreFoundation                 0x213f8 __CFRunLoopDoObservers + 552
48 CoreFoundation                 0x75da8 __CFRunLoopRun + 948
49 CoreFoundation                 0xc8284 CFRunLoopRunSpecific + 588
50 GraphicsServices               0x14c0 GSEventRunModal + 164
51 UIKitCore                      0x3ee674 -[UIApplication _run] + 816
52 UIKitCore                      0x14e88 UIApplicationMain + 340
53 SwiftUI                        0x291ef8 closure #1 in KitRendererCommon(_:) + 168
54 SwiftUI                        0x291e28 runApp<A>(_:) + 100
55 SwiftUI                        0x291d0c static App.main() + 180
56 DholRainbow                    0x3019e8 main + 4339145192 (DholRainbowApp.swift:4339145192)
57 ???                            0x1b0bf5de8 (Missing)

From Crashlytics I know at least human readable format of this error

Fatal error: Duplicate keys of type 'Contact' were found in a Dictionary. This usually means either that the type violates Hashable's requirements, or that members of such a dictionary were mutated after insertion.

I 've checked all my parts of code where Im using dictionary. This is a function which creating that particulary dictionary.

    private func logsByDate() {
                
        let groupedByDate = Dictionary(grouping: logs.filter { ($0.remoteParty as? Contact != nil) } ) {
            $0.date.removeTimeStamp ?? .distantPast }.mapValues {
                $0.compactMap { $0 }
            }
        
        var dayLogs = [DayLog]()
                
        for date in groupedByDate {
            var contacts = [CallLogContact]()
            
            for log in logs.filter({ $0.date.removeTimeStamp ?? .distantPast == date.key }) {
                
                if let contact = log.remoteParty as? Contact {
                    
                    if contacts.firstIndex(where: {$0.contact == contact }) == nil {
                        
                        let contactDayLogs = logs.filter({ $0.remoteParty as? Contact == contact && $0.date.removeTimeStamp == date.key})
                        
                        contacts.append(
                            CallLogContact(
                                contact: contact,
                                logs: contactDayLogs,
                                lastCallLogDate: contactDayLogs.sorted(by: {$0.date > $1.date}).first?.date ?? .distantPast
                            )
                        )
                    }
                }
            }
            
            dayLogs.append(DayLog(date: date.key, contact: contacts))
        }
        
        DispatchQueue.main.async {
            self.groupedCallLogs = dayLogs
        }
    }

This function is called from 3 others functions based on notification from the server in case of new call log, fetched call logs and removed call logs.

Crash: KEY_TYPE_OF_DICTIONARY_VIOLATES_HASHABLE_REQUIREMENTS
 
 
Q