Skip to content

config: Improve API for DiagnosticsLogging configuration. - #44703

Merged
mukilan merged 1 commit into
servo:mainfrom
mukilan:improve-diagnostics-logging-api
May 8, 2026
Merged

config: Improve API for DiagnosticsLogging configuration.#44703
mukilan merged 1 commit into
servo:mainfrom
mukilan:improve-diagnostics-logging-api

Conversation

@mukilan

@mukilan mukilan commented May 4, 2026

Copy link
Copy Markdown
Member

The current extend_from_string API is not suitable for embedders as it was written specifically for servoshell and therefore makes a lot of assumptions - the binary name, the format and text of the help message, etc. It also exits the whole process after displaying the help string.

Change the behaviour of this API by making it responsible only for parsing string flags. The logic for formatting and displaying the help message is moved to servoshell. This patch also switches the DiagnosticsLogging from a struct to a BitArray and exposes strum-based APIs so that the embedder can enumerate the available diagnostics option, retrieve the documentation string associated with each option and also parse the strings back to a valid DiagnosticsLogging struct.

Testing: Includes a unit test for the API used by embedders.

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 4, 2026

@mrobinson mrobinson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good. My main concern is the addition of 5 new crate dependencies to the servo itself. Is it possible to avoid the dependency on bitvec somehow?

Comment thread components/config/opts.rs Outdated
Comment on lines +103 to +104
#[strum(to_string = "style-tree")]
#[strum(message = "Log the DOM after each restyle")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we should also include the rustdoc string so that these values also show up in the API documentation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I tried that as strum also allows programmatically retrieving a variant's documentation string, but that means we can't split the documentation as message and detailed_message. But perhaps detailed_message is not very useful as only two variants have that. I'll remove detailed_message and switch message to doc strings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've switched to doc comments in 5d4fc99.

Comment thread components/config/opts.rs Outdated
Comment thread components/config/opts.rs Outdated
Comment thread ports/servoshell/prefs.rs Outdated
Comment thread ports/servoshell/prefs.rs

if cli_options.contains(&"help".into()) {
// TODO: Remove hardcoded binary name by perhaps receiving this a an argument.
println!("Usage: servoshell -Z option,[option,...]\n\twhere options include:");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
println!("Usage: servoshell -Z option,[option,...]\n\twhere options include:");
println!(
"Usage: {} -Z option,[option,...]\n\twhere options include:"
env::args().first().unwrap_or_default()
);

Comment thread ports/servoshell/prefs.rs Outdated
}

if cli_options.contains(&"help".into()) {
// TODO: Remove hardcoded binary name by perhaps receiving this a an argument.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO: Remove hardcoded binary name by perhaps receiving this a an argument.
// TODO: Remove hardcoded binary name by perhaps receiving this as an argument.

Though maybe you could just do this with the code below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't want to do that because the grand parent in the call chain of this function is already doing the same work to split the args and explictly passing down the args without binary. We can just thread that through the call chain, but I haven't tested what the binary name would look like in Android or OHOS, so I decided to handle it separately.

@servo-highfive servo-highfive added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 5, 2026

@mukilan mukilan left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is it possible to avoid the dependency on bitvec somehow?

We could use a HashSet<DiagnosticLoggingOptions> instead if we are not concerned about space usage or the performance overhead during layout. Otherwise, I am not sure how to avoid the dependency without rolling our own BitArray like data structure.

Comment thread components/config/opts.rs Outdated
Comment on lines +103 to +104
#[strum(to_string = "style-tree")]
#[strum(message = "Log the DOM after each restyle")]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I tried that as strum also allows programmatically retrieving a variant's documentation string, but that means we can't split the documentation as message and detailed_message. But perhaps detailed_message is not very useful as only two variants have that. I'll remove detailed_message and switch message to doc strings.

Comment thread ports/servoshell/prefs.rs Outdated
Comment thread ports/servoshell/prefs.rs Outdated
}

if cli_options.contains(&"help".into()) {
// TODO: Remove hardcoded binary name by perhaps receiving this a an argument.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't want to do that because the grand parent in the call chain of this function is already doing the same work to split the args and explictly passing down the args without binary. We can just thread that through the call chain, but I haven't tested what the binary name would look like in Android or OHOS, so I decided to handle it separately.

@mukilan
mukilan force-pushed the improve-diagnostics-logging-api branch from ab2f2ae to 5d4fc99 Compare May 5, 2026 10:09
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels May 5, 2026
@mukilan
mukilan force-pushed the improve-diagnostics-logging-api branch from 5d4fc99 to 53082a3 Compare May 5, 2026 12:29
@mukilan

mukilan commented May 6, 2026

Copy link
Copy Markdown
Member Author

Is it possible to avoid the dependency on bitvec somehow?

We could use a HashSet<DiagnosticLoggingOptions> instead if we are not concerned about space usage or the performance overhead during layout. Otherwise, I am not sure how to avoid the dependency without rolling our own BitArray like data structure.

Another option is to simply use a [bool; N] here because we know the N is small. I'm not sure if we plan to add more diagnostic options in the future, but maybe this is fine for now?

@mrobinson

Copy link
Copy Markdown
Member

We could use a HashSet<DiagnosticLoggingOptions> instead if we are not concerned about space usage or the performance overhead during layout. Otherwise, I am not sure how to avoid the dependency without rolling our own BitArray like data structure.

Another option is to simply use a [bool; N] here because we know the N is small. I'm not sure if we plan to add more diagnostic options in the future, but maybe this is fine for now?

I think this is probably fine for now. Thanks!

@mukilan
mukilan force-pushed the improve-diagnostics-logging-api branch from 53082a3 to ea33c29 Compare May 7, 2026 06:05
@mukilan

mukilan commented May 7, 2026

Copy link
Copy Markdown
Member Author

I've updated the PR to use [bool; N] instead of the BitArray. The new push also fixes #44689.

Comment thread components/config/opts.rs
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label May 7, 2026
The current `extend_from_string` API is not suitable for embedders as it
was written specifically for servoshell and therefore makes a lot of
assumptions - the binary name, the format and text of the help message,
etc. It also exits the whole process after displaying the help string.

Change the behaviour of this API by making it responsible only for
parsing string flags. The logic for formatting and displaying the help
message is moved to servoshell. This patch also switches the
`DiagnosticsLogging` from a struct to a `BitArray` and exposes
strum-based APIs so that the embedder can enumerate the available
diagnostics option, retrieve the documentation string associated with
each option and also parse the strings back to a valid
`DiagnosticsLogging` struct.

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
@mukilan
mukilan force-pushed the improve-diagnostics-logging-api branch from ea33c29 to 7396780 Compare May 8, 2026 05:09
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 8, 2026
@mukilan
mukilan enabled auto-merge May 8, 2026 05:11
@mukilan
mukilan added this pull request to the merge queue May 8, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label May 8, 2026
Merged via the queue into servo:main with commit 662c1b6 May 8, 2026
33 checks passed
@mukilan
mukilan deleted the improve-diagnostics-logging-api branch May 8, 2026 05:51
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants