runtime/protoimpl, cmd/protoc-gen-go: support release versioning

In order for protoc-gen-go to output the current version,
it needs to know what version it is currently running as.
However, we cannot rely on the git tags since the tags are not
made until *after* the commit has been submitted.
Instead, we manually encode the version into the code and
make sure that git tags match up with the version in the code.

The version.go file in runtime/protoimpl contains instructions
for how to make a release. Essentially:
* Every non-release commit has a version string with "devel" in it.
* Every release commit must not have "devel" in it and must be unique.
* The "release process" involves submitting two CLs.
The first CL creates a version string without "devel",
which is the commit that a git tag will actually reference.
The second CL follows immediately and re-introduces "devel"
into the version string.

The following example shows a possible sequence of VersionStrings
for git commits in time-ascending order:
	v1.19.0-devel      (this CL)
	v1.19.0-devel
	v1.19.0-devel
	v1.19.0-devel
	v1.20.0-rc.1       <- tagged
	v1.20.0-rc.1.devel
	v1.20.0-rc.1.devel
	v1.20.0-rc.1.devel
	v1.20.0-rc.2       <- tagged
	v1.20.0-rc.2.devel
	v1.20.0            <- tagged (future public release)
	v1.20.0-devel
	v1.20.0-devel
	v1.20.0-devel
	v1.20.0-devel
	v1.20.1            <- tagged
	v1.20.1-devel
	v1.20.1-devel
	v1.21.0            <- tagged
	v1.21.0-devel

Note that we start today with v1.19.0-devel, which means that our initial
release will be v1.20.0. This number was intentionally chosen since
1) the number 20 has some correlation to the fact that we keep calling
the new implementation the "v2" implementation, and
2) the set of tagged versions for github.com/golang/protobuf
and google.golang.org/protobuf are unlikely to ever overlap.
This way, the version of protoc-gen-go is never ambiguous which module
it was built from.

Now that we have version information, we add support for generating .pb.go
files with the version information recorded. However, we do not emit
these for .pb.go files in our own repository since they are always guaranteed
to be at the right version (enforced by integration_test.go).

Updates golang/protobuf#524

Change-Id: I25495a45042c2aa39a39cb7e7738ae8e831a9d26
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/186117
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/cmd/protoc-gen-go-grpc/testdata/grpc/deprecation.pb.go b/cmd/protoc-gen-go-grpc/testdata/grpc/deprecation.pb.go
index 961e213..a201555 100644
--- a/cmd/protoc-gen-go-grpc/testdata/grpc/deprecation.pb.go
+++ b/cmd/protoc-gen-go-grpc/testdata/grpc/deprecation.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 var File_grpc_deprecation_proto protoreflect.FileDescriptor
 
 var file_grpc_deprecation_proto_rawDesc = []byte{
diff --git a/cmd/protoc-gen-go-grpc/testdata/grpc/grpc.pb.go b/cmd/protoc-gen-go-grpc/testdata/grpc/grpc.pb.go
index e8b25ea..670353a 100644
--- a/cmd/protoc-gen-go-grpc/testdata/grpc/grpc.pb.go
+++ b/cmd/protoc-gen-go-grpc/testdata/grpc/grpc.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Request struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 9fe5f29..9de3c43 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -11,6 +11,7 @@
 	"go/parser"
 	"go/token"
 	"math"
+	"runtime"
 	"strconv"
 	"strings"
 	"unicode"
@@ -25,6 +26,9 @@
 	"google.golang.org/protobuf/types/descriptorpb"
 )
 
+// GenerateVersionMarkers specifies whether to generate version markers.
+var GenerateVersionMarkers = true
+
 const (
 	// generateEnumJSONMethods specifies whether to generate the UnmarshalJSON
 	// method for proto2 enums.
@@ -145,28 +149,21 @@
 	}
 
 	genStandaloneComments(g, f, fieldnum.FileDescriptorProto_Syntax)
-
-	g.P("// Code generated by protoc-gen-go. DO NOT EDIT.")
-	if f.Proto.GetOptions().GetDeprecated() {
-		g.P("// ", f.Desc.Path(), " is a deprecated file.")
-	} else {
-		g.P("// source: ", f.Desc.Path())
-	}
-	g.P()
-
+	genGeneratedHeader(gen, g, f)
 	genStandaloneComments(g, f, fieldnum.FileDescriptorProto_Package)
-
 	g.P("package ", f.GoPackageName)
 	g.P()
 
 	// Emit a static check that enforces a minimum version of the proto package.
-	g.P("const (")
-	g.P("// Verify that runtime/protoimpl is sufficiently up-to-date.")
-	g.P("_ = ", protoimplPackage.Ident("EnforceVersion"), "(", protoimplPackage.Ident("MaxVersion"), " - ", protoimpl.Version, ")")
-	g.P("// Verify that this generated code is sufficiently up-to-date.")
-	g.P("_ = ", protoimplPackage.Ident("EnforceVersion"), "(", protoimpl.Version, " - ", protoimplPackage.Ident("MinVersion"), ")")
-	g.P(")")
-	g.P()
+	if GenerateVersionMarkers {
+		g.P("const (")
+		g.P("// Verify that this generated code is sufficiently up-to-date.")
+		g.P("_ = ", protoimplPackage.Ident("EnforceVersion"), "(", protoimpl.GenVersion, " - ", protoimplPackage.Ident("MinVersion"), ")")
+		g.P("// Verify that runtime/protoimpl is sufficiently up-to-date.")
+		g.P("_ = ", protoimplPackage.Ident("EnforceVersion"), "(", protoimplPackage.Ident("MaxVersion"), " - ", protoimpl.GenVersion, ")")
+		g.P(")")
+		g.P()
+	}
 
 	for i, imps := 0, f.Desc.Imports(); i < imps.Len(); i++ {
 		genImport(gen, g, f, imps.Get(i))
@@ -209,6 +206,33 @@
 	}
 }
 
+func genGeneratedHeader(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo) {
+	g.P("// Code generated by protoc-gen-go. DO NOT EDIT.")
+
+	if GenerateVersionMarkers {
+		g.P("// versions:")
+		protocGenGoVersion := protoimpl.VersionString()
+		protocVersion := "(unknown)"
+		if v := gen.Request.GetCompilerVersion(); v != nil {
+			protocVersion = fmt.Sprintf("v%v.%v.%v", v.GetMajor(), v.GetMinor(), v.GetPatch())
+		}
+		goVersion := runtime.Version()
+		if strings.HasPrefix(goVersion, "go") {
+			goVersion = "v" + goVersion[len("go"):]
+		}
+		g.P("// \tprotoc-gen-go ", protocGenGoVersion)
+		g.P("// \tprotoc        ", protocVersion)
+		g.P("// \tgo            ", goVersion)
+	}
+
+	if f.Proto.GetOptions().GetDeprecated() {
+		g.P("// ", f.Desc.Path(), " is a deprecated file.")
+	} else {
+		g.P("// source: ", f.Desc.Path())
+	}
+	g.P()
+}
+
 func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp protoreflect.FileImport) {
 	impFile, ok := gen.FileByName(imp.Path())
 	if !ok {
diff --git a/cmd/protoc-gen-go/main.go b/cmd/protoc-gen-go/main.go
index 53770da..e1dc52c 100644
--- a/cmd/protoc-gen-go/main.go
+++ b/cmd/protoc-gen-go/main.go
@@ -9,12 +9,21 @@
 import (
 	"errors"
 	"flag"
+	"fmt"
+	"os"
+	"path/filepath"
 
 	gengo "google.golang.org/protobuf/cmd/protoc-gen-go/internal_gengo"
 	"google.golang.org/protobuf/compiler/protogen"
+	"google.golang.org/protobuf/runtime/protoimpl"
 )
 
 func main() {
+	if len(os.Args) == 2 && os.Args[1] == "--version" {
+		fmt.Fprintf(os.Stderr, "%v %v\n", filepath.Base(os.Args[0]), protoimpl.VersionString())
+		os.Exit(1)
+	}
+
 	var (
 		flags        flag.FlagSet
 		plugins      = flags.String("plugins", "", "deprecated option")
diff --git a/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go b/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go
index 6e74944..85a1519 100644
--- a/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go
+++ b/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type AnnotationsTestEnum int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go.meta b/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go.meta
index b585b1e..81982ca 100644
--- a/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go.meta
+++ b/cmd/protoc-gen-go/testdata/annotations/annotations.pb.go.meta
@@ -1 +1 @@
-annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:750 end:769} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:786 end:833} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:2113 end:2135} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2259 end:2279} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:3173 end:3196}
\ No newline at end of file
+annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:501 end:520} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:537 end:584} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1864 end:1886} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2010 end:2030} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2924 end:2947}
\ No newline at end of file
diff --git a/cmd/protoc-gen-go/testdata/comments/comments.pb.go b/cmd/protoc-gen-go/testdata/comments/comments.pb.go
index 4d56cde..0dfc577 100644
--- a/cmd/protoc-gen-go/testdata/comments/comments.pb.go
+++ b/cmd/protoc-gen-go/testdata/comments/comments.pb.go
@@ -18,13 +18,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // COMMENT: Enum1.Leading
 type Enum1 int32
 
diff --git a/cmd/protoc-gen-go/testdata/comments/deprecated.pb.go b/cmd/protoc-gen-go/testdata/comments/deprecated.pb.go
index bd1b145..f63e7b6 100644
--- a/cmd/protoc-gen-go/testdata/comments/deprecated.pb.go
+++ b/cmd/protoc-gen-go/testdata/comments/deprecated.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // Deprecated: Do not use.
 type DeprecatedEnum int32
 
diff --git a/cmd/protoc-gen-go/testdata/extensions/base/base.pb.go b/cmd/protoc-gen-go/testdata/extensions/base/base.pb.go
index 7cf79a4..18ad84b 100644
--- a/cmd/protoc-gen-go/testdata/extensions/base/base.pb.go
+++ b/cmd/protoc-gen-go/testdata/extensions/base/base.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type BaseMessage struct {
 	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go b/cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go
index 68ae19a..3dc31cf 100644
--- a/cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go
+++ b/cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go
@@ -18,13 +18,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go b/cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go
index 6bf8a53..da2f966 100644
--- a/cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go
+++ b/cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ExtraMessage struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go b/cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go
index 8ecaea5..5edd050 100644
--- a/cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go
+++ b/cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go
@@ -17,13 +17,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go b/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
index c74fdb0..066f99a 100644
--- a/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
+++ b/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // Assorted edge cases in field name conflict resolution.
 //
 // Not all (or possibly any) of these behave in an easily-understood fashion.
diff --git a/cmd/protoc-gen-go/testdata/import_public/a.pb.go b/cmd/protoc-gen-go/testdata/import_public/a.pb.go
index 56614e1..52b6972 100644
--- a/cmd/protoc-gen-go/testdata/import_public/a.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/a.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // Symbols defined in public import of import_public/sub/a.proto.
 
 type E = sub.E
diff --git a/cmd/protoc-gen-go/testdata/import_public/b.pb.go b/cmd/protoc-gen-go/testdata/import_public/b.pb.go
index 8e527b0..bb8a260 100644
--- a/cmd/protoc-gen-go/testdata/import_public/b.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/b.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Local struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/import_public/c.pb.go b/cmd/protoc-gen-go/testdata/import_public/c.pb.go
index 764fef2..bfac017 100644
--- a/cmd/protoc-gen-go/testdata/import_public/c.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/c.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type UsingPublicImport struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go b/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
index 7172612..ce9598e 100644
--- a/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
@@ -18,13 +18,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // Symbols defined in public import of import_public/sub2/a.proto.
 
 type Sub2Message = sub2.Sub2Message
diff --git a/cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go b/cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go
index 98be29e..d94b0b6 100644
--- a/cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M2 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go b/cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go
index 59ad429..03ebff4 100644
--- a/cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Sub2Message struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go b/cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go
index 8191a3c..570622b 100644
--- a/cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go b/cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go
index 1ca2769..867868c 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type E1 int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go b/cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go
index e992506..3cbdd5b 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M2 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_a_2/m3.pb.go b/cmd/protoc-gen-go/testdata/imports/test_a_2/m3.pb.go
index 2c6503c..19d2fed 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_a_2/m3.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_a_2/m3.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M3 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_a_2/m4.pb.go b/cmd/protoc-gen-go/testdata/imports/test_a_2/m4.pb.go
index 8d38b39..0dc3610 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_a_2/m4.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_a_2/m4.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M4 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_b_1/m1.pb.go b/cmd/protoc-gen-go/testdata/imports/test_b_1/m1.pb.go
index 0683e4c..ea515d0 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_b_1/m1.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_b_1/m1.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_b_1/m2.pb.go b/cmd/protoc-gen-go/testdata/imports/test_b_1/m2.pb.go
index b7ddcdd..36cc242 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_b_1/m2.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_b_1/m2.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type M2 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_import_a1m1.pb.go b/cmd/protoc-gen-go/testdata/imports/test_import_a1m1.pb.go
index 7f77c2c..7e63f68 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_import_a1m1.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_import_a1m1.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type A1M1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_import_a1m2.pb.go b/cmd/protoc-gen-go/testdata/imports/test_import_a1m2.pb.go
index 1a20bd7..8abfcd5 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_import_a1m2.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_import_a1m2.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type A1M2 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/imports/test_import_all.pb.go b/cmd/protoc-gen-go/testdata/imports/test_import_all.pb.go
index b5ea0f0..57433ed 100644
--- a/cmd/protoc-gen-go/testdata/imports/test_import_all.pb.go
+++ b/cmd/protoc-gen-go/testdata/imports/test_import_all.pb.go
@@ -18,13 +18,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type All struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
index 05b1533..0f9f962 100644
--- a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
+++ b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
@@ -10,13 +10,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Foo struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go b/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go
index ecd22eb..ec9c6e2 100644
--- a/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go
+++ b/cmd/protoc-gen-go/testdata/nopackage/nopackage.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/proto2/enum.pb.go b/cmd/protoc-gen-go/testdata/proto2/enum.pb.go
index ca8bddd..454f8c4 100644
--- a/cmd/protoc-gen-go/testdata/proto2/enum.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto2/enum.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // EnumType1 comment.
 type EnumType1 int32
 
diff --git a/cmd/protoc-gen-go/testdata/proto2/fields.pb.go b/cmd/protoc-gen-go/testdata/proto2/fields.pb.go
index 74360d3..58d4925 100644
--- a/cmd/protoc-gen-go/testdata/proto2/fields.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto2/fields.pb.go
@@ -16,13 +16,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type FieldTestMessage_Enum int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go b/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go
index 259c22e..db41504 100644
--- a/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto2/nested_messages.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Layer1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go b/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
index 3dcfe40..20b06f1 100644
--- a/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto2/proto2.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/cmd/protoc-gen-go/testdata/proto3/enum.pb.go b/cmd/protoc-gen-go/testdata/proto3/enum.pb.go
index c7d264e..aab7bb4 100644
--- a/cmd/protoc-gen-go/testdata/proto3/enum.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto3/enum.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum int32
 
 const (
diff --git a/cmd/protoc-gen-go/testdata/proto3/fields.pb.go b/cmd/protoc-gen-go/testdata/proto3/fields.pb.go
index 6b0ae36..3553582 100644
--- a/cmd/protoc-gen-go/testdata/proto3/fields.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto3/fields.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type FieldTestMessage_Enum int32
 
 const (
diff --git a/encoding/testprotos/pb2/test.pb.go b/encoding/testprotos/pb2/test.pb.go
index 9b527fd..a0ad1e2 100644
--- a/encoding/testprotos/pb2/test.pb.go
+++ b/encoding/testprotos/pb2/test.pb.go
@@ -25,13 +25,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum int32
 
 const (
diff --git a/encoding/testprotos/pb3/test.pb.go b/encoding/testprotos/pb3/test.pb.go
index 049a051..44e9292 100644
--- a/encoding/testprotos/pb3/test.pb.go
+++ b/encoding/testprotos/pb3/test.pb.go
@@ -17,13 +17,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum int32
 
 const (
diff --git a/internal/cmd/generate-protos/main.go b/internal/cmd/generate-protos/main.go
index ddfac15..734aa26 100644
--- a/internal/cmd/generate-protos/main.go
+++ b/internal/cmd/generate-protos/main.go
@@ -53,6 +53,7 @@
 					if file.Generate {
 						switch plugin {
 						case "go":
+							gengo.GenerateVersionMarkers = false
 							gengo.GenerateFile(gen, file)
 							generateFieldNumbers(gen, file)
 						case "gogrpc":
diff --git a/internal/testprotos/benchmarks/benchmarks.pb.go b/internal/testprotos/benchmarks/benchmarks.pb.go
index 97dff4d..c07f40a 100644
--- a/internal/testprotos/benchmarks/benchmarks.pb.go
+++ b/internal/testprotos/benchmarks/benchmarks.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type BenchmarkDataset struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.go b/internal/testprotos/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.go
index 13c237a..f641592 100644
--- a/internal/testprotos/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.go
@@ -12,13 +12,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type GoogleMessage1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.go b/internal/testprotos/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.go
index 9e3f3c5..d7f93ca 100644
--- a/internal/testprotos/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.go
@@ -12,13 +12,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type GoogleMessage1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message2/benchmark_message2.pb.go b/internal/testprotos/benchmarks/datasets/google_message2/benchmark_message2.pb.go
index 2423705..fbc6fc3 100644
--- a/internal/testprotos/benchmarks/datasets/google_message2/benchmark_message2.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message2/benchmark_message2.pb.go
@@ -12,13 +12,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type GoogleMessage2 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3.pb.go
index 8c0e4bb..cad680e 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type GoogleMessage3 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_1.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_1.pb.go
index 638b3f8..11a9f6e 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_1.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_1.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message34390 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_2.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_2.pb.go
index 2c9b224..ba58265 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_2.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_2.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message22853 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_3.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_3.pb.go
index 7e6639f..9bc9a05 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_3.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_3.pb.go
@@ -10,13 +10,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message35546 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_4.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_4.pb.go
index 7ed40ef..19354c8 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_4.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_4.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message24346 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_5.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_5.pb.go
index 6410504..d486bf2 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_5.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_5.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message24377 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_6.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_6.pb.go
index d9cbacf..4fb855f 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_6.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_6.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message10576 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_7.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_7.pb.go
index 45c13ed..6aaaa5f 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_7.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_7.pb.go
@@ -10,13 +10,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message11018 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_8.pb.go b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_8.pb.go
index aa09f27..320fbd1 100644
--- a/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_8.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message3/benchmark_message3_8.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum720 int32
 
 const (
diff --git a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4.pb.go b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4.pb.go
index 87bce1d..9406554 100644
--- a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type GoogleMessage4 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_1.pb.go b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_1.pb.go
index f20d7ab..7403ce2 100644
--- a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_1.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_1.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message2463 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_2.pb.go b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_2.pb.go
index 3ac63cb..d557ca2 100644
--- a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_2.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_2.pb.go
@@ -10,13 +10,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message12774 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_3.pb.go b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_3.pb.go
index 05c4de4..2d2e75f 100644
--- a/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_3.pb.go
+++ b/internal/testprotos/benchmarks/datasets/google_message4/benchmark_message4_3.pb.go
@@ -11,13 +11,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type UnusedEnum int32
 
 const (
diff --git a/internal/testprotos/conformance/conformance.pb.go b/internal/testprotos/conformance/conformance.pb.go
index a6defde..b1e4da8 100644
--- a/internal/testprotos/conformance/conformance.pb.go
+++ b/internal/testprotos/conformance/conformance.pb.go
@@ -41,13 +41,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type WireFormat int32
 
 const (
diff --git a/internal/testprotos/conformance/test_messages_proto2.pb.go b/internal/testprotos/conformance/test_messages_proto2.pb.go
index 9b6f78e..f8a233a 100644
--- a/internal/testprotos/conformance/test_messages_proto2.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto2.pb.go
@@ -47,13 +47,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ForeignEnumProto2 int32
 
 const (
diff --git a/internal/testprotos/conformance/test_messages_proto3.pb.go b/internal/testprotos/conformance/test_messages_proto3.pb.go
index 0e45cb4..c583158 100644
--- a/internal/testprotos/conformance/test_messages_proto3.pb.go
+++ b/internal/testprotos/conformance/test_messages_proto3.pb.go
@@ -54,13 +54,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ForeignEnum int32
 
 const (
diff --git a/internal/testprotos/irregular/test.pb.go b/internal/testprotos/irregular/test.pb.go
index a63ca77..31f1e11 100644
--- a/internal/testprotos/irregular/test.pb.go
+++ b/internal/testprotos/irregular/test.pb.go
@@ -18,13 +18,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Message struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/legacy/legacy.pb.go b/internal/testprotos/legacy/legacy.pb.go
index 3f8efea..db77985 100644
--- a/internal/testprotos/legacy/legacy.pb.go
+++ b/internal/testprotos/legacy/legacy.pb.go
@@ -26,13 +26,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Legacy struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/messageset/messagesetpb/message_set.pb.go b/internal/testprotos/messageset/messagesetpb/message_set.pb.go
index 4e3ea38..b2199ca 100644
--- a/internal/testprotos/messageset/messagesetpb/message_set.pb.go
+++ b/internal/testprotos/messageset/messagesetpb/message_set.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type MessageSet struct {
 	state           protoimpl.MessageState
 	sizeCache       protoimpl.SizeCache
diff --git a/internal/testprotos/messageset/msetextpb/msetextpb.pb.go b/internal/testprotos/messageset/msetextpb/msetextpb.pb.go
index be50f98..21715b0 100644
--- a/internal/testprotos/messageset/msetextpb/msetextpb.pb.go
+++ b/internal/testprotos/messageset/msetextpb/msetextpb.pb.go
@@ -16,13 +16,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Ext1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/test/ext.pb.go b/internal/testprotos/test/ext.pb.go
index 395ce91..bbb124a 100644
--- a/internal/testprotos/test/ext.pb.go
+++ b/internal/testprotos/test/ext.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 var file_test_ext_proto_extDescs = []protoiface.ExtensionDescV1{
 	{
 		ExtendedType:  (*TestAllExtensions)(nil),
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index 9f5b4cd..5e04009 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -16,13 +16,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ForeignEnum int32
 
 const (
diff --git a/internal/testprotos/test/test_import.pb.go b/internal/testprotos/test/test_import.pb.go
index 153681f..d1cdcb5 100644
--- a/internal/testprotos/test/test_import.pb.go
+++ b/internal/testprotos/test/test_import.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ImportEnum int32
 
 const (
diff --git a/internal/testprotos/test/test_public.pb.go b/internal/testprotos/test/test_public.pb.go
index 79eec41..f694f37 100644
--- a/internal/testprotos/test/test_public.pb.go
+++ b/internal/testprotos/test/test_public.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type PublicImportMessage struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/test/weak1/test_weak.pb.go b/internal/testprotos/test/weak1/test_weak.pb.go
index 07d4301..1f43692 100644
--- a/internal/testprotos/test/weak1/test_weak.pb.go
+++ b/internal/testprotos/test/weak1/test_weak.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type WeakImportMessage1 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/test/weak2/test_weak.pb.go b/internal/testprotos/test/weak2/test_weak.pb.go
index 6a23155..4105754 100644
--- a/internal/testprotos/test/weak2/test_weak.pb.go
+++ b/internal/testprotos/test/weak2/test_weak.pb.go
@@ -14,13 +14,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type WeakImportMessage2 struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
diff --git a/internal/testprotos/test3/test.pb.go b/internal/testprotos/test3/test.pb.go
index b5d340d..b52ebf0 100644
--- a/internal/testprotos/test3/test.pb.go
+++ b/internal/testprotos/test3/test.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ForeignEnum int32
 
 const (
diff --git a/internal/testprotos/test3/test_import.pb.go b/internal/testprotos/test3/test_import.pb.go
index cff01bb..3c24da6 100644
--- a/internal/testprotos/test3/test_import.pb.go
+++ b/internal/testprotos/test3/test_import.pb.go
@@ -15,13 +15,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type ImportEnum int32
 
 const (
diff --git a/reflect/protoregistry/testprotos/test.pb.go b/reflect/protoregistry/testprotos/test.pb.go
index e819612..8fa3cda 100644
--- a/reflect/protoregistry/testprotos/test.pb.go
+++ b/reflect/protoregistry/testprotos/test.pb.go
@@ -18,13 +18,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type Enum1 int32
 
 const (
diff --git a/runtime/protoimpl/impl.go b/runtime/protoimpl/impl.go
index 775f920..b419ff6 100644
--- a/runtime/protoimpl/impl.go
+++ b/runtime/protoimpl/impl.go
@@ -17,51 +17,10 @@
 	"google.golang.org/protobuf/internal/impl"
 )
 
-const (
-	// MaxVersion is the maximum supported version for generated .pb.go files;
-	// which is the current version of the package.
-	// This is incremented when the functionality of this package expands.
-	MaxVersion = 0
-
-	// MinVersion is the minimum supported version for generated .pb.go files.
-	// This is incremented when the runtime drops support for old code.
-	MinVersion = 0
-
-	// Version is the current minor version of the runtime.
-	Version = MaxVersion // v2.{Version}.x
-
-	// TODO: Encode a date instead of the minor version?
-)
-
 // UnsafeEnabled specifies whether package unsafe can be used.
 const UnsafeEnabled = impl.UnsafeEnabled
 
 type (
-	// EnforceVersion is used by code generated by protoc-gen-go
-	// to statically enforce minimum and maximum versions of this package.
-	// A compilation failure implies either that:
-	//	* the runtime package is too old and needs to be updated OR
-	//	* the generated code is too old and needs to be regenerated.
-	//
-	// The runtime package can be upgraded by running:
-	//	go get google.golang.org/protobuf
-	//
-	// The generated code can be regenerated by running:
-	//	protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
-	//
-	// Example usage by generated code:
-	//	const (
-	//		// Verify that runtime/protoimpl is sufficiently up-to-date.
-	//		_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion)
-	//		// Verify that this generated code is sufficiently up-to-date.
-	//		_ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
-	//	)
-	//
-	// The genVersion is the current version used to generated the code.
-	// This compile-time check relies on negative integer overflow of a uint
-	// being a compilation failure (guaranteed by the Go specification).
-	EnforceVersion uint
-
 	DescBuilder      = filedesc.Builder
 	TypeBuilder      = filetype.Builder
 	Pointer          = impl.Pointer
diff --git a/runtime/protoimpl/version.go b/runtime/protoimpl/version.go
new file mode 100644
index 0000000..e059004
--- /dev/null
+++ b/runtime/protoimpl/version.go
@@ -0,0 +1,125 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package protoimpl
+
+import (
+	"fmt"
+	"strings"
+)
+
+// These constants determine the current version of this module.
+//
+//
+// For our release process, we enforce the following rules:
+//	* Tagged releases use a tag that is identical to VersionString.
+//	* Tagged releases never reference a commit where the VersionString
+//	contains "devel".
+//	* The set of all commits in this repository where VersionString
+//	does not contain "devel" must have a unique VersionString.
+//
+//
+// Steps for tagging a new release:
+//	1. Create a new CL.
+//
+//	2. Update versionMinor, versionPatch, and/or versionPreRelease as necessary.
+//	versionPreRelease must not contain the string "devel".
+//
+//	3. Since the last released minor version, have there been any changes to
+//	generator that relies on new functionality in the runtime?
+//	If yes, then increment GenVersion.
+//
+//	4. Since the last released minor version, have there been any changes to
+//	the runtime that removes support for old .pb.go source code?
+//	If yes, then increment MinVersion.
+//
+//	5. Send out the CL for review and submit it.
+//	Note that the next CL in step 8 must be submitted after this CL
+//	without any other CLs in-between.
+//
+//	6. Tag a new version, where the tag is is the current VersionString.
+//
+//	7. Write release notes for all notable changes
+//	between this release and the last release.
+//
+//	8. Create a new CL.
+//
+//	9. Update versionPreRelease to include the string "devel".
+//	For example: "" -> "devel" or "rc.1" -> "rc.1.devel"
+//
+//	10. Send out the CL for review and submit it.
+const (
+	versionMajor      = 1
+	versionMinor      = 19
+	versionPatch      = 0
+	versionPreRelease = "devel"
+)
+
+// VersionString formats the version string for this module in semver format.
+//
+// Examples:
+//	v1.20.1
+//	v1.21.0-rc.1
+func VersionString() string {
+	v := fmt.Sprintf("v%d.%d.%d", versionMajor, versionMinor, versionPatch)
+	if versionPreRelease != "" {
+		v += "-" + versionPreRelease
+
+		// TODO: Add metadata about the commit or build hash.
+		// See https://golang.org/issue/29814
+		// See https://golang.org/issue/33533
+		var versionMetadata string
+		if strings.Contains(versionPreRelease, "devel") && versionMetadata != "" {
+			v += "+" + versionMetadata
+		}
+	}
+	return v
+}
+
+const (
+	// MaxVersion is the maximum supported version for generated .pb.go files.
+	// It is always the current version of the module.
+	MaxVersion = versionMinor
+
+	// GenVersion is the runtime version required by generated .pb.go files.
+	// This is incremented when generated code relies on new functionality
+	// in the runtime.
+	GenVersion = 19
+
+	// MinVersion is the minimum supported version for generated .pb.go files.
+	// This is incremented when the runtime drops support for old code.
+	MinVersion = 0
+)
+
+// EnforceVersion is used by code generated by protoc-gen-go
+// to statically enforce minimum and maximum versions of this package.
+// A compilation failure implies either that:
+//	* the runtime package is too old and needs to be updated OR
+//	* the generated code is too old and needs to be regenerated.
+//
+// The runtime package can be upgraded by running:
+//	go get google.golang.org/protobuf
+//
+// The generated code can be regenerated by running:
+//	protoc --go_out=${PROTOC_GEN_GO_ARGS} ${PROTO_FILES}
+//
+// Example usage by generated code:
+//	const (
+//		// Verify that this generated code is sufficiently up-to-date.
+//		_ = protoimpl.EnforceVersion(genVersion - protoimpl.MinVersion)
+//		// Verify that runtime/protoimpl is sufficiently up-to-date.
+//		_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - genVersion)
+//	)
+//
+// The genVersion is the current minor version used to generated the code.
+// This compile-time check relies on negative integer overflow of a uint
+// being a compilation failure (guaranteed by the Go specification).
+type EnforceVersion uint
+
+// This enforces the following invariant:
+//	MinVersion ≤ GenVersion ≤ MaxVersion
+const (
+	_ = EnforceVersion(GenVersion - MinVersion)
+	_ = EnforceVersion(MaxVersion - GenVersion)
+)
diff --git a/types/descriptorpb/descriptor.pb.go b/types/descriptorpb/descriptor.pb.go
index 3f23a30..d45ab2e 100644
--- a/types/descriptorpb/descriptor.pb.go
+++ b/types/descriptorpb/descriptor.pb.go
@@ -50,13 +50,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 type FieldDescriptorProto_Type int32
 
 const (
diff --git a/types/known/anypb/any.pb.go b/types/known/anypb/any.pb.go
index 96baf90..01982e3 100644
--- a/types/known/anypb/any.pb.go
+++ b/types/known/anypb/any.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // `Any` contains an arbitrary serialized protocol buffer message along with a
 // URL that describes the type of the serialized message.
 //
diff --git a/types/known/apipb/api.pb.go b/types/known/apipb/api.pb.go
index 2f6ebaa..14dbef4 100644
--- a/types/known/apipb/api.pb.go
+++ b/types/known/apipb/api.pb.go
@@ -42,13 +42,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // Api is a light-weight descriptor for an API Interface.
 //
 // Interfaces are also described as "protocol buffer services" in some contexts,
diff --git a/types/known/durationpb/duration.pb.go b/types/known/durationpb/duration.pb.go
index 0b4fc1d..9492b42 100644
--- a/types/known/durationpb/duration.pb.go
+++ b/types/known/durationpb/duration.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // A Duration represents a signed, fixed-length span of time represented
 // as a count of seconds and fractions of seconds at nanosecond
 // resolution. It is independent of any calendar and concepts like "day"
diff --git a/types/known/emptypb/empty.pb.go b/types/known/emptypb/empty.pb.go
index 3750763..163fa11 100644
--- a/types/known/emptypb/empty.pb.go
+++ b/types/known/emptypb/empty.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // A generic empty message that you can re-use to avoid defining duplicated
 // empty messages in your APIs. A typical example is to use it as the request
 // or the response type of an API method. For instance:
diff --git a/types/known/fieldmaskpb/field_mask.pb.go b/types/known/fieldmaskpb/field_mask.pb.go
index d403fa5..f88becb 100644
--- a/types/known/fieldmaskpb/field_mask.pb.go
+++ b/types/known/fieldmaskpb/field_mask.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // `FieldMask` represents a set of symbolic field paths, for example:
 //
 //     paths: "f.a"
diff --git a/types/known/sourcecontextpb/source_context.pb.go b/types/known/sourcecontextpb/source_context.pb.go
index f785b4d..7f0a94d 100644
--- a/types/known/sourcecontextpb/source_context.pb.go
+++ b/types/known/sourcecontextpb/source_context.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // `SourceContext` represents information about the source of a
 // protobuf element, like the file in which it is defined.
 type SourceContext struct {
diff --git a/types/known/structpb/struct.pb.go b/types/known/structpb/struct.pb.go
index 202fd80..2c881e4 100644
--- a/types/known/structpb/struct.pb.go
+++ b/types/known/structpb/struct.pb.go
@@ -41,13 +41,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // `NullValue` is a singleton enumeration to represent the null value for the
 // `Value` type union.
 //
diff --git a/types/known/timestamppb/timestamp.pb.go b/types/known/timestamppb/timestamp.pb.go
index b5116a9..fa32301 100644
--- a/types/known/timestamppb/timestamp.pb.go
+++ b/types/known/timestamppb/timestamp.pb.go
@@ -40,13 +40,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // A Timestamp represents a point in time independent of any time zone or local
 // calendar, encoded as a count of seconds and fractions of seconds at
 // nanosecond resolution. The count is relative to an epoch at UTC midnight on
diff --git a/types/known/typepb/type.pb.go b/types/known/typepb/type.pb.go
index 45fed0e..67282c6 100644
--- a/types/known/typepb/type.pb.go
+++ b/types/known/typepb/type.pb.go
@@ -43,13 +43,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // The syntax in which a protocol buffer element is defined.
 type Syntax int32
 
diff --git a/types/known/wrapperspb/wrappers.pb.go b/types/known/wrapperspb/wrappers.pb.go
index 0404f30..f3e7851 100644
--- a/types/known/wrapperspb/wrappers.pb.go
+++ b/types/known/wrapperspb/wrappers.pb.go
@@ -50,13 +50,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // Wrapper message for `double`.
 //
 // The JSON representation for `DoubleValue` is JSON number.
diff --git a/types/pluginpb/plugin.pb.go b/types/pluginpb/plugin.pb.go
index eddafb7..441437a 100644
--- a/types/pluginpb/plugin.pb.go
+++ b/types/pluginpb/plugin.pb.go
@@ -57,13 +57,6 @@
 	sync "sync"
 )
 
-const (
-	// Verify that runtime/protoimpl is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 0)
-	// Verify that this generated code is sufficiently up-to-date.
-	_ = protoimpl.EnforceVersion(0 - protoimpl.MinVersion)
-)
-
 // The version number of protocol compiler.
 type Version struct {
 	state         protoimpl.MessageState