Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve switch statement decompilation #1258
This PR contains a number of commits aimed at improving code quality surrounding [potential] switch statements. It primarily addresses two issues currently producing unnecessary gotos.
The test cases added with each commit are the best place to look for a concise before/after. Unfortunately the number of test cases required to ensure correctness would be massive, so we have to resort to inspecting the round trip tests.
The only switch related gotos remaining in the round trip tests are in
I'd be happy to discuss wider design decision via PM or some form of instant messaging if this is a lot to review.
Edit: I am unsatisfied with the quality of the
I'm not quite sure whether switch body detection is even in the right place (talking about the pass order).
Fundamental differences between the C# control flow constructs:
Unfortunately, the "continue" business is tricky and depends on the loop type.
Basically, we gain the information about what is a valid expression/statement (for
When there's only
So I think your changes here are the right way to go. It feels like a hack to use
Good analysis. I wasn't able to achieve a provably correct or satisfactorily general approach here like I was with
Proper detection would rely on two things.
As a next step, I think we should try changing up the pass order to be:
The guesswork about the "continue target block" seems unavoidable, but at least we get to avoid the guesswork about which loops contain the switch.
In general, I support said changing of pass order. The only issue I ran into when I attempted it was related to loops (and switch containers) being constructed inner first #915 Part of the switch body would end up outside the loop, and have to be poached from the parent container into the child. I didn't go any further with this because control flow graphs are restricted to container context, and I got quite good results with the current approach.