Skip to content

Rewrite attr_reader and friends into def methods #1918

@amomchilov

Description

@amomchilov

Motivation

In Tapioca, we've always defaulted to generating reader/writer methods instead of attr_xxx declarations, because it is harder to figure out if a reader/writer method was defined via an attr_xxx call, but also because if Tapioca generated attr_xxx declarations, Sorbet would then do more work to turn them into reader/writer method definitions in its rewriter anyway.

Basically, you don't get any advantage from using attr_xxx declarations in RBIs, you actually get slightly worse performance because of the extra rewriter phases that need to happen.

As a result, I think we should:

  1. Merge attr_xxx declarations with the corresponding reader/writer method definitions, AND

  2. Always leave method definitions behind.

Originally posted by @paracycle in #1709

Steps

### Tasks
- [ ] https://github.com/Shopify/rbi/pull/308
- [ ] Modify Tapioca to run the rewriter when reading user-generated RBIs

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions