Skip to content
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

sorbet: Convert some hidden-definitions into RBI files #14651

Closed

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Feb 16, 2023

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

  • Inspired by @dduugg's recent Sorbet work, I thought I'd start paring down the srb rbi hidden-definitions file by adding RBI files for dynamically generated methods.
  • The srb rbi hidden-definitions command is deprecated and we've tried removing it before, but the outcome was that we needed to write more RBI files and it wasn't a massive priority. Tonight I had (a little) desire to start this, with the help of a hacky script.

- Start decreasing the amount of stuff in the deprecated
  `srb rbi hidden-definitions` file.
- Generated with a script I wrote, nothing fancy like Tapioca.
- As with every time we add a new `Homebrew::CLI::Args` method, when we add a
  new colour or something here, we'll have to edit this RBI file when we get a
  Sorbet error.
- Start decreasing the amount of stuff in the deprecated
  `srb rbi hidden-definitions` file.
- Generated with a script I wrote, nothing fancy like Tapioca.
- As with every time we add a new `Homebrew::CLI::Args` method, when we add a
  new envvar or something here, we'll have to edit this RBI file when we get a
  Sorbet error.
@BrewTestBot
Copy link
Member

Review period will end on 2023-02-17 at 01:06:39 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Feb 16, 2023
@dduugg
Copy link
Member

dduugg commented Feb 16, 2023

Neat!

One suggestion, if we're going to start building out large rbi files, would be a test that ensures they stays in sync with their source. Maybe something like (pseudocode-ish):

methods_before = Homebrew::EnvConfig.methods
require_relative `Library/Homebrew/env_config.rbi`
methods_after = Homebrew::EnvConfig.methods
expect(methods_after - methods_before).to be_empty

wdyt?

@Bo98
Copy link
Member

Bo98 commented Feb 16, 2023

One suggestion, if we're going to start building out large rbi files, would be a test that ensures they stays in sync with their source.

tbh we should probably just auto gen the rbi files. I can have a look given I did the one for attr_predicate and attr_rw.

Comment on lines 3 to +5
module Homebrew::EnvConfig
sig { returns(String) }
def self.additional_google_analytics_id; end
Copy link
Member

Choose a reason for hiding this comment

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

Agreed with @Bo98: it'd be really nice to autogenerate these.

Copy link
Member Author

@issyl0 issyl0 Feb 16, 2023

Choose a reason for hiding this comment

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

Yeah, no idea how to do that that's not my super hacky script. I'm assuming there's a more Sorbet-native way. Can @Bo98 or @dduugg teach us?

Copy link
Member

Choose a reason for hiding this comment

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

Now that 4.0.0 is out I can have a look at this.

Copy link
Member

@Bo98 Bo98 Feb 17, 2023

Choose a reason for hiding this comment

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

Will have something to show by Monday. I would point to the existing sorbet/parlour/attr.rb, but parser code isn't always the easiest to follow so I'm looking to see if I can write that as a runtime generator rather than a static generator. Hardly anything we use supports Ruby 2.6 anymore (last Rubocop update is in about 6 weeks) so will need to see what is and isn't available for us on the versions we have.

@issyl0
Copy link
Member Author

issyl0 commented Feb 16, 2023

Can we merge this as-is (since it's identical to any automatic generation) and work on the autogeneration separately? I recognise the manual process is non-ideal, but it was vaguely fun last night and whatever we write next can be done by the Sorbet action or whatever, and replace my fingers.

@MikeMcQuaid
Copy link
Member

Can we merge this as-is (since it's identical to any automatic generation)

Will this still be automatically updated when we e.g. change env_config.rb? If so: yes, if not: no 😁

@issyl0
Copy link
Member Author

issyl0 commented Feb 16, 2023

Will this still be automatically updated when we e.g. change env_config.rb? If so: yes, if not: no 😁

Oh. No. 😁 But brew typecheck will fail and someone will add the method to the RBI file (same as with the current https://github.com/Homebrew/brew/blame/master/Library/Homebrew/cli/args.rbi#L339-L340, for example).

@MikeMcQuaid
Copy link
Member

Sorry @issyl0, this feels like a step back if it's adding more manual work that was previously done by CI 😭

@issyl0
Copy link
Member Author

issyl0 commented Feb 16, 2023

I'd argue that it's still moving us forward because rbi hidden-definitions is deprecated and moving off it in any way (while adding better type information than just Sorbet's "don't know, shrug") is better. But OK, I'd like to learn how to write RBI generators for dynamic methods anyway so this is a good excuse.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Feb 17, 2023
@BrewTestBot
Copy link
Member

Review period ended.

@issyl0 issyl0 closed this Feb 17, 2023
@issyl0 issyl0 deleted the start-trimming-srb-hidden-definitions branch February 17, 2023 17:21
@github-actions github-actions bot added the outdated PR was locked due to age label Mar 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants