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 integration #310

Merged
merged 10 commits into from
Mar 14, 2024
Merged

Sorbet integration #310

merged 10 commits into from
Mar 14, 2024

Conversation

kostyanf14
Copy link
Contributor

Please ignore everything from the sorbet folder during a review.

Copy link
Contributor

@akihikodaki akihikodaki left a comment

Choose a reason for hiding this comment

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

It doesn't make sense to check in RBIs when you don't check in gems.

Gemfile Outdated Show resolved Hide resolved
lib/engines/hckinstall/hckinstall.rb Outdated Show resolved Hide resolved
lib/engines/hckinstall/hckinstall.rb Outdated Show resolved Hide resolved
bin/tapioca Outdated Show resolved Hide resolved
lib/engines/hckinstall/hckinstall.rb Outdated Show resolved Hide resolved
lib/engines/hcktest/hcktest.rb Outdated Show resolved Hide resolved
Comment on lines 65 to 95
typecheck:
runs-on: ubuntu-20.04
strategy:
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Update Ubuntu package repository
run: sudo apt-get update
- name: Setup sqlite-devel
run: sudo apt-get -y install libsqlite3-dev
- name: Setup libcurl-devel
run: sudo apt-get -y install libcurl4 libcurl3-gnutls libcurl4-openssl-dev

- name: Set up Ruby 3.1.4
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.4
bundler-cache: false

- name: Install dependencies
run: bundle install

- name: Run sorbet type check
run: bundle exec srb typecheck

Copy link
Contributor

Choose a reason for hiding this comment

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

We already have different jobs for rspec and rubocop, but they actually should be one job; we can save many lines and computation time for setup in that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expect to run all jobs even if one fails. How do you propose to combine it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Add continue-on-error for each of typecheck, rspec, and rubocop. You can later check if all of the steps succeeded.

@akihikodaki
Copy link
Contributor

Thanks for providing a proof of concept. This is very informative.

Having two definitions for one JSON is terrible so we should pick one. I have mixed feelings for Sorbet, but I think the utility of its static type checker supasses its disadvantages.

We can write a converter to Sorbet if we want to write a schema in another language, but it's hard to support Sorbet's static type checker with such a converter. Supporting its runtime type check-ing is easy since we can generate a type definition as Ruby objects on Ruby, but static type checking requires the generated definitions to be saved as Ruby code, and that's very complicated.

The other way around is easy in contrary. If we will have a frontend written in JavaScript and need to consume Sorbet code, we can traverse the types and generate JSON, which is only a matter of calling JSON.dump.

Honestly, I don't like some syntactical aspects of Sorbet; it requires typing T:: a lot, and the enum idiom does not make sense, but I think we can tolerate that.

@kostyanf14
Copy link
Contributor Author

@akihikodaki I don't touch workflow-related commit, I want to investigate the ability to simplify it. As this is not related to Sorbet in general, let's move the deduplication part outside this PR.

@kostyanf14
Copy link
Contributor Author

I think these changes are good enough to start with Sorbet.

If there are no critical problems that we can see now, let's continue in the next way:

  1. merge this PR
  2. remove JTD related code
  3. add models for other objects that we get from JSON
  4. enable typing in other parts of the source

lib/auxiliary/json_helper.rb Outdated Show resolved Hide resolved
sorbet/config Outdated Show resolved Hide resolved
spec/srb_json_load_spec.rb Show resolved Hide resolved
spec/srb_json_load_spec.rb Outdated Show resolved Hide resolved
lib/setupmanagers/qemuhck/qemuhck.rb Outdated Show resolved Hide resolved
@akihikodaki
Copy link
Contributor

I think these changes are good enough to start with Sorbet.

If there are no critical problems that we can see now, let's continue in the next way:

1. merge this PR

2. remove JTD related code

3. add models for other objects that we get from JSON

4. enable typing in other parts of the source

That sounds good to me.

@kostyanf14 kostyanf14 force-pushed the sorbet branch 4 times, most recently from 695ef94 to d5fd9b1 Compare March 6, 2024 12:03
@kostyanf14 kostyanf14 requested a review from akihikodaki March 6, 2024 12:05
@kostyanf14 kostyanf14 changed the title RFC: Sorbet integration Sorbet integration Mar 6, 2024
Copy link
Contributor

@akihikodaki akihikodaki left a comment

Choose a reason for hiding this comment

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

I think we should also run tapioca gems --verify. Their documentation says it breaks Dependabot, but it apparently does not. dependabot-core itself uses Dependabot with Sorbet and it seems just fine: https://github.com/dependabot/dependabot-core/issues?page=3&q=label%3Adependencies+label%3Aruby+is%3Aclosed

lib/auxiliary/json_helper.rb Show resolved Hide resolved
Gemfile Outdated Show resolved Hide resolved
lib/setupmanagers/qemuhck/qemuhck.rb Outdated Show resolved Hide resolved
spec/srb_json_load_spec.rb Show resolved Hide resolved
@kostyanf14
Copy link
Contributor Author

webrick
Please try to remove it and see if it works.

When I update gems and run tapioca gem to regenerate RBIs, tapioca fails with the error webrick is not found. You may need to 'gem install webrick' to install webrick.

@kostyanf14
Copy link
Contributor Author

I think we should also run tapioca gems --verify. Their documentation says it breaks Dependabot, but it apparently does not. dependabot-core itself uses Dependabot with Sorbet and it seems just fine: https://github.com/dependabot/dependabot-core/issues?page=3&q=label%3Adependencies+label%3Aruby+is%3Aclosed

I think they mean this problem dependabot/dependabot-core#5962. Need to download tapioca definitions after updating a gem.

@akihikodaki
Copy link
Contributor

I think we should also run tapioca gems --verify. Their documentation says it breaks Dependabot, but it apparently does not. dependabot-core itself uses Dependabot with Sorbet and it seems just fine: https://github.com/dependabot/dependabot-core/issues?page=3&q=label%3Adependencies+label%3Aruby+is%3Aclosed

I think they mean this problem dependabot/dependabot-core#5962. Need to download tapioca definitions after updating a gem.

Yes, what I don't get is that https://github.com/dependabot/dependabot-core/ doesn't have such code yet it seems working.

@akihikodaki
Copy link
Contributor

webrick
Please try to remove it and see if it works.

When I update gems and run tapioca gem to regenerate RBIs, tapioca fails with the error webrick is not found. You may need to 'gem install webrick' to install webrick.

Excluding rdoc fixed the error. Add it to sorbet/tapioca/config.yml and note that RDoc::Servlet needs webrick, which we don't have.

Copy link
Contributor

@akihikodaki akihikodaki left a comment

Choose a reason for hiding this comment

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

Things I have pointed out earlier are all correctly resolved. I still have a few comments though.

Gemfile Outdated Show resolved Hide resolved
spec/srb_json_load_spec.rb Outdated Show resolved Hide resolved
spec/srb_json_load_spec.rb Outdated Show resolved Hide resolved
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
@kostyanf14 kostyanf14 merged commit 5dbc025 into HCK-CI:master Mar 14, 2024
6 checks passed
@kostyanf14 kostyanf14 deleted the sorbet branch March 14, 2024 09:33
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.

3 participants