<commit_before>#!/bin/bash
#
# This script produces a list of all diagnostics that are defined
# in Diagnostic*.td files but not used in sources.
#

ALL_DIAGS=$(mktemp)
ALL_SOURCES=$(mktemp)

grep -E --only-matching --no-filename '(err_|warn_|ext_|note_)[a-z_]+ ' ./include/clang/Basic/Diagnostic*.td > $ALL_DIAGS
find lib include tools -name \*.cpp -or -name \*.h > $ALL_SOURCES
for DIAG in $(cat $ALL_DIAGS); do
  if ! grep -r $DIAG $(cat $ALL_SOURCES) > /dev/null; then
    echo $DIAG
  fi;
done

rm $ALL_DIAGS $ALL_SOURCES
<commit_msg>Speed up find-unused-diagnostics. Now runs in less than a second instead of more than a minute.<commit_after>#!/bin/bash
#
# This script produces a list of all diagnostics that are defined
# in Diagnostic*.td files but not used in sources.
#

# Gather all diagnostic identifiers from the .td files.
ALL_DIAGS=$(grep -E --only-matching --no-filename '(err_|warn_|ext_|note_)[a-z_]+' ./include/clang/Basic/Diagnostic*.td)

# Now look for all potential identifiers in the source files.
ALL_SOURCES=$(find lib include tools -name \*.cpp -or -name \*.h)
DIAGS_IN_SOURCES=$(grep -E --only-matching --no-filename '(err_|warn_|ext_|note_)[a-z_]+' $ALL_SOURCES)

# Print all diags that occur in the .td files but not in the source.
diff -u <(sort -u <<< "$ALL_DIAGS") <(sort -u <<< "$DIAGS_IN_SOURCES") | sed -En 's/^-([a-z_]+)/\1/p'
{'fraction_non_alphanumeric': 0.15260454878943508, 'fraction_numerical': 0.0007336757153338225, 'mean_word_length': 4.014705882352941, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915902', 'n_tokens_mistral': 529, 'n_tokens_neox': 496, 'n_words': 159}