This checkin basically amounts to a complete rewrite of the type-resolution