Skip to content

Conversation

@kkysen
Copy link
Contributor

@kkysen kkysen commented Nov 10, 2025

In contrast to #1414, which this supersedes, this doesn't add c2rust-refactor as a dependency of c2rust, which messes up librustc_driver*.so dynamic dependencies and makes cargo install c2rust not work by default (stable) anymore.

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.
kkysen and others added 10 commits November 10, 2025 09:44
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`.
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.
@kkysen kkysen force-pushed the kkysen/reorganize-definitions-prereqs branch from fc57cd9 to 8e391d8 Compare November 10, 2025 17:45
@kkysen kkysen force-pushed the kkysen/reorganize-definitions-enable branch from 3d9f762 to b1993e9 Compare November 10, 2025 17:45
@kkysen kkysen requested a review from fw-immunant November 10, 2025 18:34
Copy link
Contributor

@fw-immunant fw-immunant left a 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.

@kkysen kkysen force-pushed the kkysen/reorganize-definitions-prereqs branch from 8e391d8 to ed6ed73 Compare November 11, 2025 00:05
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants