Skip to content

Ruby: split standard library models into multiple files #7886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 21, 2022

Conversation

hmac
Copy link
Contributor

@hmac hmac commented Feb 8, 2022

Split the classes modeling various standard library concepts into a
structured group of multiple files.

Things that are part of the core language live in libraries/core and
standard libraries (that aren't part of core) live in libraries/stdlib. In future we may want to add libraries/gems to hold third-party libraries. At the moment these live as separate files at the libraries level.

This mirrors the structure followed by the Ruby docs
(https://docs.ruby-lang.org/en/3.1/).

This PR is split up into multiple commits so it's easier to review. As a result, the intermediate commits will not build, but it should make reviewing a lot easier.

The last two commits are optional: they rename the frameworks directory to libraries, since I think that better describes its contents. This does churn many import paths, so I'm happy to drop this if you think it's too disruptive.

Base automatically changed from nickrolfe/array_flow_summaries to main February 9, 2022 09:58
@hmac hmac force-pushed the hmac/split-ruby-std-library branch 6 times, most recently from dbc3112 to 55ca8e0 Compare February 13, 2022 22:23
@hmac hmac marked this pull request as ready for review February 14, 2022 04:58
@hmac hmac requested a review from a team as a code owner February 14, 2022 04:58
@hmac hmac added the no-change-note-required This PR does not need a change note label Feb 14, 2022
Copy link
Contributor

@alexrford alexrford left a comment

Choose a reason for hiding this comment

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

This is generally really nice and makes things much neater.

I'm conflicted on the frameworks -> libraries rename. It seems more accurate as to what we're actually modelling, but JS and Python generally bundle up both frameworks and libraries under the frameworks umbrella term. I also have some fears about breaking external queries and libraries that currently import QLLs that are moved or deleted in this PR.

On balance I'd personally prefer to keep these under frameworks for consistency with other languages.

For similar reasons of avoiding breaking external queries, we might want to keep a version of frameworks/StandardLibrary.qll around that re-exports public modules/classes/predicates of Core.qll and Stdlib.qll as deprecated versions. Ideally we would just be able to mark StandardLibrary.qll itself as deprecated, but I'm not aware of a simple way to do this.

Comment on lines 8 to 13
import core.BasicObject::BasicObject
import core.Object::Object
import core.Kernel::Kernel
import core.Module
import core.Array
import core.Regexp
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the criteria for importing the module within a QLL (e.g. core.Kernel::Kernel) vs. the QLL itself (e.g. core.Module)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I did this was to reduce churn in other files that previously imported StandardLibrary.qll and then used the classes directly. I can add a followup commit that explicitly imports the required modules in those files, and then change these imports back to import core.Object; import core.Kernel. Maybe that would be better as a followup, to avoid piling too many things in this PR? What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Having this as a followup sounds good to me.

@nickrolfe
Copy link
Contributor

I guess this is going to clash with #7878, but I'm not sure how soon that PR is going to be in a mergeable state.

@hmac
Copy link
Contributor Author

hmac commented Feb 14, 2022

I added the no-change-note-required label because this PR doesn't change any queries, but perhaps it would be useful to add a change note about StandardLibrary being deprecated?

@hmac hmac force-pushed the hmac/split-ruby-std-library branch from 002286d to b125fc0 Compare February 14, 2022 21:20
@hmac hmac force-pushed the hmac/split-ruby-std-library branch from 892a9c4 to 89d2879 Compare February 14, 2022 22:34
@asgerf
Copy link
Contributor

asgerf commented Feb 15, 2022

I guess this is going to clash with #7878, but I'm not sure how soon that PR is going to be in a mergeable state.

FWIW don't let the existence of that PR slow you down. I'm confident I can resolve conflicts efficiently on my end, and I'd be happy to help resolve conflicts in other PRs once mine is merged.

@nickrolfe
Copy link
Contributor

If I understood correctly, sticking with the frameworks name will be the less disruptive option. I don't find myself strongly preferring either name over the other, so I guess I vote weakly for frameworks.

@hmac
Copy link
Contributor Author

hmac commented Feb 17, 2022

OK, let's go with frameworks.

hmac added 6 commits February 17, 2022 20:44
Split the classes modeling various standard library concepts into a
structured group of multiple files.

Things that are part of the core language live in framworks/core and
standard libraries (that aren't part of core) live in frameworks/stdlib.

This mirrors the structure followed by the Ruby docs
(https://docs.ruby-lang.org/en/3.1/).

Tests are split in a followup commit.
codeql.ruby.frameworks.StandardLibrary is deprecated
This file re-exports everything it used to define, marking each as
deprecated to warn users that they should import `Core` or `Stdlib`
instead.
@hmac hmac force-pushed the hmac/split-ruby-std-library branch from 89d2879 to bfd2c14 Compare February 17, 2022 07:44
alexrford
alexrford previously approved these changes Feb 17, 2022
Copy link
Contributor

@alexrford alexrford left a comment

Choose a reason for hiding this comment

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

The test output needs to be regenerated, otherwise LGTM.

@hmac
Copy link
Contributor Author

hmac commented Feb 20, 2022

Ugh that's so annoying! I thought this was ready to go...

Copy link
Contributor

@alexrford alexrford left a comment

Choose a reason for hiding this comment

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

👍

@hmac hmac merged commit e4f801b into main Feb 21, 2022
@hmac hmac deleted the hmac/split-ruby-std-library branch February 21, 2022 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation no-change-note-required This PR does not need a change note Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants