Skip to content

Commit

Permalink
Fix another concurrent mutation crash while indexing. Closes #453 (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch authored Jan 6, 2022
1 parent ab167f6 commit 7c61d1a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

##### Bug Fixes

- None.
- Fix another crash while indexing.

## 2.8.5 (2022-01-03)

Expand Down
20 changes: 14 additions & 6 deletions Sources/PeripheryKit/Indexer/SourceGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 }
}
}

Expand Down
32 changes: 16 additions & 16 deletions Sources/PeripheryKit/Indexer/SwiftIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 7c61d1a

Please sign in to comment.