Merge "Have R classes generate their own reference rewrite logic" into lmp-dev