Add a memoize! macro and use it throughout rustc

Maybe these could be moved to be first, so that they're close to the function declaration (as it stands, one has to navigate around a possibly-long function body to find them, made harder by formatting it without indentation).