Skip to content

Split BindgenOptions #2263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

pvdrz
Copy link
Contributor

@pvdrz pvdrz commented Sep 5, 2022

This PR splits all the fields inside BindgenOptions struct into two new structs:

  • inputs: BindgenInputs: Which holds all the command line arguments and implements Clone.
  • state: BindgenState: Which holds the remaining fields of BindgenOptions and does not implement Clone.

This change would allow bindgen to preserve its initial configuration and run again if required (which would help solve #1090).

It would also ease a transition to a newer version of clap (#1873) and is somewhat related to #2132.

Additionally BindgenOptions::inputs is exposed immutably, meaning that it is not possible to accidentally change the user inputs.

cc @emilio @amanjeev

Blocked by: #2271

@pvdrz pvdrz force-pushed the split-options branch 5 times, most recently from eb53d8c to ddc570d Compare September 6, 2022 15:29
@bors-servo
Copy link

☔ The latest upstream changes (presumably 8b29355) made this pull request unmergeable. Please resolve the merge conflicts.

@bors-servo
Copy link

☔ The latest upstream changes (presumably 61636e9) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz pvdrz marked this pull request as draft September 12, 2022 18:49
@bors-servo
Copy link

☔ The latest upstream changes (presumably 0d805d7) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz pvdrz requested review from emilio and kulp and removed request for emilio September 19, 2022 16:51
@pvdrz pvdrz marked this pull request as ready for review September 19, 2022 16:58
@bors-servo
Copy link

☔ The latest upstream changes (presumably 86f059f) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

So this is a pretty massive change, and I'm not sure it's warranted.

From a quick look, the things in BindgenOptions that can't be cloned are input_unsaved_files and the ParseCallbacks.

input_unsaved_files seems rather trivial to get rid of (just a matter of generating the UnsavedFile list in generate rather than the caller unless I'm missing something).

The ParseCallbacks seem like similarly could be passed separately from BindgenOptions as an extra argument to generate etc, unless I'm missing something.

That leaves the weird mutations that we do on the clang flags and so. Those don't seem impossible to remove (we could make the options immutable I think). But also, not sure we'd need to. As long as we clone the options before calling generate(), we can call generate() again with the same set of options and it should work.

That is to say, I think this can be done in a much less intrusive way, wdyt?

@pvdrz
Copy link
Contributor Author

pvdrz commented Sep 23, 2022

I agree that it would be possible to preserve the user inputs by just cloning BindgenOptions before calling generate. But at the same time, I believe this change makes clearer when a value was set by the user with some intent vs when bindgen modified one value due to its internal logic.

At the same time, keeping all the CLI inputs in a single type makes easier moving to things like clap 3 with its derive macro. Which would ease adding new flags and keeping the documentation and names consistent as they would be a bunch of field attributes instead of being on a different file.

I'm not opposed to just cloning things before they are changed. I just think this makes the code a bit more organized while only adding the extra burden of thinking if something is part of the inputs or part of the state to decide where to find it. At the end most of the changes done to the uses of BindgenOptions were reduced to doing

+ foo.options()
- foo.inputs()

@bors-servo
Copy link

☔ The latest upstream changes (presumably #2278) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz
Copy link
Contributor Author

pvdrz commented Sep 26, 2022

Closed in favor of #2285

@pvdrz pvdrz closed this Sep 26, 2022
@divagant-martian
Copy link

Sad to this closed, seemed like a good code quality improvement

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.

4 participants