Skip to content

Use createMessage() of type GeneratedMessage Function() in Dart protoc compiler#1093

Open
mkustermann wants to merge 11 commits into
masterfrom
create-signature
Open

Use createMessage() of type GeneratedMessage Function() in Dart protoc compiler#1093
mkustermann wants to merge 11 commits into
masterfrom
create-signature

Conversation

@mkustermann

Copy link
Copy Markdown
Collaborator

Often apps use extensive numbers of protos. The BuilderInfo of a proto will refer to sub proto messages via using Foo.create tear-offs.

Big apps can end up with tens of thousands of those <name>.create closures. All of them currently have a unique <name> Function() function type.

Though the actual usage of those closures is only in contexts where the caller of the closure expects a GeneratedMessage as return type. If a caller knew the actual return type, then the caller could call the constructor directly.

To avoid having to create potentially tens of thousands of unique function types, we make those closures have the
GeneratedMessage Function() type.

Often apps use extensive numbers of protos. The `BuilderInfo` of a proto
will refer to sub proto messages via using `Foo.create` tear-offs.

Big apps can end up with tens of thousands of those `<name>.create`
closures. All of them currently have a unique `<name> Function()`
function type.

Though the actual usage of those closures is only in contexts where the
caller of the closure expects a `GeneratedMessage` as return type. If a
caller knew the actual return type, then the caller could call the
constructor directly.

To avoid having to create potentially tens of thousands of unique
function types, we make those closures have the
`GeneratedMessage Function()` type.

@sigurdm sigurdm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

This is probably a breaking change though.

@mkustermann

Copy link
Copy Markdown
Collaborator Author

@sigurdm Do you know how I can fix the PR failures? I formatted locally before pushing, but it still seems fail. Maybe the bot uses a slightly different Dart SDK with slightly different analyzer infos?

@mkustermann

Copy link
Copy Markdown
Collaborator Author

This is probably a breaking change though.

I will try this in g3 before landing & measure impact on some apps before landing.

In reality I hope this doesn't break anyone as it'd be strange to use Foo.create() instead of just Foo() in user code.
How should we reflect this change in the version numbers?

@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown

Package publishing

Package Version Status Publish tag (post-merge)
package:protobuf 6.1.0 ready to publish protobuf-v6.1.0
package:protoc_plugin 25.1.0 ready to publish protoc_plugin-v25.1.0

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@sigurdm

sigurdm commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Yeah it would be strange, but people do the strangest things...

If we cannot find any breakages I'm ok with a minor release
@mosuem @jonasfj WDYT?

At least we should try see how this fares against google3.

The protoc_plugin pubspec should have its constraint on protobuf updated to require at least this new version.

@mkustermann

Copy link
Copy Markdown
Collaborator Author

/cc @rakudrama

@mkustermann mkustermann changed the title Make create() functions have GeneratedMessage Function() type Use createMessage() of type GeneratedMessage Function() in Dart protoc compiler May 21, 2026
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.

2 participants