-
Notifications
You must be signed in to change notification settings - Fork 265
Option to disable pruning of static functions #287
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
Comments
Thanks for doing some initial research on this @chrysn; I don't know how to preserve these functions without adding a new flag. The transpiler flags are defined in Re. the attributes you mention ( |
I'd call it |
to keep otherwise pruned static / inline functions. Closes: immunant#287
to keep otherwise pruned static / inline functions. Closes: immunant#287
* Add --preserve-unused-functions to keep otherwise pruned static / inline functions. Closes: #287 * transpile: Reduce code duplication * prune_unused_decls: Rename to unwanted 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.
C2Rust, by default and since 8bcb5c9, removes unneeded definitions, which includes static inline functions.
Exporting them is useful when C2Rust is used outside a full transpilation setting -- for example when a C library is accessed by cbindgen, but some functions are declared static inline. (Exporting them anyhow there might be an option; however, as they are static inline, chances are they're used in hot loops, and avoiding the function call would be really nice there. There's some discussion already at rust-lang/rust-bindgen#1344; I'm trying to get that done in a step-by-step fashion).
As a crude proof-of-concept, making TypedAstContext::prune_unused_decls return immediately does the trick; as a next refinement, so does matching on any CDeclKind::Function with Some body by ripping out the conditions -- but that's not really feasible outside experimental setups.
c2rust transpile x.json --translate-static-inline
.The text was updated successfully, but these errors were encountered: