Refactor method dispatch infrastructure

This is a pretty major refactoring of the method dispatch infrastructure. It is intended to avoid gross inefficiencies and enable caching and other optimizations (e.g. #17995), though it itself doesn't seem to execute particularly faster yet. It also solves some cases where we were failing to resolve methods that we theoretically should have succeeded with.

Fixes #18674.

cc #18208 


So, a follow-up PR should address the fact that, currently, method resolution does not consider *coercions* but only subtyping. (More accurately, the rewrite in this PR does not and the original method code did not; the *current* code does, and I think we will want to reproduce that logic, but I didn't want to merge it all.)

In any case, adding more tests seems like a good idea.