func (b *builder) writeCompactIndex() {
	m := map[language.Tag]bool{}
	for _, lang := range b.data.Locales() {
		tag := language.Make(strings.Replace(lang, "_POSIX", "-u-va-posix", 1))
		m[tag] = true
	}
	for _, plurals := range b.supp.Plurals {
		for _, rules := range plurals.PluralRules {
			for _, lang := range strings.Split(rules.Locales, " ") {
				m[language.Make(lang)] = true
			}
		}
	}
	var coreTags []language.CompactCoreInfo
	var special []string
	for t := range m {
		if x := t.Extensions(); len(x) != 0 && fmt.Sprint(x) != "[u-va-posix]" {
			log.Fatalf("Unexpected extension %v in %v", x, t)
		}
		if len(t.Variants()) == 0 && len(t.Extensions()) == 0 {
			cci, ok := language.GetCompactCore(t)
			if !ok {
				log.Fatalf("Locale for non-basic language %q", t)
			}
			coreTags = append(coreTags, cci)
		} else {
			special = append(special, t.String())
		}
	}
	w := b.w
	sort.Slice(coreTags, func(i, j int) bool { return coreTags[i] < coreTags[j] })
	sort.Strings(special)
	w.WriteComment(`
	NumCompactTags is the number of common tags. The maximum tag is
	NumCompactTags-1.`)
	w.WriteConst("NumCompactTags", len(m))
	fmt.Fprintln(w, "const (")
	for i, t := range coreTags {
		fmt.Fprintf(w, "%s ID = %d\n", ident(t.Tag().String()), i)
	}
	for i, t := range special {
		fmt.Fprintf(w, "%s ID = %d\n", ident(t), i+len(coreTags))
	}
	fmt.Fprintln(w, ")")
	w.WriteVar("coreTags", coreTags)
	w.WriteConst("specialTagsStr", strings.Join(special, " "))
}
Compact indices:
Note -va-X variants only apply to localization variants.
BCP variants only ever apply to language.
The only ambiguity between tags is with regions.
package main
import (
	"fmt"
	"log"
	"sort"
	"strings"
	"golang.org/x/text/internal/language"
)