Skip to content

Commit 8640421

Browse files
Remove parallel invocation of AST parsing (#16)
1 parent c30c40a commit 8640421

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

Sources/SwiftAstGenLib/SwiftAstGenerator.swift

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ public class SwiftAstGenerator {
55
private var srcDir: URL
66
private var outputDir: URL
77
private var prettyPrint: Bool
8-
private let availableProcessors = ProcessInfo.processInfo.activeProcessorCount
9-
10-
// Private serial queue for directory creation operations
11-
private let fileQueue = DispatchQueue(label: "io.joern.swiftastgen")
128

139
public init(srcDir: URL, outputDir: URL, prettyPrint: Bool) throws {
1410
self.srcDir = srcDir
@@ -47,34 +43,26 @@ public class SwiftAstGenerator {
4743
.appendingPathExtension("json")
4844
let outfileDirUrl = outFileUrl.deletingLastPathComponent()
4945

50-
do {
51-
try fileQueue.sync {
52-
try FileManager.default.createDirectory(
53-
atPath: outfileDirUrl.path,
54-
withIntermediateDirectories: true,
55-
attributes: nil
56-
)
57-
}
58-
} catch {}
46+
if !FileManager.default.fileExists(atPath: outfileDirUrl.path) {
47+
try FileManager.default.createDirectory(
48+
atPath: outfileDirUrl.path,
49+
withIntermediateDirectories: true,
50+
attributes: nil
51+
)
52+
}
5953

6054
try astJsonString.write(
6155
to: outFileUrl,
6256
atomically: true,
6357
encoding: String.Encoding.utf8
6458
)
65-
66-
print("Generated AST for file: `\(fileUrl.path)`")
59+
print("Generated AST for file: `\(fileUrl.path)`")
6760
} catch {
6861
print("Parsing failed for file: `\(fileUrl.path)` (\(error))")
6962
}
7063
}
7164

7265
private func iterateSwiftFiles(at url: URL) {
73-
let queue = OperationQueue()
74-
queue.name = "SwiftAstGen"
75-
queue.qualityOfService = .userInitiated
76-
queue.maxConcurrentOperationCount = availableProcessors
77-
7866
if let enumerator = FileManager.default.enumerator(
7967
at: url,
8068
includingPropertiesForKeys: [.isRegularFileKey],
@@ -84,15 +72,11 @@ public class SwiftAstGenerator {
8472
if fileAttributes.isRegularFile! && fileURL.pathExtension == "swift" {
8573
let relativeFilePath = fileURL.relativePath(from: srcDir)!
8674
if !ignoreDirectory(name: "/\(relativeFilePath)") {
87-
queue.addOperation {
88-
self.parseFile(fileUrl: fileURL)
89-
}
75+
self.parseFile(fileUrl: fileURL)
9076
}
9177
}
9278
}
9379
}
94-
95-
queue.waitUntilAllOperationsAreFinished()
9680
}
9781

9882
public func generate() throws {

0 commit comments

Comments
 (0)