Polish optimization of namespace lookups
Polish optimization of namespace lookups

* Explain better how optimization of namespace lookups are done in comments.
* Consider `hasReplacements` to be true if there exists any namespace replacements.
* Improve error messages slightly

Permutatrix/rollup,alalonde/rollup,corneliusweig/rollup,Victorystick/rollup,lukeapage/rollup