Skip to content

Make preference system more robust#314

Merged
Loirooriol merged 1 commit intoservo:mainfrom
Loirooriol:robust-prefs
Mar 3, 2026
Merged

Make preference system more robust#314
Loirooriol merged 1 commit intoservo:mainfrom
Loirooriol:robust-prefs

Conversation

@Loirooriol
Copy link
Copy Markdown
Collaborator

@Loirooriol Loirooriol commented Feb 21, 2026

This makes the stylo_static_prefs crate more robust. In particular, the set_bool() and set_i32() functions are removed, in favor of a new set_pref!() macro. This macro ensures (at compile time) that the preference being set actually exists, and that the provided value has the correct type.

That will be useful for embedders of Stylo, since they will now detect accidental typos, or if e.g. a Stylo upgrade renamed or removed a pref that they are setting. This is not hypothetical: both Servo and Blitz are currently setting 2 preferences which no longer exist.

For consistency, this removes get_bool() and get_i32() too, in favor of the pref!() macro. And default_value!() no longer defaults to false, in order to be able to tell whether the preference exists.

It's still possible to get or set preferences without using the macros, by using the Preference trait (renamed from Getter, since now it can also set). But it's discouraged.

Servo PR: servo/servo#42741

This makes the `stylo_static_prefs` crate more robust. In particular,
the `set_bool()` and `set_i32()` functions are removed, in favor of a
new `set_pref!()` macro. This macro ensures (at compile time) that the
preference being set actually exists, and that the provided value has
the correct type.

That will be useful for embedders of Stylo, since they will now detect
accidental typos, or if e.g. a Stylo upgrade renamed or removed a pref
that they are setting. This is not hypothetical: both Servo and Blitz
are currently setting 2 preferences which no longer exist.

For consistency, this removes `get_bool()` and `get_i32()` too, in favor
of the `pref!()` macro. And `default_value!()` no longer defaults to
false, in order to be able to tell whether the preference exists.

It's still possible to get or set preferences without using the macros,
by using the `Preference` trait (renamed from `Getter`, since now it can
also set). But it's discouraged.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
@Loirooriol Loirooriol marked this pull request as ready for review February 21, 2026 21:40
@Loirooriol Loirooriol added this pull request to the merge queue Mar 3, 2026
Merged via the queue into servo:main with commit 9b63562 Mar 3, 2026
5 checks passed
@Loirooriol Loirooriol deleted the robust-prefs branch March 3, 2026 17:08
github-merge-queue Bot pushed a commit to servo/servo that referenced this pull request Mar 3, 2026
Bumps Stylo to servo/stylo#314

In particular, we would now get a compile error because we were setting
`layout.flexbox.enabled` and `layout.css.transition-behavior.enabled`,
even if Stylo removed at some point. So stop setting them.

Testing: Not needed, no behavior change

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
minghuaw pushed a commit to minghuaw/stylo that referenced this pull request Mar 5, 2026
This makes the `stylo_static_prefs` crate more robust. In particular,
the `set_bool()` and `set_i32()` functions are removed, in favor of a
new `set_pref!()` macro. This macro ensures (at compile time) that the
preference being set actually exists, and that the provided value has
the correct type.

That will be useful for embedders of Stylo, since they will now detect
accidental typos, or if e.g. a Stylo upgrade renamed or removed a pref
that they are setting. This is not hypothetical: both Servo and Blitz
are currently setting 2 preferences which no longer exist.

For consistency, this removes `get_bool()` and `get_i32()` too, in favor
of the `pref!()` macro. And `default_value!()` no longer defaults to
false, in order to be able to tell whether the preference exists.

It's still possible to get or set preferences without using the macros,
by using the `Preference` trait (renamed from `Getter`, since now it can
also set). But it's discouraged.

Servo PR: servo/servo#42741

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Loirooriol added a commit that referenced this pull request Mar 5, 2026
This makes the `stylo_static_prefs` crate more robust. In particular,
the `set_bool()` and `set_i32()` functions are removed, in favor of a
new `set_pref!()` macro. This macro ensures (at compile time) that the
preference being set actually exists, and that the provided value has
the correct type.

That will be useful for embedders of Stylo, since they will now detect
accidental typos, or if e.g. a Stylo upgrade renamed or removed a pref
that they are setting. This is not hypothetical: both Servo and Blitz
are currently setting 2 preferences which no longer exist.

For consistency, this removes `get_bool()` and `get_i32()` too, in favor
of the `pref!()` macro. And `default_value!()` no longer defaults to
false, in order to be able to tell whether the preference exists.

It's still possible to get or set preferences without using the macros,
by using the `Preference` trait (renamed from `Getter`, since now it can
also set). But it's discouraged.

Servo PR: servo/servo#42741

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Mar 6, 2026
…reviewers,dshin

This imports:
- Allow the embedder to override all preferences
  servo/stylo#309
- Make preference system more robust
  servo/stylo#314

Differential Revision: https://phabricator.services.mozilla.com/D286392
github-actions Bot pushed a commit that referenced this pull request Mar 7, 2026
…reviewers,dshin

This imports:
- Allow the embedder to override all preferences
  #309
- Make preference system more robust
  #314

Differential Revision: https://phabricator.services.mozilla.com/D286392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants