Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

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 chunhtai requested review from chunhtai and hannah-hyj March 23, 2023 16:53
@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).

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

/// 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

@bernaferrari bernaferrari Mar 31, 2023

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.

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 2, 2023

One test fixed. The next step is this. Does anyone know what might be happening? Is there a way Dart_GetNativeIntegerArgument is getting the wrong value because it is used to class instead of enum?

Tap seems correct, but action_id seems wrong, where is Dart_GetNativeIntegerArgument called? This is getting hard for me.

../../flutter/shell/platform/embedder/tests/embedder_a11y_unittests.cc:241: Failure
Expected equality of these values:
  static_cast<int32_t>(flutter::SemanticsAction::kTap)
    Which is: 1
  action_id
    Which is: 0

image

Update: that test seems to be 2 weeks old from @loic-sharma. Could you help me here? I have no idea what to do.

final RegExp fieldExp = RegExp(r'_k(\w*)Index');
final List<String> fields = <String>[];
for (final CompilationUnitMember unitMember in result.unit.declarations) {
if (unitMember is EnumDeclaration && unitMember.name.lexeme == className) {
Copy link
Member

Choose a reason for hiding this comment

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

Is EnumDeclaration vs ClassDeclaration the only difference between getDartEnumFields and getDartClassFields ? If so we should find a bette way to avoid duplication here. Some ideas:

  1. private _getFields method that takes a Type argument and getDartEnumFields passes in EnumDeclaration
  2. getDartClassFields just checks is ClassMember || is ClassDeclaration.

I am sure there are others...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I'll fix this.

for (final CompilationUnitMember unitMember in result.unit.declarations) {
if (unitMember is ClassDeclaration && unitMember.name.lexeme == className) {
if ((unitMember is ClassDeclaration || unitMember is EnumDeclaration) && (unitMember as NamedCompilationUnitMember).name.lexeme == className) {
for (final ClassMember classMember in unitMember.members) {
Copy link
Member

@goderbauer goderbauer Apr 7, 2023

Choose a reason for hiding this comment

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

Looks like deduplicating this is not as easy as I thought as there is no common base class of ClassDeclaration and EnumDeclaration that defines the .members property here. We may have to come up with a different approach to de-duplicating this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for all the help!!! I just commited a replacement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it doesn't work now... lol

@goderbauer
Copy link
Member

Hm, somewhere this is still failing. I wonder if there is another place where we accidentally use index instead of value....

@goderbauer
Copy link
Member

Yeah, I think that is it: Things like this here

https://github.com/flutter/flutter/blob/73bd97852978a4778f51dae0c48bc0c08d674edb/packages/flutter/test/cupertino/button_test.dart#L291

are now doing the wrong thing because they use Enum.index instead of what we now call value. There may not be a good way to migrate this since I don't think we can override Enum.index.

@bernaferrari
Copy link
Contributor Author

Ahhhhhhhh... We kind of opened a pandora box, each day something new appears lol
I think I found a test that might fail (just commited), but that's a lot worse.

I guess... hmm.. add value to engine, replace index with value in Flutter and then make the migration?

@goderbauer
Copy link
Member

What about user code that currently uses .index? They will be broken in the worst possible way: everything still appears to be valid and compiles, but then it may fail in hard-to-debug ways at runtime. I am actually more leaning towards not doing this clean-up now.

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

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

@goderbauer goderbauer requested a review from chunhtai April 10, 2023 16:31
@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
@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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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

Development

Successfully merging this pull request may close these issues.

5 participants