-
Notifications
You must be signed in to change notification settings - Fork 246
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
Add --preserve-unused-functions #291
Add --preserve-unused-functions #291
Conversation
Looks good overall. I think it is fine to add a parameter to The tests should pass before we merge. We're hitting an upstream bug on macOS (see #289). If that is not what you are hitting, what platform are you seeing failures on? |
c2rust-transpile/src/c_ast/mod.rs
Outdated
.. | ||
} if preserve_unused_functions => { | ||
to_walk.push(decl_id); | ||
used.insert(decl_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The used
variable no longer tracks what is used because of the option to preserve unused functions. Now it tracks what we want to keep, so we should consider renaming it to keep
or similar to reflect that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to adjust that, though when I get to that level I'll also want to refactor the whole match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed in b19396a now; I'm not sure if you'll be happy with it because doing it all the way through meant renaming the function as well (for otherwise things would be inconsistent there). Just have a look, I'd understand if you rather not have that commit.
[edit: commit ref was broken, fixed now]
I'm building on Debian GNU/Linux unstable, with Rust provided by rustup. All that follows was done on current master (4062985). On
whereas on nightly, I hit
When running in c2rust-transpile, things compile on stable (nightly has the same error, I may be missing some parts from rustup there), but fails at several places. `cargo test` in c2rust-transpile``` running 3 tests test renamer::tests::forgets ... ok test renamer::tests::simple ... ok test renamer::tests::scoped ... oktest result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out running 6 tests failures: ---- src/translator/structs.rs - translator::structs::Translation::convert_struct_fields (line 264) stdout ---- error: cannot find attribute error: cannot find attribute error: aborting due to 3 previous errors Couldn't compile the test. error: aborting due to previous error For more information about this error, try error[E0425]: cannot find value error[E0412]: cannot find type error[E0425]: cannot find value error: aborting due to 4 previous errors Some errors have detailed explanations: E0412, E0425. error[E0425]: cannot find value error[E0425]: cannot find value error: aborting due to 3 previous errors For more information about this error, try error[E0425]: cannot find value error[E0425]: cannot find value error: aborting due to 3 previous errors For more information about this error, try error[E0586]: inclusive range with no end error[E0412]: cannot find type error[E0425]: cannot find value error[E0425]: cannot find function error[E0425]: cannot find value error[E0425]: cannot find value error: aborting due to 7 previous errors Some errors have detailed explanations: E0412, E0425, E0586. failures: test result: FAILED. 0 passed; 6 failed; 0 ignored; 0 measured; 0 filtered out
|
We don't use |
OK, that explains how things went south. Running
|
b6260db
to
b19396a
Compare
Just to ensure I'm testing the right thing next time (I reinstalled to be sure and ran the test again with the same result): Does this test the installed version or the crate / git repo it is in? |
Good to hear that the tests pass on your host. |
The unsuccessful tests all appear to be unrelated to the PR itself. What can I do to progress this? Can I trigger the CI again, eg. by force-pushing an amend with a new timestamp? Is there anything review-wise that still needs addressing? |
c2rust/src/transpile.yaml
Outdated
@@ -172,6 +172,10 @@ args: | |||
long: disable-refactoring | |||
help: Disable running refactoring tool after translation | |||
takes_value: false | |||
- preserve-unused-functions: | |||
long: preserve-unused-functions | |||
help: Translate even static and inline C functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this wording: "Include static and inline functions in translation".
@chrysn I looked at the failures and agree that you didn't cause these. I (think I) reconfigured GitHub actions to not build PRs. As for the Azure pipeline failure on macOS, that is caused by a homebrew issue with the LLVM formula on macOS. Update: can you try rebasing your PR on top of master? Should pass the Azure tests on all platforms now. |
to keep otherwise pruned static / inline functions. Closes: immunant#287
The criterion for whether it is desired for an item to be transpiled have been broadened to possibly preserve unused functions as well. Thus, the "unused" name part has been replaced with "unwanted", which traditionally means unused but, in other configurations, can mean "unused but not a function" now as well.
b19396a
to
25d3e11
Compare
Wording adapted and rebased. |
Revisiting this from a bindgen interaction point of view, I'm questioning my choice of limiting this to |
I think the flag name is fine. We can rely on the help text to provide further guidance to other users – and update the text in the unlikely event that users are frequently confused about this flag. |
Depends on immunant/c2rust#291. Is exploratory work for rust-lang/rust-bindgen#1344.
Changes: * Use C2Rust in addition to bindgen * Enable more headers, eg. for CoAP, sockets and all peripherals * Enable building for docs.rs by having a slimmed-down copy of the headers checked in (not fully active yet as it depends on [291] and a release from there) [291]: immunant/c2rust#291
to keep otherwise pruned static / inline functions.
Closes: #287
This is an initial simple approach to #287. It looks like it's generating valid code, but I'm too early in my whole evaluation of c2rust to say whether what comes out of this will work, so please take it with due care. (Also, tests don't pass, but neither do they pass on my machine on current master, so...)
I'm playing fast and lose with API stability here, as I don't have the overview to tell whether prune_unused_decls is part of any practically public API. If it is, I can replace the added parameter with a second function
prune_unused_decls_but_not_functions
and rename the current implementation to a private impl one.