diff --git a/CHANGELOG.md b/CHANGELOG.md index cd80ba7de..9717021ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ##### Bug Fixes -- None. +- Fix another crash while indexing. ## 2.8.5 (2022-01-03) diff --git a/Sources/PeripheryKit/Indexer/SourceGraph.swift b/Sources/PeripheryKit/Indexer/SourceGraph.swift index e4454ae42..756cddcda 100644 --- a/Sources/PeripheryKit/Indexer/SourceGraph.swift +++ b/Sources/PeripheryKit/Indexer/SourceGraph.swift @@ -93,10 +93,14 @@ public final class SourceGraph { func markRetained(_ declaration: Declaration) { mutationQueue.sync { - _ = retainedDeclarations.insert(declaration) + markRetainedUnsafe(declaration) } } + func markRetainedUnsafe(_ declaration: Declaration) { + _ = retainedDeclarations.insert(declaration) + } + func markPotentialAssignOnlyProperty(_ declaration: Declaration) { mutationQueue.sync { _ = potentialAssignOnlyProperties.insert(declaration) @@ -117,12 +121,16 @@ public final class SourceGraph { func add(_ declaration: Declaration) { mutationQueue.sync { - allDeclarations.insert(declaration) - allDeclarationsByKind[declaration.kind, default: []].insert(declaration) + addUnsafe(declaration) + } + } - if !declaration.isImplicit { - declaration.usrs.forEach { allExplicitDeclarationsByUsr[$0] = declaration } - } + func addUnsafe(_ declaration: Declaration) { + allDeclarations.insert(declaration) + allDeclarationsByKind[declaration.kind, default: []].insert(declaration) + + if !declaration.isImplicit { + declaration.usrs.forEach { allExplicitDeclarationsByUsr[$0] = declaration } } } diff --git a/Sources/PeripheryKit/Indexer/SwiftIndexer.swift b/Sources/PeripheryKit/Indexer/SwiftIndexer.swift index 0b3e3bd26..a3e7b1cd2 100644 --- a/Sources/PeripheryKit/Indexer/SwiftIndexer.swift +++ b/Sources/PeripheryKit/Indexer/SwiftIndexer.swift @@ -280,14 +280,13 @@ public final class SwiftIndexer { private func associateLatentReferences() { for (usr, refs) in referencesByUsr { - guard let decl = graph.explicitDeclaration(withUsr: usr) else { - danglingReferences.append(contentsOf: refs) - continue - } - graph.mutating { - for ref in refs { - associateUnsafe(ref, with: decl) + if let decl = graph.explicitDeclaration(withUsr: usr) { + for ref in refs { + associateUnsafe(ref, with: decl) + } + } else { + danglingReferences.append(contentsOf: refs) } } } @@ -433,15 +432,16 @@ public final class SwiftIndexer { } } - for param in params { - let paramDecl = param.declaration - paramDecl.parent = functionDecl - functionDecl.unusedParameters.insert(paramDecl) - graph.add(paramDecl) - - if ignoredParamNames.contains(param.name) || - (functionDecl.isObjcAccessible && configuration.retainObjcAccessible) { - graph.markRetained(paramDecl) + graph.mutating { + for param in params { + let paramDecl = param.declaration + paramDecl.parent = functionDecl + functionDecl.unusedParameters.insert(paramDecl) + graph.addUnsafe(paramDecl) + + if (functionDecl.isObjcAccessible && configuration.retainObjcAccessible) || ignoredParamNames.contains(param.name) { + graph.markRetainedUnsafe(paramDecl) + } } } }