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: Autogenerate the RBI file for utils/tty.rb #14896

Merged
merged 2 commits into from
Mar 7, 2023

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Mar 6, 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?

  • Sort of. It's not via Parlour, because I read the docs and all it says about dynamically generating things is "of course it's better to do that", no examples. I tried my best, but Bo's work on attr.rb was mind-boggling.
  • Instead, let's add a simple but functional generator script that I actually understand, as an alternative to maintaining these RBI files for dynamic methods manually, or as an alternative to skipping them entirely, so that we can get rid of some use of srb rbi hidden-definitions since that's deprecated.
  • Follow up to sorbet: Convert some hidden-definitions into RBI files #14651.

  • TODO (if this is the direction we want to go): Run this script as part of brew typecheck --update so it gets updated with all the other RBI files periodically.

  • Feel free to throw this away if this isn't the direction we want to go or if it's rubbish and/or not the Proper Way - no hard feelings! ❤️

@issyl0 issyl0 requested a review from Bo98 March 6, 2023 00:08
@BrewTestBot
Copy link
Member

Review period will end on 2023-03-07 at 00:08:08 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 6, 2023
@Bo98
Copy link
Member

Bo98 commented Mar 6, 2023

I tried my best, but Bo's work on attr.rb was mind-boggling.

Yes I agree.

The Parlour way makes sense on a technical sense as it's the way Sorbet does it - i.e. parsing an AST. However parsing AST is always not the easiest to understand. With Rubocop there's some AST stuff but we've built a few helper functions on top still.

An alternative way (i.e. like how Tapioca does it) would be runtime generation. It's sometimes a bit more "hacky" (i.e. for attr you would inject something that listens into attr_* as there's no way to get a list of attributes at runtime otherwise) but will in the end be easier to understand. I'll try rewrite attr.rb to do it that way soon which will hopefully mean it's more understandable by others.

The way you're doing here is not far off that so it makes sense to me, even as is.

@MikeMcQuaid
Copy link
Member

  • Run this script as part of brew typecheck --update so it gets updated with all the other RBI files periodically.

Agreed!

The way you're doing here is not far off that so it makes sense to me, even as is.

Good to know, happy to merge given that!

issyl0 added 2 commits March 6, 2023 21:46
- Sort of. It's not via Parlour, because I read the docs and all it says
  about dynamically generating things is "of course it's better to do
  that", no examples. I tried my best, but Bo's work on `attr.rb` was
  mind-boggling.
- Instead, let's add a simple but functional generator script that I
  actually understand, as an alternative to maintaining these RBI files
  for dynamic methods manually, so that we can get rid of some use of
  `srb rbi hidden-definitions` since that's deprecated.
- TODO: Run this script as part of `brew typecheck --update` so it gets
  updated with all the other RBI files periodically.
- Follow up to PR 14651.
- I needed to add some more `require`s to the `tty.rb` generator script
  since it failed to recognise `env_config` and Sorbet's `T` setup if I
  ran it not via `brew ruby`, and I couldn't get `brew ruby` to work
  within `safe_system` in the `typecheck` dev-cmd.
@issyl0 issyl0 force-pushed the sorbet-autogenerate-tty-rbi branch from 0522498 to 48802da Compare March 6, 2023 21:46
@issyl0 issyl0 marked this pull request as ready for review March 6, 2023 21:57
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 7, 2023
@BrewTestBot
Copy link
Member

Review period ended.

@MikeMcQuaid
Copy link
Member

Thanks again @issyl0!

@MikeMcQuaid MikeMcQuaid merged commit a6b70ee into Homebrew:master Mar 7, 2023
@issyl0 issyl0 deleted the sorbet-autogenerate-tty-rbi branch March 7, 2023 09:48
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 7, 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.

4 participants