Skip to content

feat: full proto2 support and protoc 36.2 descriptor parity - #5

Merged
ZergsLaw merged 6 commits into
mainfrom
feat/proto2-support
Dec 4, 2026
Merged

ZergsLaw merged 6 commits into
mainfrom
feat/proto2-support

Conversation

@ZergsLaw

@ZergsLaw ZergsLaw commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Brings proto2 compilation, validation, custom option wire encoding, and SourceCodeInfo generation to full parity with protoc 36.2:

  1. Option field presence & packing follow-up (internal/linker/, internal/options/):
    • Builds on fix(options): encode option message fields like protoc #4 by moving fieldEncoding computation into ResolveFile after cross-file type resolution so imported enum fields (including leading-dot references like .pkg.Enum) and LSPSession.DidChange incremental re-links compute presence and packing accurately.
  2. Parser (parser/):
    • Supports proto2 group declarations inside message, extend (top-level and nested), and oneof, enforcing capitalized group names and [options] placement before {.
    • Enforces mandatory optional / required / repeated field labels in proto2 messages and extend blocks, and rejects labels inside oneof.
    • Parses bracketed type URLs ([type.googleapis.com/pkg.Msg]) and colon-less list fields in aggregate option values, preserves raw default literal spans/kinds, matches protoc synthetic proto3 optional oneof naming for leading underscores (_foo -> X_foo), and defers all symbol resolution to the linker.
  3. Linker & semantic validation (internal/linker/):
    • Resolves TYPE_GROUP fields and extensions to canonical .pkg.Scope.GroupName while preserving TYPE_GROUP and group lookup aliases.
    • Supports option message_set_wire_format = true and extensions ... to max (2147483647).
    • Validates default = ... values (disallowed on repeated/message/group, integer/uint bounds, bools, enum value membership), duplicate enum numbers without option allow_alias = true, [packed = true] on non-repeated or non-packable types, invalid map<K, V> key types, proto3 custom json_name collisions, and MessageSet constraints.
  4. Option wire encoding, descriptor serialization & SourceCodeInfo (internal/options/, internal/serialize/, internal/sourceinfo/):
    • Encodes TYPE_GROUP (StartGroup/EndGroup), MessageSet Item groups, expanded google.protobuf.Any option literals, and canonical IEEE-754 quiet NaN for nan/-nan.
    • Always emits FieldDescriptorProto.json_name even when empty (__ or [json_name = ""]), formats TYPE_FLOAT numeric defaults with 32-bit precision, and serializes EnumValueOptions.feature_support.
    • Produces protoc-identical SourceCodeInfo paths and spans for group fields/synthetic messages (including extend), nested extension option paths .(ext), and FeatureSet fields (features.*).
  5. Tests & upstream proto2 parity corpus (protoc/, bench/):
    • Adds protoc/proto2_parity_test.go and protoc/proto2_errors_test.go.
    • Pins protocolbuffers/protobuf at v36.2 (2c74169) via sparse-checkout in bench/run.sh, adds the 14-file proto2 corpus to bench/run.sh parity, builds fdsdiff with -tags protolegacy, and guards fdsdiff against typed-nil extension resolvers.

Verification

  • test -z "$(gofmt -l .)"
  • go vet ./... and (cd bench && go vet ./...)
  • golangci-lint run and (cd bench && golangci-lint run --config ../.golangci.yml) (0 issues)
  • GOOS=linux GOARCH=arm GOARM=7 go build ./... and (cd bench && go build ./...)
  • go test -race -count=1 ./...
  • bench/run.sh parity (wkt, proto2, compute, api-common, googleapis: all same as protoc)

@ZergsLaw
ZergsLaw force-pushed the feat/proto2-support branch from 1d07144 to 59e518a Compare December 3, 2026 20:40
@ZergsLaw
ZergsLaw merged commit b5e0791 into main Dec 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant