all: implement support for proto3 optional semantics

In the upcoming 3.12.x release of protoc, the proto3 language will be
amended to support true presence for scalars. This CL adds support
to both the generator and runtime to support these semantics.

Newly added public API:
	protogen.Plugin.SupportedFeatures
	protoreflect.FieldDescriptor.HasPresence
	protoreflect.FieldDescriptor.HasOptionalKeyword
	protoreflect.OneofDescriptor.IsSynthetic

Change-Id: I7c86bf66d0ae56642109beb5f2132184593747ad
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/230698
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/impl/codec_message.go b/internal/impl/codec_message.go
index 5259f2f..29ed59b 100644
--- a/internal/impl/codec_message.go
+++ b/internal/impl/codec_message.go
@@ -63,7 +63,8 @@
 		fd := fields.Get(i)
 
 		fs := si.fieldsByNumber[fd.Number()]
-		if fd.ContainingOneof() != nil {
+		isOneof := fd.ContainingOneof() != nil && !fd.ContainingOneof().IsSynthetic()
+		if isOneof {
 			fs = si.oneofsByName[fd.ContainingOneof().Name()]
 		}
 		ft := fs.Type
@@ -77,7 +78,7 @@
 		var funcs pointerCoderFuncs
 		var childMessage *MessageInfo
 		switch {
-		case fd.ContainingOneof() != nil:
+		case isOneof:
 			fieldOffset = offsetOf(fs, mi.Exporter)
 		case fd.IsWeak():
 			fieldOffset = si.weakOffset
@@ -102,17 +103,16 @@
 			funcs:      funcs,
 			mi:         childMessage,
 			validation: newFieldValidationInfo(mi, si, fd, ft),
-			isPointer: (fd.Cardinality() == pref.Repeated ||
-				fd.Kind() == pref.MessageKind ||
-				fd.Kind() == pref.GroupKind ||
-				fd.Syntax() != pref.Proto3),
+			isPointer:  fd.Cardinality() == pref.Repeated || fd.HasPresence(),
 			isRequired: fd.Cardinality() == pref.Required,
 		}
 		mi.orderedCoderFields = append(mi.orderedCoderFields, cf)
 		mi.coderFields[cf.num] = cf
 	}
 	for i, oneofs := 0, mi.Desc.Oneofs(); i < oneofs.Len(); i++ {
-		mi.initOneofFieldCoders(oneofs.Get(i), si)
+		if od := oneofs.Get(i); !od.IsSynthetic() {
+			mi.initOneofFieldCoders(od, si)
+		}
 	}
 	if messageset.IsMessageSet(mi.Desc) {
 		if !mi.extensionOffset.IsValid() {