Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pigeon]: added generation of empty classes in dart #8337

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

feduke-nukem
Copy link

@feduke-nukem feduke-nukem commented Dec 21, 2024

  • Added generation of empty classes in dart
  • Removed generating data class in Kotlin if class has no fields

closes 160501

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

You'll need to run the generate command dart run tools/generate.dart in the pigeon root folder before I can review this pr.

Thanks for putting this together!

packages/pigeon/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

No real issues with the implementation here. Thanks for putting this together.

We will need an integration test for this though, you should be able to add it to the already existing 'event channel handles extended sealed classes' test in packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart

The new version needs to be added to the pubspec and generator_tools.dart files as well. I assume those changes got lost during a merge from main.

We should land this one before your other pr to avoid having to update it again.

@@ -6,6 +6,7 @@

* [swift] Adds support for platform checks of imports of ProxyApis.
* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* [dart] fixes [160501](https://github.com/flutter/flutter/issues/160501).
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be it's own version update 22.7.3

I think it should read Adds support for empty data classes
This shouldn't be added to dart if it isn't supported on all platforms also, so no [dart] needed

Copy link
Author

@feduke-nukem feduke-nukem Jan 15, 2025

Choose a reason for hiding this comment

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

Done

Also added generating @Suppress("UNUSED_PARAMETER") for fromList() method of empty classes (Kotlin) as tests were failing due to linter

However I am facing issues at some CI steps:

Infra Failure: Step('Run package tests.reset XCode') (canceled) (retcode: None)
Task timed out.

UPD: It worked

packages/pigeon/lib/kotlin_generator.dart Show resolved Hide resolved
feduke-nukem and others added 2 commits January 15, 2025 11:12
@@ -906,7 +906,8 @@ object SendClass : StreamEventsStreamHandler() {
DoubleEvent(3.14),
ObjectsEvent(true),
EnumEvent(EventEnum.FORTY_TWO),
ClassEvent(EventAllNullableTypes(aNullableInt = 0)))
ClassEvent(EventAllNullableTypes(aNullableInt = 0)),
EmptyEvent())
Copy link
Contributor

@tarrinneal tarrinneal Jan 15, 2025

Choose a reason for hiding this comment

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

I'm realizing we don't have tests for sealed classes that aren't used in event channels (and therefor not tested on all platforms). I think adding it to the AllTypes family of classes is probably a good idea. I can do that part, if it's not something you would be interested in.

Copy link
Author

@feduke-nukem feduke-nukem Jan 16, 2025

Choose a reason for hiding this comment

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

I can do that part, if it's not something you would be interested in.

Everything is fine, I am ready to do whatever is required.

But I should know exactly what is expected to be done?

Should I add new SealedAllTypes, SealedAllNullableTypes and SealedAllNullableTypesWithoutRecursion classes and create corresponding methods for testing like echoSomething or some new fields should be added to existing AllTypes classes to be able to reuse existing tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think just adding a Sealed class option to AllTypes and AllNullableTypes (and AllNullableTypesWithoutRecursion) should be sufficient. That's still a hefty change though as the methods that check for equality, and every test that creates one of those classes will need to be updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a different sub class as the default version of each class to get more coverage (including an empty class of course)

Copy link
Author

Choose a reason for hiding this comment

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

I think just adding a Sealed class option to AllTypes and AllNullableTypes (and AllNullableTypesWithoutRecursion) should be sufficient. That's still a hefty change though as the methods that check for equality, and every test that creates one of those classes will need to be updated.

So I need to add a single parent sealed class and make AllTypes, AllNullableTypes, AllNullableTypesWithoutRecursion it's subclasses plus additional empty subclass AllTypesEmpty.

Did I get it right?

Or each of the classes AllTypes, AllNullableTypes and AllNullableTypesWithoutRecursion should itself become sealed with one subclass actually filled with assosiated "types" and second empty without any fields?

Sorry for questioning a lot 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant add a field in the AllTypes class that is the sealed class.

And 100% no worries at all about asking questions, I'm just happy you're working on pigeon :)

I'm very happy to help/assist/answer in any way you need.

Copy link
Contributor

Choose a reason for hiding this comment

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

AllTypes(anInt, aString,..., aSealedClass)

Copy link
Author

@feduke-nukem feduke-nukem Jan 18, 2025

Choose a reason for hiding this comment

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

AllTypes(anInt, aString,..., aSealedClass)

Got it.

Last clarification before implementation.

Should aSealed class have subclasses containing basic types/structures like in event channel tests like: IntClass extends SealedClass, StringClass extends SealedClass, EmptyClass extends SealedClass etc? Or should it be like AllTypesSealedClass filled with copy/pasted properties from AllTypes (same for others AllTypes classes) to test proper serialization/deserialization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pigeon] Empty generated Dart classes aren't serializable
2 participants