Skip to content

Conversation

@ahomescu
Copy link
Contributor

@ahomescu ahomescu commented Dec 2, 2025

  • Fix reorganize_definitions test: the test (and probably all the refactoring tests) has bitrotted; get it working again
  • Add repro of statvfs issue from python2: reproduce the issue encountered by the python2 test on Ubuntu 22.04 where the statvfs structure has a private field that we cannot use
  • Check visibility when comparing structural equivalence for function signatures
  • Deep match visibility when comparing function signatures: updates to the algorithm we use to match equivalent types and function signatures.
  • Enable more transforms on the python2 integration test.

When matching between two types to determine whether they can be unified, we now account for differences in visibility because importing a structure with private types from an external crate (e.g. libc) makes them unusable to us when trying to construct new values of those types. The motivating example is statvfs:

    pub struct statvfs {
        pub f_bsize: c_ulong,
        pub f_frsize: c_ulong,
        pub f_blocks: crate::fsblkcnt_t,
        pub f_bfree: crate::fsblkcnt_t,
        pub f_bavail: crate::fsblkcnt_t,
        pub f_files: crate::fsfilcnt_t,
        pub f_ffree: crate::fsfilcnt_t,
        pub f_favail: crate::fsfilcnt_t,
        pub f_fsid: c_ulong,
        pub f_flag: c_ulong,
        pub f_namemax: c_ulong,
        __f_spare: [c_int; 6],
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a snapshot?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I run the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go into c2rust-refactor/tests, run run-test.sh reorganize_definitions. I think we should start adding these tests back to CI, but I wasn't sure if it goes into this PR or do another one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to have all the testing just in Rust instead of scattered shell scripts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to move all the refactorer tests into tests/refactor at the top level, and then we can change the testing there. We should do that separately though.

It'd be nice to have all the testing just in Rust instead of scattered shell scripts.

I'm not sure how this is supposed to work in this case. The inputs are Rust files that we feed into the refactorer, are you saying we should call that tool from Rust #[test] code? I'm not sure how that's simpler or what it buys us over shell scripts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to move all the refactorer tests into tests/refactor at the top level, and then we can change the testing there. We should do that separately though.

I don't care too much, but our transpiler snapshot tests are under c2rust-transpile/, so the way it is now would be the same.

I'm not sure how that's simpler or what it buys us over shell scripts.

We just run cargo test and cargo figures out what we need to build. For example the current shell scripts have a lot of complexity over setting up paths and run only debug mode, whereas with cargo it just does the right thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, we can do that but I'd prefer making a separate PR for those (probably larger) changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's totally fine.

@ahomescu ahomescu force-pushed the ahomescu/fix_reorganize_test branch 3 times, most recently from af7d13d to 5665646 Compare December 3, 2025 01:22
Comment on lines +1161 to +1164
_ => 'match_fields: {
if variant1.fields().len() != variant2.fields().len() {
break 'match_fields false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh clever!

@kkysen kkysen changed the title c2rust-refactor: Update reorganize_definitions test and fix some issues refactor: Update reorganize_definitions test and fix some issues Dec 7, 2025
@kkysen kkysen changed the title refactor: Update reorganize_definitions test and fix some issues refactor: Update reorganize_definitions test and fix some issues Dec 7, 2025
Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this all LGTM now besides those two little nits.

@kkysen kkysen force-pushed the ahomescu/fix_reorganize_test branch from 5665646 to e1fbe80 Compare December 8, 2025 12:01
@kkysen kkysen merged commit afef0e8 into master Dec 8, 2025
5 checks passed
@kkysen kkysen deleted the ahomescu/fix_reorganize_test branch December 8, 2025 12:26
kkysen added a commit that referenced this pull request Dec 9, 2025
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