Skip to content

Add --report-orphans flag to produce orphan definition report#566

Merged
st0012 merged 1 commit intomainfrom
show-orphans
Feb 9, 2026
Merged

Add --report-orphans flag to produce orphan definition report#566
st0012 merged 1 commit intomainfrom
show-orphans

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Feb 5, 2026

When used, rubydex would list orphan definitions under /tmp/rubydex-orphan-report.txt (can be changed by supplying arg to the flag).

Example output:

Constant	::Rack::Cache::MetaStore::RAILS	/Users/hung-wulo/src/github.com/rails/rails/actionpack/lib/action_dispatch/http/rack_cache.rb:29:31-29:35
Constant	::Rack::Cache::EntityStore::RAILS	/Users/hung-wulo/src/github.com/rails/rails/actionpack/lib/action_dispatch/http/rack_cache.rb:61:33-61:37
InstanceVariable	@adapter	/Users/hung-wulo/src/github.com/rails/rails/activejob/test/helper.rb:8:1-8:9
SingletonClass	Benchmark::<Benchmark>	/Users/hung-wulo/src/github.com/rails/rails/activesupport/lib/active_support/core_ext/benchmark.rb:5:1-5:13

This feature is helpful for investigating issues. For example, some definitions in Core become orphan due to NameId collision and that's shown in the report (I've shown that to @vinistock in pairing). (This is fixed now)
Another example is that this helps me investigate incorrect resolution in #515.

However, it's also worth noting that detecting orphans don't necessarily mean there's a but in the code or rubydex. For example, due to the lack of <main> representation, top level instance variables would be considered orphans now.

@st0012 st0012 self-assigned this Feb 5, 2026
@st0012 st0012 requested a review from a team as a code owner February 5, 2026 21:12
@st0012 st0012 changed the title Add --show-orphan flag to produce orphan definition report Add --report-orphans flag to produce orphan definition report Feb 6, 2026

/// Walks the Name system's `parent_scope` chain to reconstruct the constant path.
/// Falls back to `nesting` for enclosing scope context when there is no explicit parent scope.
pub(crate) fn build_qualified_name_from_name(&self, name_id: NameId) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

Not a strong opinion, but I would probably simplify the code and only keep URI + line/col information. That way, whoever is investigating the inconsistent data can open the file in one click and take a look at what pattern causes it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I still think it'd helpful to have the type and name. The collision cases were found because the generated FQN was weird. If all we have is the location, then we wouldn't be able to tell they became orphan because of the name collision.

Add a CLI flag that writes a TSV report of all orphan definitions
(definitions not linked to any declaration) to a specified file.

Each line contains: kind, qualified name, and source location.

The qualified name is reconstructed by walking either the Name system's
parent_scope chain (for constant-like definitions) or the
lexical_nesting_id chain (for method-like definitions).

Ungate Offset#to_display_range so it can be reused for location
formatting outside of tests.
@st0012 st0012 enabled auto-merge (squash) February 9, 2026 22:15
@st0012 st0012 merged commit 4c7fdfd into main Feb 9, 2026
27 checks passed
@st0012 st0012 deleted the show-orphans branch February 9, 2026 22:17
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.

Add --show-orphans or similar flags to produce detailed info on orphan definitions

3 participants