mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:30:12 +01:00
Fix the check that every registered diagnostic kind is declared (#7660)
`load_diagnostic_kind` matched `^\s+CARBON_DIAGNOSTIC_KIND` without `re.MULTILINE` against a file whose entries start at column zero, so it found nothing: `check_unused` was comparing an empty set of declarations against every use and reporting nothing at all. The check has never run. With it running, three kinds turn out to be registered and never declared, and go: `BuildFailureRunningClangToLink`, `BuildOutputFileOpenError`, and `BuildPreludeManifestError`. `load_diagnostic_uses_in` looked only for `CARBON_DIAGNOSTIC`, so a diagnostic declared with `CARBON_DIAGNOSTIC_ON_SCOPE` counted as unused, and it read the two macros' own definitions in `diagnostic.h` as uses. Both are why the kinds above could not simply be deleted before. Assisted-by: Claude Code --------- Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
co-authored by
Geoff Romer
parent
40aa4419c0
commit
2b9fdd6e42
@@ -56,7 +56,9 @@ def load_diagnostic_kind() -> Set[str]:
|
||||
"""
|
||||
path = Path("toolchain/diagnostics/kind.def")
|
||||
content = path.read_text()
|
||||
decls = set(re.findall(r"^\s+CARBON_DIAGNOSTIC_KIND\((.+)\)", content))
|
||||
decls = set(
|
||||
re.findall(r"^CARBON_DIAGNOSTIC_KIND\((.+)\)", content, flags=re.M)
|
||||
)
|
||||
return decls.difference(IGNORED)
|
||||
|
||||
|
||||
@@ -71,9 +73,13 @@ def load_diagnostic_uses_in(
|
||||
line_offset = 0
|
||||
|
||||
found: Dict[str, List[Loc]] = collections.defaultdict(lambda: [])
|
||||
for m in re.finditer(r"CARBON_DIAGNOSTIC\(\s*(\w+),", content):
|
||||
# `CARBON_DIAGNOSTIC_ON_SCOPE` declares a diagnostic too; the definitions of
|
||||
# both macros name their own parameter, which is not a use.
|
||||
for m in re.finditer(
|
||||
r"(?<!#define )CARBON_DIAGNOSTIC(?:_ON_SCOPE)?\(\s*(\w+),", content
|
||||
):
|
||||
diag = m.group(1)
|
||||
if diag in IGNORED:
|
||||
if diag in IGNORED or diag in ("DiagnosticName",):
|
||||
continue
|
||||
line += content.count("\n", line_offset, m.start())
|
||||
line_offset = m.start()
|
||||
|
||||
@@ -31,9 +31,6 @@ constexpr Kind UntestedKinds[] = {
|
||||
|
||||
// Diagnosing erroneous install conditions, but test environments are
|
||||
// typically correct.
|
||||
Kind::BuildFailureRunningClangToLink,
|
||||
Kind::BuildOutputFileOpenError,
|
||||
Kind::BuildPreludeManifestError,
|
||||
Kind::BuildTempDirectoryCreationError,
|
||||
Kind::BuildTempDirectoryDeletionError,
|
||||
Kind::CompileCoreManifestError,
|
||||
|
||||
@@ -25,9 +25,6 @@ CARBON_DIAGNOSTIC_KIND(DriverInstallInvalid)
|
||||
CARBON_DIAGNOSTIC_KIND(DriverRuntimesCacheInvalid)
|
||||
CARBON_DIAGNOSTIC_KIND(DriverPrebuiltRuntimesInvalid)
|
||||
CARBON_DIAGNOSTIC_KIND(DriverCommandLineParseFailed)
|
||||
CARBON_DIAGNOSTIC_KIND(BuildFailureRunningClangToLink)
|
||||
CARBON_DIAGNOSTIC_KIND(BuildOutputFileOpenError)
|
||||
CARBON_DIAGNOSTIC_KIND(BuildPreludeManifestError)
|
||||
CARBON_DIAGNOSTIC_KIND(BuildTempDirectoryCreationError)
|
||||
CARBON_DIAGNOSTIC_KIND(BuildTempDirectoryDeletionError)
|
||||
CARBON_DIAGNOSTIC_KIND(CompileCoreManifestError)
|
||||
|
||||
Reference in New Issue
Block a user