Changes the AST map builder to use a callback

This is for 2 reasons, 1. The map gets updated by the metadata
reader and any other way would require moving it out of the
owning structure. 2. Issue #4868 means that a borrow of the Map and
its lifetime collide, forcing the borrow to last for the lifetime of
the Map itself, not ideal.

There is some unsafe code introduced here to work around this problem
as it still comes up, but in a more managable form.