Feature #21020
closedSync sig directory for prism of default gem.
Description
Currently, the type signatures (RBS) for the default gem is not available.
Prism is the only default gem with type signatures, but this number is expected to increase in the future.
As a first step to resolving this issue, I propose including the sig directory of Prism as a default gem in the synchronization process.
Updated by kddnewton (Kevin Newton) over 1 year ago
I'm fine with this if everyone else is.
Updated by hsbt (Hiroshi SHIBATA) over 1 year ago
- Status changed from Open to Assigned
- Assignee set to prism
I'm interesting that location of signature with fresh installation of ruby.
The sig directory under the prism is fine if we have only prism signature. Where is the best location if we will add json or psych signatures?
1. $prefix/lib/ruby/3.5.0+0/$name/sig <- current proposal
2. $prefix/lib/ruby/3.5.0+0/sig/$name
3. $prefix/lib/ruby/sig/$name
4. $prefix/lib/ruby/gems/3.5.0+0/sig/$name
5. $GEM_HOME/sig/$name # This is same as 4 with $GEM_HOME is not specified.
6. $prefix/include/sig/$name
7. $prefix/share/sig/$name
...
I prefer 2 or 3.
Updated by Eregon (Benoit Daloze) over 1 year ago
How about $prefix/lib/ruby/gems/3.5.0+0/gems/$name-$version/sig so it would be consistent between default and bundled gems?
Updated by kddnewton (Kevin Newton) over 1 year ago
I think the code in the PR is good, but I agree I don't think the sig should live under prism/sig. I think it should be top directory of ruby repository sig. When it's installed I agree with @Eregon (Benoit Daloze) but I also think @hsbt's solution 2 is fine, provided RBS knows to use the overridden version if one is provided.
Updated by tenderlovemaking (Aaron Patterson) about 1 year ago
- Status changed from Assigned to Feedback
@ksss (Yuki Kurihara) What do you think?
Updated by ksss (Yuki Kurihara) 3 days ago
Sorry for the late reply. I'd like to resume the discussion.
I'd like to install the signatures into the gem directory of each default gem, as @Eregon (Benoit Daloze) suggested in #note-3:
The reasons are:
- rbinstall already creates this directory for every default gem (today it is only used for
exe/). - Bundled gems and gems installed by RubyGems already put their signatures here, so default gems and bundled gems are handled the same way.
- No change is needed in rbs.
RBS::EnvironmentLoaderandrbs collectionlook upsigunderGem::Specification#gem_dirbefore the stdlib signatures bundled with the rbs gem, so the installed signatures take precedence. This also satisfies @kddnewton (Kevin Newton) 's condition in #note-4 that RBS should use the overridden version.
I also considered options 2 and 3 from @hsbt (Hiroshi SHIBATA) 's list, but they would require adding new lookup paths to rbs. In addition, only the gem directory approach lets the signatures of a newer gem take precedence naturally when a default gem is updated with gem update.
In the repository, following @kddnewton (Kevin Newton) 's suggestion, the signatures are synced under the top-level sig/ directory as sig/<gem name>/ (e.g. sig/prism/generated/prism.rbs).
When I opened this issue, prism was the only default gem with type signatures, and the change felt hard to justify for a single gem. Now I see it the other way around. rbs bundles signatures for about 30 default gems in its stdlib/ directory, and to move them into each gem's own repository, ruby/ruby first needs a place to sync and install them. net-http already ships its own sig/, so I included it as well.
I've updated https://github.com/ruby/ruby/pull/12541 with this approach, and verified it with make install (including with DESTDIR), rbs -r <gem> validate and rbs collection install.
While verifying it, I found that prism's signatures on main reference PP without declaring the dependency, and opened https://github.com/ruby/prism/pull/4248 to fix it. Validating the installed signatures after make install makes it possible to catch this kind of problem.