mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-02-07 03:40:29 +00:00
afd3633ce3
Suppose some init logic performs protobuf reflection. If so, it will cause the table-driven logic for protobuf reflection to be initialized. This is problematic for weak fields since we can not be certain that all weak references have been registered at this point in time. This is a fundamental issue with with weak dependencies, since it means that we cannot enforce any ordering constraints on the weak dependency unless we directly import the weakly referenced package (which would defeat the point of weak imports). Alleviate the problem by pushing evaluation of weak reference to actual usage. This does not completely fix the problem, but signifcantly reduces the probability of it being problematic. In general, people should avoid interacting with weak fields at init time. Change-Id: Iebaefddde8cf07b5cd7dee49b7015b05b5428618 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/188980 Reviewed-by: Damien Neil <dneil@google.com>