I need this API in the Swift plugin, but it seems generally useful enough to expose it in the main branch.