Skip to content

refactor: refuse to run transforms on crates that do not compile#1898

Closed
thedataking wants to merge 1 commit into
masterfrom
perl/refactor-fail-fast
Closed

refactor: refuse to run transforms on crates that do not compile#1898
thedataking wants to merge 1 commit into
masterfrom
perl/refactor-fail-fast

Conversation

@thedataking

@thedataking thedataking commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

c2rust-refactor runs the rustc analysis passes before applying a transform, but discarded the result (let _result = tcx.analysis(())). When the input crate has type errors, the transform then operates on incomplete typeck tables: it may silently emit rewrites derived from bogus types, or panic on an internal invariant far from the actual problem. Because each transform in a sequence consumes the previous one's output, one transform that produces an invalid crate poisons every transform that runs after it.

This surfaced while adding libgit2 to the integration testsuite (#1861). libgit2 compiles its test sources with GIT_DEPRECATE_HARD but its library sources without it, so several public structs legitimately have two incompatible declarations within one crate (a member that is a function pointer in one view is a reserved void pointer in the other). The reorganize_definitions transform, which merges duplicate declarations by name, produced an ill-typed crate from that input, but the failure CI reported was a "mismatched key trees" panic in remove_literal_suffixes, three transforms later, which took considerable effort to trace back to the transform actually at fault.

Check the analysis result and exit with an error instead, so a transform sequence stops at the transform that broke the crate and rustc's diagnostics point at the real breakage.

c2rust-refactor runs the rustc analysis passes before applying a
transform, but discarded the result (`let _result = tcx.analysis(())`).
When the input crate has type errors, the transform then operates on
incomplete typeck tables: it may silently emit rewrites derived from
bogus types, or panic on an internal invariant far from the actual
problem. Because each transform in a sequence consumes the previous
one's output, one transform that produces an invalid crate poisons
every transform that runs after it.

This surfaced while adding libgit2 to the integration testsuite.
libgit2 compiles its test sources with GIT_DEPRECATE_HARD but its
library sources without it, so several public structs legitimately
have two incompatible declarations within one crate (a member that is
a function pointer in one view is a reserved void pointer in the
other). The reorganize_definitions transform, which merges duplicate
declarations by name, produced an ill-typed crate from that input,
but the failure CI reported was a "mismatched key trees" panic in
remove_literal_suffixes, three transforms later, which took
considerable effort to trace back to the transform actually at fault.

Check the analysis result and exit with an error instead, so a
transform sequence stops at the transform that broke the crate and
rustc's diagnostics point at the real breakage.
@thedataking

Copy link
Copy Markdown
Contributor Author

Withdrawing this: the refactor tool intentionally supports running commands on crates that do not compile (e.g. test_abstract feeds a crate with expected E0133 errors back into the tool, and the illtyped machinery exists to repair broken intermediate states), so an unconditional abort breaks that contract — as CI on #1864 demonstrated. The libgit2 failure that motivated this is addressed at the source in #1861 (transpiling with -UGIT_DEPRECATE_HARD), and the underlying reorganize_definitions limitation is tracked in #1899.

@thedataking thedataking deleted the perl/refactor-fail-fast branch July 12, 2026 23:15
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.

1 participant