Skip to content

ruby-rbs crate: Add declaration tables to Environment - #3174

Draft
dak2 wants to merge 10 commits into
ruby:masterfrom
dak2:rust-environment-duplicate-decl-detection
Draft

dak2 wants to merge 10 commits into
ruby:masterfrom
dak2:rust-environment-duplicate-decl-detection

Conversation

@dak2

@dak2 dak2 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part of #2954.

Ports RBS::Environment#insert_rbs_decl: registers declarations by absolute name and reports duplicates as RBS::DuplicatedDeclarationError does.

  • interface
  • type alias
  • global
  • class
  • module
  • constant
  • class alias
  • module alias

Alias normalization, type name resolution, and type parameter validation are follow-ups.

🤖 Generated with Claude Code

@dak2 dak2 changed the title Detect duplicated interface declarations in Environment (Rust) ruby-rbs crate: Detect duplicated interface declarations in Environment Sep 27, 2026
Add DeclId, SingleEntry, and DuplicatedDeclarationError types, and
insert.rs to track interface declarations per source and report
duplicates as load errors instead of silently overwriting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dak2
dak2 force-pushed the rust-environment-duplicate-decl-detection branch from b6cbb4f to c1cf045 Compare October 12, 2026 01:33
Register type aliases in their own table so duplicates are reported as
load errors, as is already done for interfaces.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@dak2 dak2 changed the title ruby-rbs crate: Detect duplicated interface declarations in Environment ruby-rbs crate: Add declaration tables to Environment Oct 12, 2026
dak2 and others added 8 commits October 12, 2026 11:57
Report them as load errors instead of silently overwriting, as is
already done for interfaces and type aliases.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Declarations inside a module were never reached, so a duplicate such as
two `interface Foo::_I` went undetected. Register modules as one entry
per name, recurse into their bodies with the enclosing namespace, and
record each declaration's context.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ruby keeps classes and modules in one `class_decls` table, so a name is
either a class or a module. Split the entry into `ClassEntry` and
`ModuleEntry` over a shared layout, and report a duplicated declaration
when a name is reopened as the other kind.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Constant lookup needs constant entries, and Ruby's Environment rejects
a constant that shares a name with a class or module.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ruby keeps module aliases in the same constant name space as classes,
modules and constants, so `module Foo = Kernel` followed by
`module Foo` or `Foo: String` must raise a duplication error.

module_entry now returns ModuleLookup since an alias has no ModuleEntry.
class_entry is unchanged until class aliases are registered.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Skipping them let a class, module, constant or module alias reuse an
alias name undetected, and class_entry could not see an alias, unlike Ruby.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comments restating what the code does drift from it; the code and test
names already say that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Type name and string IDs are already xxh3 hashes, so the interners now
use IdHasher instead of re-hashing with SipHash. concat skips the
segments Vec for single-segment names, the common case.

Most classes and modules are declared once, so Entry keeps the first
declaration inline and allocates only for reopenings. primary_decl is
fixed at registration instead of scanning declarations on every call,
which also lets it drop the &Environment argument.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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