Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #22923 - peterjoel:issue_8539_prefs_refactor, r=jdm
#8539 Config preferences backend restructure <!-- Please describe your changes on the following line: --> A procedural macro for generating static structures for use as the backend for config preferences, as well a mapping from string names to accessors. Preferences can be accessed and updated via a map-like interface with `String` keys, and now also via a convenience macro: `get_pref!(path.to.pref)`. Various `serde`-compatible field attributes are also supported, including renaming the string keys. This could be useful when changing the backend structure without breaking existing usages. I have added the choice to use `i64` as well as `f64` for storing numbers. As it turns out, none of the existing preferences used non-integer values. Setting a floating point value from a command-line argument requires a decimal point in order to parse correctly. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #8539 <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> ----- I have a few outstanding problems or questions: 1. I am unable to get rid of this warning: ``` warning: unnecessary path disambiguator --> components/config/prefs.rs:130:51 | 130 | accessor_type = crate::pref_util::Accessor::<Prefs, crate::pref_util::PrefValue>, | ^^ try removing `::` ``` See: https://stackoverflow.com/questions/54710797/how-to-disable-unnecessary-path-disambiguator-warning 2. Several of the preferences in use were not represented in `prefs.json`. Some of these may be in error, but it is hard to tell. For example `js.offthread_compilation.enabled` vs `js.ion.offthread_compilation.enabled` could be different preferences or could be intended to have the same value. 3. Previously, several pieces of code provided default values when accessing a preference that may not be present. For example: ```Rust let DBL_CLICK_TIMEOUT = Duration::from_millis( PREFS .get("dom.document.dblclick_timeout") .as_u64() .unwrap_or(300), ); ``` Fallback values don't really make sense now and I've added these defaults to `prefs.json`. Does this sound right? 4. I have kept `PrefValue::Missing`, though it doesn't seem very useful any more. An error might be more appropriate now for an incorrect preference key. I've kept this partly because [`webdriver_server` uses it](https://github.com/servo/servo/blob/master/components/webdriver_server/lib.rs#L224). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22923) <!-- Reviewable:end -->
- Loading branch information