Skip to content

Skip the subclass method lookup for calls on Object - #489

Merged
sinsoku merged 1 commit into
ruby:masterfrom
sinsoku:skip-toplevel-subclass-lookup
Sep 26, 2026
Merged

sinsoku merged 1 commit into
ruby:masterfrom
sinsoku:skip-toplevel-subclass-lookup

Conversation

@sinsoku

@sinsoku sinsoku commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Motivation / Background

This Pull Request has been created because receiver-less calls at the top level pass their arguments to same-named methods of unrelated classes.

Since 7588c4fd, a receiver-less call also looks up the method in the descendants of self's class. When self is Object, those are every class:

def foo(n) = n

foo(1)

class C
  def foo(n)
  end
end

TypeProf infers C#foo: (Integer) -> nil here. In a Rails app, get in config/routes.rb reaches Faraday's get and causes wrong diagnostics, and walking every class on each call slows down the analysis of large projects.

Detail

This skips the lookup when self is Object or an instance of it. It also applies inside methods defined at the top level, where the lookup likewise only matched unrelated classes.

The new scenario checks that neither case reaches C.

Verification

typeprof --show-errors . on rubygems.org (Ruby 4.0.6, Apple M1 Max):

before after
with RBS collection 55.3s 16.4s
--no-collection 7.9s 7.0s

The only output changes are removed wrong argument types and diagnostics.

🤖 Generated with Claude Code

Top-level calls like `get` in Rails routes passed their arguments to
unrelated methods such as Faraday's `get`, and walking every class on
each call made the analysis of large projects like rubygems.org much
slower.
@sinsoku
sinsoku merged commit 3125e31 into ruby:master Sep 26, 2026
6 checks passed
@sinsoku
sinsoku deleted the skip-toplevel-subclass-lookup branch September 26, 2026 17:31
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.

1 participant