Skip to content

[pigeon] Implements primitive enums for arguments to HostApis - #1871

Merged
fluttergithubbot merged 15 commits into
flutter:mainfrom
gaaclarke:primitive-enum
May 27, 2022
Merged

fluttergithubbot merged 15 commits into
flutter:mainfrom
gaaclarke:primitive-enum

Conversation

@gaaclarke

@gaaclarke gaaclarke commented May 10, 2022 •

Copy link
Copy Markdown
Member

issue: flutter/flutter#87307

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

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

@gaaclarke gaaclarke changed the title Implements primitive enums for arguments to HostApis [pigeon] Implements primitive enums for arguments to HostApis May 10, 2022
@gaaclarke
gaaclarke marked this pull request as ready for review May 10, 2022 21:24
@gaaclarke
gaaclarke requested a review from stuartmorgan-g May 10, 2022 21:24
Comment thread packages/pigeon/lib/dart_generator.dart Outdated

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.

Should this be called argValues or argValueExpressions or something like that? foo.index isn't the name of an argument.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, argExpressions

Comment thread packages/pigeon/lib/java_generator.dart Outdated

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.

Needs a declaration comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread packages/pigeon/lib/objc_generator.dart Outdated

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.

Doesn't an enum need to be wrapped in an NSNumber so that it can be nullable, like other primitives? (And shouldn't that logic be in _objcTypeForDartType?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We are blocking nullable enums for now so it isn't necessary. When we support nullable enums that would be a good way to implement them.

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.

Sorry, I hadn't fully paged this back in when I re-reviewed. Even though you aren't supporting nullable enums now, we will want to add that support soon (since it's a weird gap), so it should be an NSNumber now otherwise it will be a breaking change to add nullable support.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was thinking I'd use nullable NSNumber* for nullable enums and the primitive type for non-null enums. That way the usage is cleaner, safer and it matches the behavior we have for enums in class fields. I don't think nullable enums are that high priority anyways since the null value can easily be represented with an enum field. That would be preferable to losing the type safety of dealing directly with enums versus introducing nsnumbers.

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.

I didn't realize that's what we were doing for enum class fields, I thought they were boxed as well. The inconsistency with other primitive types, which we box regardless of whether or not they are nullable, seems odd, but it sounds like that ship has already sailed. Maybe at some point we can do a breaking change to better unify handling if we start doing switching on enums.

Comment thread packages/pigeon/lib/objc_generator.dart Outdated

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.

Unless I'm misunderstanding the code this generates, this would convert a null value from dart to whatever enum value zero is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yep, but we are blocking nullable enums right now.

Comment thread packages/pigeon/lib/objc_generator.dart Outdated

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.

I guess this answers some of my questions above. But couldn't we just support it instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm just cutting off scope to what I need for now. I don't have a lot of time to open this up.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@gaaclarke
gaaclarke requested a review from stuartmorgan-g May 27, 2022 16:59
@gaaclarke

Copy link
Copy Markdown
Member Author

@stuartmorgan a few of your comments are good points but I'm pretty sure they are relevant only if we support nullable enum arguments which I didn't do here. PTAL.

Comment thread packages/pigeon/lib/objc_generator.dart Outdated

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.

Comment thread packages/pigeon/lib/pigeon_lib.dart Outdated

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.

You'll need to block this in the C++ generator as part of this PR, now that C++ has landed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

@gaaclarke
gaaclarke requested a review from stuartmorgan-g May 27, 2022 18:02
Comment thread packages/pigeon/lib/cpp_generator.dart Outdated
// TODO(gaaclarke): Add line number and filename.
result.add(Error(
message:
'Nullable enum types aren\'t support in C++ arguments in method:${api.name}.${method.name} argument:(${arg.type.baseName} ${arg.name}).'));

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.

Typo: supported

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Comment thread packages/pigeon/lib/objc_generator.dart Outdated

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.

Sorry, I hadn't fully paged this back in when I re-reviewed. Even though you aren't supporting nullable enums now, we will want to add that support soon (since it's a weird gap), so it should be an NSNumber now otherwise it will be a breaking change to add nullable support.

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.

3 participants