Skip to content

Commit d9e1684

Browse files
committed
Fix concurrent access crash. Closes #232
1 parent 189717a commit d9e1684

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
##### Bug Fixes
1212

13-
- None.
13+
- Fix crash during indexing phase.
1414

1515
## 2.3.0 (2020-12-05)
1616

Sources/PeripheryKit/Indexer/SourceGraph.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,19 @@ public final class SourceGraph {
9898

9999
func remove(_ declaration: Declaration) {
100100
mutationQueue.sync {
101-
declaration.parent?.declarations.remove(declaration)
102-
allDeclarations.remove(declaration)
103-
allDeclarationsByKind[declaration.kind]?.remove(declaration)
104-
rootDeclarations.remove(declaration)
105-
reachableDeclarations.remove(declaration)
106-
declaration.usrs.forEach { allExplicitDeclarationsByUsr.removeValue(forKey: $0) }
101+
removeUnsafe(declaration)
107102
}
108103
}
109104

105+
func removeUnsafe(_ declaration: Declaration) {
106+
declaration.parent?.declarations.remove(declaration)
107+
allDeclarations.remove(declaration)
108+
allDeclarationsByKind[declaration.kind]?.remove(declaration)
109+
rootDeclarations.remove(declaration)
110+
reachableDeclarations.remove(declaration)
111+
declaration.usrs.forEach { allExplicitDeclarationsByUsr.removeValue(forKey: $0) }
112+
}
113+
110114
func add(_ reference: Reference) {
111115
mutationQueue.sync {
112116
_ = allReferences.insert(reference)

Sources/PeripheryKit/Indexer/SwiftIndexer.swift

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,32 +216,30 @@ public final class SwiftIndexer {
216216
private var varParameterUsrs: Set<String> = []
217217

218218
private func establishDeclarationHierarchy() {
219-
for (parent, decls) in childDeclsByParentUsr {
220-
guard let parentDecl = graph.explicitDeclaration(withUsr: parent) else {
221-
if varParameterUsrs.contains(parent) {
222-
// These declarations are children of a parameter and are redundant.
223-
decls.forEach { graph.remove($0) }
224-
}
219+
graph.mutating {
220+
for (parent, decls) in childDeclsByParentUsr {
221+
guard let parentDecl = graph.explicitDeclaration(withUsr: parent) else {
222+
if varParameterUsrs.contains(parent) {
223+
// These declarations are children of a parameter and are redundant.
224+
decls.forEach { graph.removeUnsafe($0) }
225+
}
225226

226-
continue
227-
}
227+
continue
228+
}
228229

229-
graph.mutating {
230230
for decl in decls {
231231
decl.parent = parentDecl
232232
}
233233

234234
parentDecl.declarations.formUnion(decls)
235235
}
236-
}
237236

238-
for (usr, references) in referencedDeclsByUsr {
239-
guard let decl = graph.explicitDeclaration(withUsr: usr) else {
240-
danglingReferences.append(contentsOf: references)
241-
continue
242-
}
237+
for (usr, references) in referencedDeclsByUsr {
238+
guard let decl = graph.explicitDeclaration(withUsr: usr) else {
239+
danglingReferences.append(contentsOf: references)
240+
continue
241+
}
243242

244-
graph.mutating {
245243
for reference in references {
246244
reference.parent = decl
247245

@@ -252,9 +250,7 @@ public final class SwiftIndexer {
252250
}
253251
}
254252
}
255-
}
256253

257-
graph.mutating {
258254
for (decl, refs) in referencedUsrsByDecl {
259255
for ref in refs {
260256
ref.parent = decl

0 commit comments

Comments
 (0)