Skip to content

Migrate Sorbet signatures to RBS comments#455

Merged
rafaelfranca merged 19 commits into
mainfrom
at/rbs-comment-signatures
May 6, 2026
Merged

Migrate Sorbet signatures to RBS comments#455
rafaelfranca merged 19 commits into
mainfrom
at/rbs-comment-signatures

Conversation

@Morriar

@Morriar Morriar commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrate all Sorbet sig blocks and type annotations to RBS comment signatures, allowing us to drop the runtime dependency on sorbet-runtime.

The main goal is to remove the sorbet-runtime dependency from the gem. This eliminates the runtime overhead of signature validation and method wrapping, boosting performance for all Packwerk users — especially on large codebases where the cost of sorbet-runtime adds up across thousands of file checks.

What changed

  • Translate all sig blocks to #: RBS comment signatures
  • Translate T.let, T.cast, T.must, T.bind, T.unsafe to RBS comment equivalents (#: as Type, #: as !nil, etc.)
  • Translate T.type_alias to #: type name = ... RBS syntax
  • Migrate T::Struct subclasses to plain Ruby classes
  • Remove extend T::Sig, extend T::Helpers, T::Generics usage
  • Remove sorbet-runtime from gemspec dependencies
  • Remove disable_sorbet.rb shim (no longer needed)

@Morriar Morriar requested a review from a team as a code owner May 1, 2026 19:20
@Morriar Morriar force-pushed the at/rbs-comment-signatures branch from fa09654 to 52480ca Compare May 1, 2026 19:23
Base automatically changed from at/bump-sorbet to main May 1, 2026 19:46
Comment thread Gemfile.lock Outdated
thor (>= 1.2.0)
tsort
thor (1.5.0)
thor (1.4.0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random downgrade?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, not sure why bundler decided to downgrade some gems because I remove sorbet-runtime

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downgrades are still there

Comment thread Gemfile.lock Outdated
@Morriar Morriar force-pushed the at/rbs-comment-signatures branch from 52480ca to fdeee74 Compare May 5, 2026 14:38

@paracycle paracycle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the lockfile changes that @hmcguire-shopify pointed out, I think this is great!

Comment thread lib/packwerk/parsers/erb.rb Outdated
Comment thread lib/packwerk/association_inspector.rb Outdated
Comment thread lib/packwerk/association_inspector.rb Outdated
@rafaelfranca rafaelfranca force-pushed the at/rbs-comment-signatures branch from fdeee74 to 74b0047 Compare May 6, 2026 18:58
Morriar and others added 19 commits May 6, 2026 20:51
* Use conservative rubocop bump (1.69.0 instead of 1.86.1) to minimize
  transitive dependency changes
* Add minitest-mock gem (extracted from minitest 6) to restore Object#stub
* Require "parser" instead of sub-files to fix AST constant load order
  with parser 3.3.11.1
* Use Prism::Translation::Parser::Builder as base class for
  TolerateInvalidUtf8Builder to fix Prism 1.9.0 deprecation warnings
* Update integration test to match new nil error message after T.must
  removal
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
@rafaelfranca rafaelfranca force-pushed the at/rbs-comment-signatures branch from fba1a83 to c0f9886 Compare May 6, 2026 20:54
@rafaelfranca rafaelfranca merged commit dbe4349 into main May 6, 2026
10 checks passed
@rafaelfranca rafaelfranca deleted the at/rbs-comment-signatures branch May 6, 2026 20:58
edavey added a commit to alphagov/content-block-manager that referenced this pull request May 12, 2026
Packwerk 3.3.0 no longer implicitly loads sorbet-runtime
(Shopify/packwerk#455), causing packwerk-extensions 0.3.0 to
fail with "uninitialized constant Packwerk::Privacy::T" when
individual checkers are required directly.

We resolve this issue (rubyatscale/packwerk-extensions#66) by
requiring the top-level entrypoint, which explicitly loads
sorbet-runtime before the checkers.

This also loads all packwerk-extensions checkers (privacy,
visibility, folder_privacy, layer) rather than just privacy,
though unused checkers remain inactive unless configured in
package.yml files.
dduugg added a commit to rubyatscale/packwerk-extensions that referenced this pull request May 29, 2026
#68)

* Update gem rbis

* Modernize Sorbet tooling and pin rubocop-sorbet for new T.let cops

Bump sorbet, sorbet-runtime, tapioca, spoom, rbi, and rbs to current
versions and regenerate the gem RBIs to match.

Pin rubocop-sorbet to Shopify/rubocop-sorbet@7b7d3cb (post-#367 and
post-#372) so the not-yet-released Sorbet/RedundantTLetForLiteral and
Sorbet/RedundantTLet cops are available.

* Remove redundant T.let on literals via Sorbet cops

Apply Sorbet/RedundantTLetForLiteral and Sorbet/RedundantTLet
autocorrections. Sorbet infers the type of literal constants
automatically, so the explicit T.let wrappers were redundant.

* Migrate type annotations to RBS comments and drop sorbet-runtime

Replace Sorbet's runtime DSL with inline RBS comment annotations so the
gem no longer depends on sorbet-runtime at runtime, matching upstream
packwerk (Shopify/packwerk#455).

- Enable --parser=prism and --enable-experimental-rbs-comments in
  sorbet/config
- Translate all sig blocks to #: RBS comments (via spoom)
- Convert the T::Struct Package classes to plain classes with
  RBS-annotated attr_readers and keyword initializers
- Replace T.let / T.must / extend T::Sig with inline RBS annotations
- Drop require 'sorbet-runtime' and the sorbet-runtime gem dependency

* Trim rubocop config for the RBS migration

- Allow RBS inline annotation comments (Layout/LeadingCommentSpace)
- Set TargetRubyVersion to 3.2 (matches required_ruby_version), fixing
  Lint/RedundantRequireStatement on the binstubs
- Remove disabled-cop entries that no longer have any violations,
  including Style/TrivialAccessors (its Sorbet-sig rationale is moot now
  that RBS makes annotated attr_readers clean)

* Bump minimum Ruby version to 3.3

The modernized Sorbet toolchain pulls in rbi 0.3.12, which requires
Ruby >= 3.3. Raise required_ruby_version and TargetRubyVersion to match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants