Add a memoize! macro and use it throughout rustc

@huonw Good idea, thanks!