Memoize static contracts and resulting contracts

This commit uses memoization not just for Name types
but for static contracts for all types. It also adjusts
how Name contracts are generated to increase sharing
across multiple type->contract calls.