protobuf: support gaps in edition defaults calculation

protoc guarantees that the edition defaults will be ordered, but not contiguous.  Gaps represent no changes to the defaults and should be handled.

Change-Id: I01fde5ff89b2b206b066c5a415083f6526a4ed91
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/575876
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Stapelberg <stapelberg@google.com>
Reviewed-by: Michael Stapelberg <stapelberg@google.com>
diff --git a/internal/filedesc/editions.go b/internal/filedesc/editions.go
index 443b70c..5f01803 100644
--- a/internal/filedesc/editions.go
+++ b/internal/filedesc/editions.go
@@ -14,6 +14,7 @@
 )
 
 var defaultsCache = make(map[Edition]EditionFeatures)
+var defaultsKeys = []Edition{}
 
 func init() {
 	unmarshalEditionDefaults(editiondefaults.Defaults)
@@ -112,6 +113,7 @@
 		}
 	}
 	defaultsCache[ed] = fs
+	defaultsKeys = append(defaultsKeys, ed)
 }
 
 func unmarshalEditionDefaults(b []byte) {
@@ -137,8 +139,15 @@
 }
 
 func getFeaturesFor(ed Edition) EditionFeatures {
-	if def, ok := defaultsCache[ed]; ok {
-		return def
+	match := EditionUnknown
+	for _, key := range defaultsKeys {
+		if key > ed {
+			break
+		}
+		match = key
 	}
-	panic(fmt.Sprintf("unsupported edition: %v", ed))
+	if match == EditionUnknown {
+		panic(fmt.Sprintf("unsupported edition: %v", ed))
+	}
+	return defaultsCache[match]
 }