Skip to content

Conversation

@copybara-service
Copy link

Rename default instances.

This CL prepares upcoming changes to collocate message-globals under a single
wrapper (go/proto-msg-globals). The plan is to keep dual state guarded by
PROTOBUF_MESSAGE_GLOBALS, which allows smaller CLs and potential A/B experiments.

Exising code exposes a raw default instance to messages that contain the type
to support constinit or constexpr. Using T::default_instance() would encapsulate
#ifdef'ing but I didn't find a way to achieve that. (Also, constexpr doesn't allow
reinterpret_cast.)

This CL renames existing raw default instances so that both branches (#ifdef & #ifndef)
can refer to the same name.

// Before:
struct FooDefaultTypeInternal;
extern FooDefaultTypeInternal _Foo_default_instance_;
DoSomething(_Foo_default_instance_._instance);

// After
struct FooGlobalsTypeInternal;
extern FooGlobalsTypeInternal _Foo_globals_;
DoSomething(_Foo_globals_._default);

Note that this is meant to be name changes only.

@copybara-service copybara-service bot force-pushed the test_862956528 branch 3 times, most recently from 91093b2 to 172eafc Compare February 3, 2026 00:19
This CL prepares upcoming changes to collocate message-globals under a single
wrapper (go/proto-msg-globals). The plan is to keep dual state guarded by
PROTOBUF_MESSAGE_GLOBALS, which allows smaller CLs and potential A/B experiments.

Exising code exposes a raw default instance to messages that contain the type
to support constinit or constexpr. Using `T::default_instance()` would encapsulate
#ifdef'ing but I didn't find a way to achieve that. (Also, constexpr doesn't allow
reinterpret_cast.)

This CL renames existing raw default instances so that both branches (#ifdef & #ifndef)
can refer to the same name.

```
// Before:
struct FooDefaultTypeInternal;
extern FooDefaultTypeInternal _Foo_default_instance_;
DoSomething(_Foo_default_instance_._instance);

// After
struct FooGlobalsTypeInternal;
extern FooGlobalsTypeInternal _Foo_globals_;
DoSomething(_Foo_globals_._default);
```

Note that this is meant to be name changes only.

PiperOrigin-RevId: 864580684
@copybara-service copybara-service bot merged commit 33e255c into main Feb 3, 2026
@copybara-service copybara-service bot deleted the test_862956528 branch February 3, 2026 00:57
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