Initial work on #618.

This is still a work in progress, since the externs do not include the kind information, which is a bug, but this is pretty close in case anyone wants to look over it.