[webkit-changes] [WebKit/WebKit] 80b7b8: Check feature flag default values at compile time

Elliott Williams noreply at github.com
Mon Oct 30 18:51:58 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 80b7b85c4493d6cdc616efd9b10e2ba1914a0b17
      https://github.com/WebKit/WebKit/commit/80b7b85c4493d6cdc616efd9b10e2ba1914a0b17
  Author: Elliott Williams <emw at apple.com>
  Date:   2023-10-30 (Mon, 30 Oct 2023)

  Changed paths:
    M Source/WTF/Scripts/GeneratePreferences.rb
    M Source/WTF/wtf/PlatformEnable.h
    M Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb
    M Source/WebKit/UIProcess/API/APIFeature.cpp
    M Source/WebKit/UIProcess/API/APIFeature.h
    M Source/WebKit/UIProcess/API/APIFeatureStatus.h

  Log Message:
  -----------
  Check feature flag default values at compile time
https://bugs.webkit.org/show_bug.cgi?id=258041
rdar://104759188

Reviewed by Darin Adler.

Feature flags which have a constant default value (true or false, not
determined at runtime) can be checked statically to ensure that their
default value corresponds with their feature status's implied default.

First, the preferences generator emits a std::bool_constant for boolean
literals when generating WebKit's feature default values. It also emits
the feature's status as a constant type.

Then, a new template overload to APIFeature::create() accepts a feature
status constant and a std::bool_constant default value, and
static-asserts that the default values match.

Assertion failures contain a template instation note, so it's easy to
see which feature caused the failure:

    In file included from /Volumes/Data/OpenSource/WebKitBuild/Debug/DerivedSources/WebKit/WebPreferencesFeatures.cpp:29:
    In file included from /Volumes/Data/OpenSource/Source/WebKit/UIProcess/WebPreferences.h:28:
    /Volumes/Data/OpenSource/Source/WebKit/UIProcess/API/APIFeature.h:48:13: error: static assertion failed due to requirement '!defaultValue': Feature's status implies it should be off by default
                static_assert(!defaultValue, "Feature's status implies it should be off by default");
                ^             ~~~~~~~~~~~~~
    /Volumes/Data/OpenSource/WebKitBuild/Debug/DerivedSources/WebKit/WebPreferencesFeatures.cpp:688:23: note: in instantiation of function template specialization 'API::Feature::create<API::FeatureStatus::Developer, true>' requested here
            API::Feature::create("Prefer Page Rendering Updates near 60fps"""_s, "PreferPageRenderingUpdatesNear60FPSEnabled"_s, API::FeatureConstant<API::FeatureStatus::Developer>{}, API::FeatureCategory::DOM, "Prefer page rendering updates near 60 frames per second rather than using the display's refresh rate"""_s, DEFAULT_VALUE_FOR_PreferPageRenderingUpdatesNear60FPSEnabled, false),
                          ^
    1 error generated.

This mechanism is controlled by a ENABLE(FEATURE_DEFAULT_VALIDATION)
flag, which is currently only enabled on PLATFORM(MAC).

* Source/WTF/Scripts/GeneratePreferences.rb:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: Change the
  status of two features whose defaults are not aligned:
  - PreferPageRenderingUpdatesNear60FPSEnabled, developer -> stable:
    It's on by default everywhere except visionOS.
  - MediaSourceInlinePaintingEnabled, unstable -> stable: It's on for
    all Apple platforms since last year.
* Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb:
* Source/WebKit/UIProcess/API/APIFeature.cpp:
(API::Feature::uncheckedCreate):
(API::Feature::create): Deleted.
* Source/WebKit/UIProcess/API/APIFeature.h:
* Source/WebKit/UIProcess/API/APIFeatureStatus.h:
(API::defaultValueForFeatureStatus):

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




More information about the webkit-changes mailing list