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

SemanticsFlag/SemanticsAction cleanup (part 3) #40567

Merged
merged 4 commits into from Apr 10, 2023

Conversation

bernaferrari
Copy link
Contributor

These two classes should be an enum, because they work as enum, but they are older than the enhanced enum, so this wasn't possible before. Now it is.

This is kind of breaking because Flutter uses semanticsFlag.values.values, but I searched on code search and couldn't find a repo that uses that, so it seems really internal.
We could do in these ways:

  • Add deserialize/indexAt/[] on them, migrate Flutter, convert to enum;
  • Convert to enum and land the Flutter change at the same time (is this possible?);
  • Don't do anything, lol

@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Mar 23, 2023
@kevmoo
Copy link
Contributor

kevmoo commented Mar 23, 2023

@yjbanov ?

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Mar 23, 2023

Bot tagged as web because there are two SemanticsFlag, one on the web and one everywhere else. I don't know who is responsible, lol. This could fall under accessibility. But Greg likes to review my PRs, if he is on engine and Yegor doesn't fit, you could assign him.

Ps. I saw some tests are failing. I'm into it. Just figuring out how to get gclient sync to work, this is tricky.
Ps2. I'm really struggling to get things working.
Ps3. The issue is probably getDartClassFields returning invalid because it is an enum.

@loic-sharma
Copy link
Member

/cc @chunhtai @hangyujin

@chunhtai
Copy link
Contributor

It looks like ci is failing, can you fix it?

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Mar 23, 2023

Yes, but I need your help. Getting gsync to work is too much for me. Can you help in Discord? I don't know how to get api_check to appear.

@chunhtai
Copy link
Contributor

based on some of the error message, you may need to do a migration

Try correcting the name to the name of an existing getter, or defining a getter or field named 'values'.
      for (final SemanticsAction action in SemanticsAction.values.values)
                                                                  ^^^^^^
lib/src/semantics/semantics.dart:683:61: Error: The getter 'values' isn't defined for the class 'List<SemanticsFlag>'.
 - 'List' is from 'dart:core'.
 - 'SemanticsFlag' is from 'dart:ui'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'values'.
      for (final SemanticsFlag flag in SemanticsFlag.values.values)
                                                            ^^^^^^
lib/src/semantics/semantics.dart:2758:53: Error: The getter 'values' isn't defined for the class 'List<SemanticsFlag>'.
 - 'List' is from 'dart:core'.
 - 'SemanticsFlag' is from 'dart:ui'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'values'.
    final List<String> flags = SemanticsFlag.values.values.where((SemanticsFlag flag) => hasFlag(flag)).map((SemanticsFlag flag) => flag.toString().substring('SemanticsFlag.'.length)).toList();
                                                    ^^^^^^

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Mar 23, 2023

Do I make the migration in this PR? Or do I make one in Flutter and tie them together? I thought the error message was something else. This one is easy. I have it here: flutter/flutter#123329

@chunhtai
Copy link
Contributor

Unfortunately, this can't be migrate like this because engine and framework pr can't go in at the same time.

You would need to create an temporarily API so that engine and framework pr can go in separately.

@bernaferrari bernaferrari changed the title Make SemanticsFlag and SemanticsAction be an enum. SemanticsFlag/SemanticsAction migration to enum part 3 Mar 23, 2023
@bernaferrari bernaferrari changed the title SemanticsFlag/SemanticsAction migration to enum part 3 SemanticsFlag/SemanticsAction migration to enum (part 3) Mar 23, 2023
@bernaferrari bernaferrari changed the title SemanticsFlag/SemanticsAction migration to enum (part 3) SemanticsFlag/SemanticsAction enum migration (part 3) Mar 23, 2023
@bernaferrari bernaferrari changed the title SemanticsFlag/SemanticsAction enum migration (part 3) SemanticsFlag/SemanticsAction enum migration (part 3) Mar 23, 2023
@bernaferrari
Copy link
Contributor Author

bernaferrari commented Mar 23, 2023

I went ahead. This now is blocked by #40571 😀

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Mar 31, 2023

I just rebased on top of master.

Do you think SemanticsAction.deserialize(flag) is a good replacement for SemanticsAction.values[flag]? AndroidSemanticsAction used "deserialize", which was my inspiration.

I'm also using value as the value. field or something else would also be valid names (even action, flag or actionId could be good names! But value works for both, so the cognitive load might be lower. It also works as the individual unit of values).

