Skip to content

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

Merged
mkustermann merged 8 commits into
masterfrom
create-signature
Jun 30, 2026
Merged

Use createMessage() of type GeneratedMessage Function() in Dart protoc compiler#1093
mkustermann merged 8 commits into
masterfrom
create-signature

Conversation

@mkustermann

@mkustermann mkustermann commented May 8, 2026

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.

This mirrors cl/923994549 & cl/940364489

@mkustermann mkustermann force-pushed the create-signature branch 2 times, most recently from 786ce2e to b9bf0fe Compare May 8, 2026 13:09

@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

If you have publishing permissions, you can use the links below to publish the changes after merging this PR.

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
@mkustermann

Copy link
Copy Markdown
Collaborator Author

@sigurdm The g3 change landed (with small update sent today). This is now mirroring those changes externally to avoid github<->g3 drift.

@mkustermann mkustermann merged commit 91efb90 into master Jun 30, 2026
18 checks passed
@mkustermann mkustermann deleted the create-signature branch June 30, 2026 19:10
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