Shopify / Shopify/tapioca

Rewrite `attr_reader` and friends into `def` methods

Open
#1,918 0 comments 0 reactions 1 assignee View on GitHub

@amomchilov is already working on this.

Since Jun 10, 2024.

Dominant language
Ruby
Stars
873
Forks
164
Avg merge
4d 27m
Merged PRs (30d)
9

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.