@bernaferrari bernaferrari force-pushed the Semantics branch 2 times, most recently from 3e3b150 to a0f91a0 Compare March 31, 2023 16:50
@goderbauer
Copy link
Member

Looks like some checks are failing

@bernaferrari
Copy link
Contributor Author

Hold on, testing here (I need a YouTube tutorial on how to debug the engine lol). But almost there.

lib/ui/platform_dispatcher.dart Outdated Show resolved Hide resolved
/// The numerical value for this action.
///
/// Each action has one bit set in this bit field.
final int value;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a good reason to change the name of this property from index to value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

enum has its own index (https://api.dart.dev/stable/2.19.4/dart-core/Enum/index.html), so you can't have two index with the same name. They are kind of similar, but the original index is 1 << index (so 2^index), and the "new index" matches the list position.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right! Makes sense.

lib/ui/semantics.dart Outdated Show resolved Hide resolved
lib/ui/semantics.dart Outdated Show resolved Hide resolved
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

/// Creates a new [SemanticsAction] from an integer `value`.
///
/// Returns `null` if the id is not a known action.
static SemanticsAction? fromValue(int value) => _kActionById[value];
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not super familiar with this but could this just be SemanticsAction(value)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, from [] maybe. Could be potentially confusing, but I need to check.

/// Creates a new [SemanticsFlag] from an integer `value`.
///
/// Returns `null` if the id is not a known action.
static SemanticsFlag? fromValue(int value) => _kFlagById[value];
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

@bernaferrari
Copy link
Contributor Author

I have a marriage now, I'll probably only finish this on the weekend.

The test failing is SemanticsFlag enums match, probably getDartClassFields doesn't know how to get an enum, that's my guess. If you want to help, feel free, else I'll take a look later. Engine Ninja took 17min to compile here, hopefully that's it.

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Apr 7, 2023

I agree. But...are there users using SemanticsAction? I searched code search and found a single usage, which the person copied Flutter bindings for Go. I doesn't seem to have that big of a user-base. But we could deprecate index, move to value, then migrate, or just don't do it. 99% of the (few) users use SemanticsAction.tap, not SemanticsAction.tap.index.

We could make half migration, deprecate index, move to value, then in a few months/years remove the value and put the enum in place without anyone seeing.

@goderbauer
Copy link
Member

You could:

a) add value to the SemanticsAction class (not the enum)
b) migrate the framework
c) remove index from the SemanticsAction class and see if any of our customer tests (or google testing) break. If nothing breaks, we can continue with this migration and change the class to an enum. If things break, we may have to undo all that.

It's upto you if you're up for doing all that extra work :)

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Apr 7, 2023

Well, we came until here, we can get there (as long as your patience allows)... value is 1 LOC. Let's try and see.

Hixie will get tired of pressing ignore tests.

@bernaferrari bernaferrari changed the title SemanticsFlag/SemanticsAction enum migration (part 3) SemanticsFlag/SemanticsAction cleanup (part 3) Apr 8, 2023
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Apr 8, 2023

After a lot of discussion and nice ideas, this will be the end result. It is not an enum, and might probably never be, but it is almost there.

Do you prefer from, actionAt, fromAction, fromIndex or deserialize for the => values[index] getter? Somewhere else in Flutter uses deserialize, but I don't like. from or fromAction sounds better because SemanticsAction.fromAction(action) is more readable than SemanticsAction.fromIndex(action). But anything is fine.

Thanks for all the help!

lib/ui/semantics.dart Outdated Show resolved Hide resolved
lib/ui/semantics.dart Outdated Show resolved Hide resolved
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #40567 at sha eb423ae

@bernaferrari
Copy link
Contributor Author

The bot went crazy.

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@bernaferrari
Copy link
Contributor Author

Thanks, everybody for this long journey. Feel free to add the "autosubmit".

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 10, 2023
@auto-submit auto-submit bot merged commit 3b8f922 into flutter:main Apr 10, 2023
35 checks passed
@bernaferrari bernaferrari deleted the Semantics branch April 10, 2023 22:32
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 10, 2023
zhongwuzw pushed a commit to zhongwuzw/engine that referenced this pull request Apr 14, 2023
`SemanticsFlag`/`SemanticsAction` cleanup (part 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App needs tests platform-web Code specifically for the web engine will affect goldens
Projects
None yet
5 participants