Re-landing changes to use ArrayRef instead of SmallVectorImpl, and new API test.