Skip to content

Check that GHC.Types.Builtin.Names builds unique Uniques

I was wary of duplicate occurrences of the same decimal number in GHC.Types.Builtin.Names, so I let ChatGPT help me in defining the following useful awk script:

$ awk '{
    # Iterate over each field
    for (i=1; i<=NF; i++) {
        # If the field is a decimal number, add it to the count
        if ($i ~ /^[0-9]+$/) {
            count[$(i-1)][$i]++
        }
    }
}
END {
    # Print the decimal numbers and their counts
    for (s in count) {
        for (num in count[s]) {
            if (count[s][num] > 1) { print s, num, count[s][num] }
        }
    }
}' compiler/GHC/Builtin/Names.hs

This will print out duplicate calls of the the form mkPreludeMiscIdUnique 135, e.g.,

mkPreludeMiscIdUnique 135 2

The last number is the number of occurrences. Perhaps that's helpful to someone or even worth a test in CI.

Edited by Matthew Pickering
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information