GHC sometimes uses NameEnv when it should use a data structure based on uniques directly.
It was pointed out to me that my change in !3526 (closed) is representative of a larger pattern. Specifically the problem is that looking up in a finite map may take more indirections than really needed. Consider looking up a TyCon in a NameEnv. We will
- Get the
Namefrom theTyCon - Get the
Uniquefrom theName - Look up the name in the
UniqFM
But TyCon already has a Unique, cached from its Name. Better to replace the first two steps with
- Get the
Uniquefrom theTyCon.
Conclusion:
- We should not use NameEnv (or other Env types) for things which themselves have uniques.
- It's somewhat unsatisfying to use UniqFM. It enforces a Unique constraint on keys but in theory different use sites could use different types as Keys. Which is a potential source of errors.
!3526 (closed) is just one instance of this pattern. SPJ found another one as well: !3526 (comment 281971)
I don't want to hold that particular patch up further. But I'm opening this ticket so that we might not forget about the big picture.
Edited by Simon Peyton Jones