-
Notifications
You must be signed in to change notification settings - Fork 6k
SemanticsFlag/SemanticsAction cleanup (part 3)
#40567
Conversation
|
@yjbanov ? |
|
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. |
|
/cc @chunhtai @Hangyujin |
|
It looks like ci is failing, can you fix it? |
|
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. |
|
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();
^^^^^^ |
|
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 |
|
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. |
SemanticsFlag and SemanticsAction be an enum.SemanticsFlag/SemanticsAction enum migration (part 3)
|
I went ahead. This now is blocked by #40571 😀 |
|
I just rebased on top of master. Do you think I'm also using |
|
Looks like some checks are failing |
|
Hold on, testing here (I need a YouTube tutorial on how to debug the engine lol). But almost there. |
lib/ui/semantics.dart
Outdated
| /// The numerical value for this action. | ||
| /// | ||
| /// Each action has one bit set in this bit field. | ||
| final int value; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right! Makes sense.
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lib/ui/semantics.dart
Outdated
| /// 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]; |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
lib/ui/semantics.dart
Outdated
| /// 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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
|
I have a marriage now, I'll probably only finish this on the weekend. The test failing is |
|
One test fixed. The next step is this. Does anyone know what might be happening? Is there a way Tap seems correct, but action_id seems wrong, where is Update: that test seems to be 2 weeks old from @loic-sharma. Could you help me here? I have no idea what to do. |
tools/api_check/lib/apicheck.dart
Outdated
| 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) { |
There was a problem hiding this comment.
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:
- private _getFields method that takes a
Typeargument and getDartEnumFields passes in EnumDeclaration - getDartClassFields just checks
is ClassMember || is ClassDeclaration.
I am sure there are others...
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
Hm, somewhere this is still failing. I wonder if there is another place where we accidentally use |
|
Yeah, I think that is it: Things like this here are now doing the wrong thing because they use |
|
Ahhhhhhhh... We kind of opened a pandora box, each day something new appears lol I guess... hmm.. add |
|
What about user code that currently uses |
|
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. |
|
You could: a) add It's upto you if you're up for doing all that extra work :) |
|
Well, we came until here, we can get there (as long as your patience allows)... Hixie will get tired of pressing ignore tests. |
SemanticsFlag/SemanticsAction enum migration (part 3)SemanticsFlag/SemanticsAction cleanup (part 3)
|
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. |
|
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 Thanks for all the help! |
goderbauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
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. |
|
The bot went crazy. |
chunhtai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks, everybody for this long journey. Feel free to add the "autosubmit". |
`SemanticsFlag`/`SemanticsAction` cleanup (part 3)

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:
deserialize/indexAt/[]on them, migrate Flutter, convert to enum;