Appearance
| 1 | namespace Logging is | |
| 2 | // A pass can walk the same tree more than once - a property's type | |
| 3 | // expression is resolved on every walk of it - and report the same | |
| 4 | // thing each time. The duplicates say nothing the first report did | |
| 5 | // not, so one file's diagnostics keep the first of any set that | |
| 6 | // agree on severity, span, code and wording. | |
| 7 | // | |
| 8 | // Held per file and per speculation level, which is what makes this | |
| 9 | // respect a roll back: a level that is rolled back takes its record | |
| 10 | // of what it has seen with it, so a report made only inside it is | |
| 11 | // made again when the walk that survives repeats it. | |
| 12 | // | |
| 13 | // The wording is part of the key because the wording is the datum | |
| 14 | // here - two reports that read identically to the user are what is | |
| 15 | // being collapsed - rather than a rendering of some entity standing | |
| 16 | // in for it. | |
| 17 | class DIAGNOSTIC_DEDUPLICATOR is | |
| 18 | _seen: Collections.SET[string] | |
| 19 | ||
| 20 | init() is | |
| 21 | _seen = Collections.SET[string]() | |
| 22 | si | |
| 23 | ||
| 24 | // True where the message has not been seen before, which is also | |
| 25 | // when it is recorded. | |
| 26 | is_first(message: DIAGNOSTIC_MESSAGE) -> bool is | |
| 27 | let key = _key(message) | |
| 28 | ||
| 29 | if _seen.contains(key) then | |
| 30 | return false | |
| 31 | fi | |
| 32 | ||
| 33 | _seen.add(key) | |
| 34 | ||
| 35 | return true | |
| 36 | si | |
| 37 | ||
| 38 | _key(message: DIAGNOSTIC_MESSAGE) -> string => | |
| 39 | "{cast int(message.severity)} |