Skip to content

Commit da9efb0

Browse files
committed
Fixes a bug where the errors variable could be mutated on multiple threads by switching to Structured Concurrency from GCD, allowing the compiler to prevent future bugs of this nature from being written
1 parent 3527bb7 commit da9efb0

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

CodeGeneration/Sources/generate-swift-syntax/GenerateSwiftSyntax.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
153153
}
154154
)
155155

156-
let specs = fileSpecs
157-
await withTaskGroup(of: (URL, Error?).self) { group in
158-
for index in 0..<fileSpecs.count {
156+
await withTaskGroup(of: (url: URL, error: Error?).self) { group in
157+
for fileSpec in fileSpecs {
159158
group.addTask {
160-
let fileSpec = specs[index]
161159
do {
162160
var destination = destination
163161
for component in fileSpec.pathComponents {
@@ -181,9 +179,9 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
181179
}
182180
}
183181
for await result in group {
184-
_ = previouslyGeneratedFiles.remove(result.0)
185-
if let error = result.1 {
186-
print(error)
182+
_ = previouslyGeneratedFiles.remove(result.url)
183+
if let error = result.error {
184+
print("Error when generating file at \(result.url):", error)
187185
}
188186
}
189187
}
@@ -197,7 +195,7 @@ struct GenerateSwiftSyntax: AsyncParsableCommand {
197195

198196
}
199197

200-
func generateFile(
198+
fileprivate func generateFile(
201199
contents: @autoclosure () -> String,
202200
destination: URL,
203201
verbose: Bool

0 commit comments

Comments
 (0)