Fixes for various shortcomings of regionck

While working on #5527 I found various shortcomings in regionck where it failed to infer regions that would be needed for later checks to pass. I also did some refactoring on the inference code. This PR contains just those bug fixes and refactorings.

r? @pnkfelix