Use Set for unique name checking for efficiency

A list is fine in most cases, but we were getting some pathologically
bad cases especially where there were lots of ambiguous names in large
functions.