Skip to content

Commit

Permalink
YAML diagnostics collector should have stable output (#295)
Browse files Browse the repository at this point in the history
YAML diagnostics collector should have stable output

### Motivation

Fixes #294.

Since we're running generation in parallel now, the order of diagnostics depends on the racing of the cores, resulting in unstable output.

### Modifications

Sort the diagnostics before writing them to file, making the output stable again.

### Result

Stable YAML diagnostics file.

### Test Plan

N/A, the order isn't significant, so we're not testing the details of the sorting function, we just care about it being stable.


Reviewed by: dnadoba

Builds:
     ✔︎ pull request validation (5.8) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (compatibility test) - Build finished. 
     ✔︎ pull request validation (docc test) - Build finished. 
     ✔︎ pull request validation (integration test) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#295
  • Loading branch information
czechboy0 authored Sep 25, 2023
1 parent a359eab commit df985d7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ final class _YamlFileDiagnosticsCollector: DiagnosticCollector, @unchecked Senda
func finalize() throws {
lock.lock()
defer { lock.unlock() }
let uniqueMessages = Set(diagnostics.map(\.message)).sorted()
let sortedDiagnostics = diagnostics.sorted(by: { a, b in
a.description < b.description
})
let uniqueMessages = Set(sortedDiagnostics.map(\.message)).sorted()
let encoder = YAMLEncoder()
encoder.options.sortKeys = true
let container = _DiagnosticsYamlFileContent(
uniqueMessages: uniqueMessages,
diagnostics: diagnostics
diagnostics: sortedDiagnostics
)
try encoder
.encode(container)
Expand Down

0 comments on commit df985d7

Please sign in to comment.