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

AXNotification enum ought to be an X macro #25805

Conversation

rkirsling
Copy link
Member

@rkirsling rkirsling commented Mar 13, 2024

129ce14

AXNotification enum ought to be an X macro
https://bugs.webkit.org/show_bug.cgi?id=270893

Reviewed by Darin Adler.

AXNotification is a giant and frequently updated enum.
Every time it is updated, exhaustive switch statements must be updated accordingly.

This is a very appropriate place for an X macro --
selfishly, it will help PlayStation port avoid build breaks (since we handle this enum in WKAPICast),
but irrespective of platform, it also means that AXLogger won't need to be updated each time AXNotification is updated.

* Source/WebCore/accessibility/AXLogger.cpp:
(WebCore::operator<<):
* Source/WebCore/accessibility/AXObjectCache.h:

Canonical link: https://commits.webkit.org/276393@main

f65af2a

Misc iOS, tvOS & watchOS macOS Linux Windows
❌ πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ§ͺ wpe-wk2
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ api-wpe
  πŸ§ͺ ios-wk2-wpt βœ… πŸ§ͺ mac-wk1 βœ… πŸ›  wpe-skia
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  gtk
βœ… πŸ›  tv βœ… πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ§ͺ gtk-wk2
βœ… πŸ›  tv-sim βœ… πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch
βœ… πŸ›  watch-sim

@rkirsling rkirsling requested review from a team, cdumez and rniwa as code owners March 13, 2024 03:30
@rkirsling rkirsling self-assigned this Mar 13, 2024
@rkirsling rkirsling added the Accessibility For bugs related to accessibility. label Mar 13, 2024
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 13, 2024
@rkirsling rkirsling removed the merging-blocked Applied to prevent a change from being merged label Mar 13, 2024
@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from 78460d1 to 1ebd6fc Compare March 13, 2024 04:47
@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from 1ebd6fc to b0f75c2 Compare March 13, 2024 04:58
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 13, 2024
@rkirsling
Copy link
Member Author

Background: #23035 (comment)

Basically, it may or may not actually be beneficial for us to upstream our current AX impl, since it differs so much from other platforms, but if we could X-macro-ify AXNotification and AccessibilityRole, it would save us from a lot of build breaks. And since exhaustive switches exist upstream for each of these, it's not just PS that benefits.

@rkirsling rkirsling removed the merging-blocked Applied to prevent a change from being merged label Mar 13, 2024
@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from b0f75c2 to 4da9cac Compare March 13, 2024 05:28
@@ -139,6 +139,110 @@ class AccessibilityReplacedText {
VisiblePositionIndexRange m_replacedRange;
};

#define WEBCORE_AXNOTIFICATION_KEYS_DEFAULT(macro) \
macro(AccessKeyChanged) \
Copy link
Member

Choose a reason for hiding this comment

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

This looks strictly worse. I don't understand why we want to adopt this change.

Copy link
Member Author

@rkirsling rkirsling Mar 13, 2024

Choose a reason for hiding this comment

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

I linked the explanation above but I can link it again here: #23035 (comment)

Introducing WebKit/UIProcess/API/C/WKAXTypes.h with enums like...

enum AXNotification {
     // must be same as WebCore::AXObjectCache::AXNotification
     kWKAXAccessKeyChanged,
     ...
 };
 typedef uint32_t WKAXNotification;

...and extending WebKit/UIProcess/API/C/WKAPICast.h with casts like...

inline WKAXNotification toAPI(WebCore::AXObjectCache::AXNotification notification)
{
    switch (notification) {
    case WebCore::AXObjectCache::AXNotification::AXAccessKeyChanged:
        return kWKAXAccessKeyChanged;
    ...
    }
}

...feels rather hard to justify if only one platform is planning to use these casts.

Since the idea is just to ensure that the API casts get updated whenever the WebCore enums get updated, the ideal situation would be to have this happen automatically, without requiring developers to be conscious of it. This automation is achieved by X macros, which allow us to do an exhaustive switch on a enum without being concerned with the specific values of that enum changing. Indeed, forgetting about any platform-specific needs, in AXLogger, we're able to reduce a switch from 286 lines to just 8, and those 8 lines needn't be touched the next time AXNotification changes.

I understand that while this is commonplace in JSC (looks like we may have almost 200 of them), it surely feels quite foreign in WebCore. But I'm not sure of a different tool that fits this problem so well.

Copy link
Member Author

@rkirsling rkirsling Mar 18, 2024

@rkirsling rkirsling changed the title AXNotification ought to be an X-macroed enum class AXNotification enum ought to be a X macro Mar 19, 2024
@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from 4da9cac to 0bc8bf0 Compare March 19, 2024 05:57
@rkirsling
Copy link
Member Author

Per @darinadler's suggestion on Slack, I've removed the enum class change such that this patch is solely focused on making AXNotification an X macro. (I'm still happy to do the other part in a separate patch if desired.)

@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from 0bc8bf0 to bb5fd9b Compare March 19, 2024 06:04
stream << "AXTextCompositionEnded";
#define WEBCORE_LOG_AXNOTIFICATION(name) \
case AXObjectCache::AXNotification::name: \
stream << #name; \
Copy link
Member

Choose a reason for hiding this comment

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

If we put β€œAX” #name here then we could leave all the repeated AX out of the macro arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great idea!

AXDraggingEnteredDropZone,
AXDraggingDropped,
AXDraggingExitedDropZone
#define WEBCORE_DEFINE_AXNOTIFICATION_ENUM(name) name,
Copy link
Member

Choose a reason for hiding this comment

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

And here AX##name.

@rkirsling rkirsling changed the title AXNotification enum ought to be a X macro AXNotification enum ought to be an X macro Mar 19, 2024
@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from bb5fd9b to e9b308b Compare March 19, 2024 15:06
@rkirsling rkirsling added safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks merge-queue Applied to send a pull request to merge-queue labels Mar 19, 2024
@rkirsling rkirsling removed the merge-queue Applied to send a pull request to merge-queue label Mar 20, 2024
@rkirsling rkirsling force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from e9b308b to f65af2a Compare March 20, 2024 03:48
@rkirsling rkirsling added merge-queue Applied to send a pull request to merge-queue and removed safe-merge-queue Applied to automatically send a pull-request to merge-queue after passing EWS checks labels Mar 20, 2024
https://bugs.webkit.org/show_bug.cgi?id=270893

Reviewed by Darin Adler.

AXNotification is a giant and frequently updated enum.
Every time it is updated, exhaustive switch statements must be updated accordingly.

This is a very appropriate place for an X macro --
selfishly, it will help PlayStation port avoid build breaks (since we handle this enum in WKAPICast),
but irrespective of platform, it also means that AXLogger won't need to be updated each time AXNotification is updated.

* Source/WebCore/accessibility/AXLogger.cpp:
(WebCore::operator<<):
* Source/WebCore/accessibility/AXObjectCache.h:

Canonical link: https://commits.webkit.org/276393@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch from f65af2a to 129ce14 Compare March 20, 2024 07:41
@webkit-commit-queue
Copy link
Collaborator

Committed 276393@main (129ce14): https://commits.webkit.org/276393@main

Reviewed commits have been landed. Closing PR #25805 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Mar 20, 2024
@webkit-commit-queue webkit-commit-queue merged commit 129ce14 into WebKit:main Mar 20, 2024
@rkirsling rkirsling deleted the eng/AXNotification-ought-to-be-an-X-macroed-enum-class branch March 20, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accessibility For bugs related to accessibility.
Projects
None yet
6 participants