-
Notifications
You must be signed in to change notification settings - Fork 280
transpile: re-enable --reorganize-definitions
#1451
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
Open
kkysen
wants to merge
21
commits into
kkysen/reorganize-definitions-prereqs
Choose a base branch
from
kkysen/reorganize-definitions-enable
base: kkysen/reorganize-definitions-prereqs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
transpile: re-enable --reorganize-definitions
#1451
kkysen
wants to merge
21
commits into
kkysen/reorganize-definitions-prereqs
from
kkysen/reorganize-definitions-enable
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this closure is called when exporting types, and a convert_type method already exists
other exports from the submodule (for types it defines via enum/struct definitions) are already added to this set, but reexports were not. this meant that if we organized imports of std/core types into a submodule (which the transpiler itself does when `--reorganize-definitions` is passed), these imports would then be missing from the main module.
these will have `use`s added unconditionally with the stdlib path if the main module uses them directly, so in order to allow deduplication without tracing through reexports, we should have the main module import these from their original (stdlib) location, not the reexported one
computing these is impure because it can call `import_type`. ideally we would not disable this caching but instead cache both the initializer and its set of required imports.
be2a985 to
3d9f762
Compare
This partially reverts 2bd339d, but only the changes to `c2rust-transpile/src/lib.rs`. We can't move `c2rust-refactor/src/bin/c2rust-refactor.rs` back to `c2rust/src/bin/c2rust-refactor.rs` because that introduces a dependency on `c2rust-refactor` from `c2rust`, which we can't have. `c2rust-refactor` is nightly-pinned, but `c2rust` (and its dependent `c2rust-transpile`) work on stable. Otherwise, `cargo install c2rust` won't work anymore. By keeping the explicit dependency detached, `--reorganize-definitions` should work if the `c2rust-refactor` binary exists. Furthermore, with the explicit dependency, the wrong `librustc_driver-*.so` was dependended on, which broke `c2rust-refactor`'s dynamic dependencies. Without it, it works.
This should work for suggestions even if `c2rust-refactor` is not installed, which may be the case since `c2rust` doesn't (and can't) explicitly depend on `c2rust-refactor`.
…nd and don't use racy `.exists()` check
….rs` to `main.rs`
Unfortunately, we have to bend over backwards to make this work without changing CLI behavior. This adds a new `--no-reorganize-definitions` flag to disable reorganizing definitions, because it would not be backwards-compatible to add an optional argument for the flag (it would eat a following argument that would previously be unassociated with the flag).
…=> unused}_reorganize_definitions` The latter is because the two fields are equal, so naming the second one `no` is misleading.
fc57cd9 to
8e391d8
Compare
3d9f762 to
b1993e9
Compare
fw-immunant
approved these changes
Nov 10, 2025
Contributor
fw-immunant
left a comment
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.
LGTM; thanks for figuring out the library issues. I didn't realize that they were part and parcel with making the nightly-dependent refactorer a dependency of the transpile tool.
The tweaks to CLI flag definition look good.
8e391d8 to
ed6ed73
Compare
kkysen
added a commit
that referenced
this pull request
Nov 11, 2025
This is split off from #1451, but doesn't enable `--reorganize-definitions` by default, so it shouldn't need the fixes in #1452 yet, of which the disabling caching of zero values needs to be fixed. Also, I'm not sure if we should enable `--reorganize-definitions` by default, since `c2rust-refactor` won't be installed by default.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In contrast to #1414, which this supersedes, this doesn't add
c2rust-refactoras a dependency ofc2rust, which messes uplibrustc_driver*.sodynamic dependencies and makescargo install c2rustnot work by default (stable) anymore.