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

Remove use of hidden-definitions #16586

Merged
merged 15 commits into from Feb 12, 2024
Merged

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Feb 5, 2024

  • 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?

Resolves #16557

This also reduces the time to run brew typecheck --update-all by > 30% (5m7s → 3m31s on an M1 Pro, n=4)

@dduugg dduugg marked this pull request as draft February 5, 2024 06:10
@dduugg dduugg changed the title No hidden RBI Remove use of hidden-definitions Feb 5, 2024
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good so far!

@dduugg dduugg force-pushed the no-hidden-rbi branch 2 times, most recently from a7961a5 to 515b9bc Compare February 9, 2024 20:21
Library/Homebrew/Gemfile Show resolved Hide resolved
Library/Homebrew/rubocops/cask/extend/node.rb Show resolved Hide resolved
# This is an autogenerated file for dynamic methods in `RuboCop::Cop::FormulaAudit::AssertStatements`.
# Please instead update this file by running `bin/tapioca dsl RuboCop::Cop::FormulaAudit::AssertStatements`.

class RuboCop::Cop::FormulaAudit::AssertStatements; end
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Note that there are 21 rbi files that are useless that are introduced in this PR. It might be possible to make the dsl compiler logic smarter (I would need a class source API, like the method_source gem we rely on for methods) to avoid this. (The initial attempt used a hard-coded list to avoid this, which I also don't like.)

I think that tapioca should maybe not create rbi files when no action is taken in the decorator, so I might try filing an issue upstream first.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that tapioca should maybe not create rbi files when no action is taken in the decorator, so I might try filing an issue upstream first.

That's what I would expect it to do too.

@@ -1,319 +0,0 @@
# typed: false
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

This is unrelated to the scope of the PR, but Tapioca ends up setting this to typed: false, bc it conflicts with the source rbi file in sorbet itself. We can just exclude it from generation (as we do with json for the same reason).

@dduugg dduugg marked this pull request as ready for review February 9, 2024 20:29
Copy link
Contributor

@apainintheneck apainintheneck left a comment

Choose a reason for hiding this comment

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

Code looks good and it's great that we don't have to exclude and/or create by hand as many RBI files anymore. I left a bunch of nits but, of course, feel free to ignore them.

Library/Homebrew/sorbet/tapioca/compilers/rubocop.rb Outdated Show resolved Hide resolved
Library/Homebrew/formula_cellar_checks.rb Show resolved Hide resolved
# This is an autogenerated file for dynamic methods in `RuboCop::Cop::FormulaAudit::AssertStatements`.
# Please instead update this file by running `bin/tapioca dsl RuboCop::Cop::FormulaAudit::AssertStatements`.

class RuboCop::Cop::FormulaAudit::AssertStatements; end
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that tapioca should maybe not create rbi files when no action is taken in the decorator, so I might try filing an issue upstream first.

That's what I would expect it to do too.

Library/Homebrew/sorbet/tapioca/compilers/rubocop.rb Outdated Show resolved Hide resolved
Comment on lines 43 to 66
if source.start_with?("def_node_matcher")
# https://github.com/Shopify/tapioca/blob/3341a9b/lib/tapioca/rbi_ext/model.rb#L89
klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "RuboCop::AST::Node"),
create_kw_rest_param("kwargs", type: "T.untyped"),
create_block_param("block", type: "T.untyped"),
],
return_type: "T.untyped",
)
elsif source.start_with?("def_node_search")
klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "T.untyped"),
create_block_param("block", type: "T.untyped"),
],
return_type: method_name.to_s.end_with?("?") ? "T::Boolean" : "T.untyped",
)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if source.start_with?("def_node_matcher")
# https://github.com/Shopify/tapioca/blob/3341a9b/lib/tapioca/rbi_ext/model.rb#L89
klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "RuboCop::AST::Node"),
create_kw_rest_param("kwargs", type: "T.untyped"),
create_block_param("block", type: "T.untyped"),
],
return_type: "T.untyped",
)
elsif source.start_with?("def_node_search")
klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "T.untyped"),
create_block_param("block", type: "T.untyped"),
],
return_type: method_name.to_s.end_with?("?") ? "T::Boolean" : "T.untyped",
)
end
case source
when /^def_node_matcher/
# https://github.com/Shopify/tapioca/blob/3341a9b/lib/tapioca/rbi_ext/model.rb#L89
klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "RuboCop::AST::Node"),
create_kw_rest_param("kwargs", type: "T.untyped"),
create_block_param("block", type: "T.untyped"),
],
return_type: "T.untyped",
)
when /^def_node_search/
klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "T.untyped"),
create_block_param("block", type: "T.untyped"),
],
return_type: method_name.to_s.end_with?("?") ? "T::Boolean" : "T.untyped",
)
end

Nit: Use a case statement here for readability.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

The version without regexes is more readable IMO, but sure 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, either way. It's personal preference I guess.

@@ -192,7 +192,7 @@ def depends_on(spec)
def uses_from_macos(deps, bounds = {})
if deps.is_a?(Hash)
bounds = deps.dup
deps = [bounds.shift].to_h
deps = [T.unsafe(bounds).shift].to_h
Copy link
Member

Choose a reason for hiding this comment

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

Can we just add a sig here instead?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

LMK if you have ideas, but i think it gets gnarly with type parameters and union types (and I think it would need to be in an rbi file due to the former). I think it's something I'd prefer to leave to a future PR (I'm thinking of doing a sweep over the T.unsafe call sites at some point anyway).

Copy link
Member

Choose a reason for hiding this comment

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

I think you can use multiple sigs.

Copy link
Member

Choose a reason for hiding this comment

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

sig { params(deps: String, bounds: T::Hash[String, T.any(Symbol, T::Array[Symbol])]).void }
sig { params(deps: T::Hash[String, T.any(Symbol, T::Array[Symbol])]).void }
def uses_from_macos(deps, bounds = {})

Actually, I think we don't even need the bounds parameter:

sig { params(deps: T.any(String, T::Hash[String, T.any(Symbol, T::Array[Symbol])])).void }
def uses_from_macos(deps)

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Overloading a method (by providing multiple signatures for the method) is only allowed for methods defined in the Ruby standard library.

Also, all params must be present in a sig.

(As a favor to the PR author, it would be appreciated to validate suggested changes before publishing them. Again, I also worry that there is excessive focus on this line, given the scope of this PR, and it may be better to refine in a future PR.)

Copy link
Member

Choose a reason for hiding this comment

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

As a favor to the PR author, it would be appreciated to validate suggested changes before publishing them.

I usually do, however I reviewed this on mobile.

@dduugg
Copy link
Sponsor Member Author

dduugg commented Feb 10, 2024

PTAL @apainintheneck @reitermarkus

Copy link
Member

@reitermarkus reitermarkus left a comment

Choose a reason for hiding this comment

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

Looks good. Feel free to ignore uses_from_macos in favour of handling this in a future PR.

klass.create_method(
method_name.to_s,
parameters: [
create_rest_param("node", type: "T.untyped"),
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this node is untyped but def_node_matcher's isn't?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Thanks for the nudge here, I was able to tighten up the types in both branches in 439c8c18

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense to me so far!

@MikeMcQuaid MikeMcQuaid merged commit 77e2765 into Homebrew:master Feb 12, 2024
26 checks passed
@dduugg dduugg deleted the no-hidden-rbi branch February 12, 2024 14:55
@github-actions github-actions bot added the outdated PR was locked due to age label Mar 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
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.

Remove use of sorbet's deprecated hidden-definitions
5 participants