Skip to content
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

fn uncompressStream: clean up state machine mess #25

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

folkertdev
Copy link
Collaborator

@folkertdev folkertdev commented Nov 9, 2024

c2rust really made a mess of things here, so it's probably best to match this versus the original C code.

My theory is that c2rust doesn't use the information about functions/branches diverging in the relooper algorithm, though in theory it does know that functions diverge (it gives then the ! return type). Idk though, it could be something else.

Incidentally, this function would be a great candidate for rust-lang/rfcs#3720, the logic can be expressed as nicely as a state machine. I had to initialize the bzf in my cleanup, but that would not be required using loop match with const continue _

Copy link

codecov bot commented Nov 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

@folkertdev folkertdev force-pushed the cleanup-uncompress-stream-state-machine branch from 53b8238 to af50ea5 Compare November 9, 2024 16:14
@folkertdev folkertdev requested a review from bjorn3 November 11, 2024 09:06
bzip2.rs Outdated Show resolved Hide resolved

'outer: loop {
match state {
State::Standard => loop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to structure the code something like:

'outer: {
    loop {
        // ...
        if should_goto_trycat {
            state = TryCat;
            break 'outer;
        }
        if should_goto_errhandler {
            state = ErrHandler;
            break 'outer;
        }
    }
}

'state: loop {
    match state {
        // ...
    }
}

given that the Standard state is never re-entered. Or does that make the code less clear?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for now I went with a correct transformation. There is a bunch of stuff in there that still needs further cleanup (e.g. casts) and I suspect we can play around with this control flow a bit too.

@folkertdev folkertdev force-pushed the cleanup-uncompress-stream-state-machine branch from af50ea5 to 77a5c5b Compare November 11, 2024 10:07
@folkertdev folkertdev merged commit a96b5ac into main Nov 11, 2024
11 checks passed
@folkertdev folkertdev deleted the cleanup-uncompress-stream-state-machine branch November 11, 2024 10:08
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.

2 participants