Skip to content

Commit

Permalink
Remove structure cache (realm#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim authored Nov 10, 2022
1 parent 4bd7da3 commit 04d1184
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
18 changes: 1 addition & 17 deletions Source/SwiftLintFramework/Extensions/SwiftLintFile+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ private let responseCache = Cache { file -> [String: SourceKitRepresentable]? in
return nil
}
}
private let structureCache = Cache { file -> Structure? in
return responseCache.get(file).map(Structure.init)
}
private let structureDictionaryCache = Cache { file in
return structureCache.get(file).map { SourceKittenDictionary($0.dictionary) }
return responseCache.get(file).map(Structure.init).map { SourceKittenDictionary($0.dictionary) }
}
private let syntaxTreeCache = Cache { file -> SourceFileSyntax in
return Parser.parse(source: file.contents)
Expand Down Expand Up @@ -131,17 +128,6 @@ extension SwiftLintFile {

internal var linesWithTokens: Set<Int> { linesWithTokensCache.get(self) }

internal var structure: Structure {
guard let structure = structureCache.get(self) else {
if let handler = assertHandler {
handler()
return Structure(sourceKitResponse: [:])
}
queuedFatalError("Never call this for file that sourcekitd fails.")
}
return structure
}

internal var structureDictionary: SourceKittenDictionary {
guard let structureDictionary = structureDictionaryCache.get(self) else {
if let handler = assertHandler {
Expand Down Expand Up @@ -199,7 +185,6 @@ extension SwiftLintFile {
file.clearCaches()
responseCache.invalidate(self)
assertHandlerCache.invalidate(self)
structureCache.invalidate(self)
structureDictionaryCache.invalidate(self)
syntaxClassificationsCache.invalidate(self)
syntaxMapCache.invalidate(self)
Expand All @@ -214,7 +199,6 @@ extension SwiftLintFile {
internal static func clearCaches() {
responseCache.clear()
assertHandlerCache.clear()
structureCache.clear()
structureDictionaryCache.clear()
syntaxClassificationsCache.clear()
syntaxMapCache.clear()
Expand Down
10 changes: 0 additions & 10 deletions Tests/SwiftLintFrameworkTests/SourceKitCrashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ class SourceKitCrashTests: XCTestCase {
var assertHandlerCalled = false
file.assertHandler = { assertHandlerCalled = true }

_ = file.structure
XCTAssertFalse(assertHandlerCalled,
"Expects assert handler was not called on accessing SwiftLintFile.structure")

assertHandlerCalled = false
_ = file.syntaxMap
XCTAssertFalse(assertHandlerCalled,
"Expects assert handler was not called on accessing SwiftLintFile.syntaxMap")
Expand All @@ -36,11 +31,6 @@ class SourceKitCrashTests: XCTestCase {
var assertHandlerCalled = false
file.assertHandler = { assertHandlerCalled = true }

_ = file.structure
XCTAssertTrue(assertHandlerCalled,
"Expects assert handler was called on accessing SwiftLintFile.structure")

assertHandlerCalled = false
_ = file.syntaxMap
XCTAssertTrue(assertHandlerCalled,
"Expects assert handler was called on accessing SwiftLintFile.syntaxMap")
Expand Down

0 comments on commit 04d1184

Please sign in to comment.