Skip to content

Remove uses of opts::get() from as much code as possible #22854

Open

Description

@jdm

Right now the code in components/config has a bunch of code depending on it because the command line arguments for Servo are global singleton that any code can access. This makes changing the command line code for Servo frustrating, because a lot of code gets rebuilt unnecessarily. We should remove as many uses of opts::get() as possible, and replace them with values that are passed into appropriate constructors via the code in components/servo/lib.rs.

We can focus on one component at a time:

Activity

  1. added
    E-less-complex
    I-refactor
    on Feb 8, 2019
  2. highfive commented on Feb 8, 2019

    @highfive

    Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

    If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

  3. snowsignal commented on Feb 21, 2019

    @snowsignal
    Contributor

    @highfive: assign me

  4. added
    C-assigned
    on Feb 21, 2019
  5. highfive commented on Feb 21, 2019

    @highfive

    Hey @JacksonCoder! Thanks for your interest in working on this issue. It's now assigned to you!

  6. peterjoel commented on Mar 6, 2019

    @peterjoel
    Contributor

    Couldn't opts just be a non-persistent prefs override? Or will this just move the same problem?

  7. jdm commented on Mar 6, 2019

    @jdm
    MemberAuthor

    I'm not sure I understand what you're suggesting. Do you have an example?

  8. peterjoel commented on Mar 6, 2019

    @peterjoel
    Contributor

    I'm not sure I understand what you're suggesting. Do you have an example?

    I am suggesting that all CLI arguments would actually set a preference, which would not be persisted. Instead of accessing opts, any configurable code would just access prefs. The actual value would be evaluated in ascending order of precedence: prefs.json, user preferences, CLI argument.

    For example, tile_size is currently a CLI argument but not in preferences. It could be made into a preference which would allow you to set it via prefs.json or choose to override it via CLI. This mechanism already works as part of my Preferences PR, and several CLI arguments are propagated that way, e.g. layout threads.

  9. jdm commented on Mar 6, 2019

    @jdm
    MemberAuthor

    Ah, I see. The advantage of keeping the command line arguments separate from preferences is that the arguments are not mutable. This is one reason why it's safe to remove access to the global arguments storage and pass the values directly to the code that uses them, allowing us to remove dependencies.

  10. peterjoel commented on Mar 6, 2019

    @peterjoel
    Contributor

    @jdm It's not ideal then that some opts are actually duplicated as (mutable) prefs, so you could get a different value for layout.threads, depending on if you access it via opts or prefs.

  11. jdm commented on Mar 6, 2019

    @jdm
    MemberAuthor

    That's true! Anything that is duplicated should be removed from the immutable options structure and any users changed to use the preference.

  12. jdm commented on Mar 6, 2019

    @jdm
    MemberAuthor

    With the caveat that using the command line option should mutate the preference.

  13. peterjoel commented on Mar 6, 2019

    @peterjoel
    Contributor

    Rather than replace all instances of opts with dependency injection, another approach is to split opts into two levels: globals (which should change infrequently) and crate-level options (which can develop alongside the features of the crate itself). For example, bluetooth only uses one option: headless, which is global. compositing uses some globals (exit_after_load maybe?), but also more specific options like device_pixels_per_px.

    Each crate would define its own options and provide access to both its own and the global options.

    If you add or remove a global option then all the component crates will still need to be rebuilt, but adding a compositing option won't affect bluetooth.

  14. jdm commented on Mar 6, 2019

    @jdm
    MemberAuthor

    You say headless is global, but it's only used by 3 crates (or 5 modules). I guess I don't see a big benefit to continuing to expose a set of global options, given how restricted their use generally is.

  15. 42 remaining items

  16. jdm commented on Oct 11, 2019

    @jdm
    MemberAuthor

    That's a good idea! It would be an improvement over the status quo because the use of opts::get would stop, and it would be a global that's private to a particular crate.

  17. added a commit that references this issue on Oct 20, 2019
  18. added a commit that references this issue on Oct 21, 2019
  19. added a commit that references this issue on Oct 21, 2019
  20. JMarlin commented on Mar 4, 2020

    @JMarlin

    @highfive: assign me

  21. added
    C-assigned
    on Mar 4, 2020
  22. highfive commented on Mar 4, 2020

    @highfive

    Hey @JMarlin! Thanks for your interest in working on this issue. It's now assigned to you!

  23. removed
    C-assigned
    E-less-complex
    on Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions