-
Notifications
You must be signed in to change notification settings - Fork 131
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
Stop generating more methods than necessary #293
Open
paracycle
wants to merge
12
commits into
main
Choose a base branch
from
uk-method-generation-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0d40ba9
Stop generating more methods than necessary
paracycle d385919
Write failing test for case where dynamic method definition is incorr…
egiurleo b596f3d
Attribute method definitions to the gem that triggers them
egiurleo ceb831f
Unlock the rbtrace version
paracycle f0094a4
Start tracking line numbers for method definitions
paracycle abd979a
Allow resolved locs to be `nil` to handle C-extension/native methods
paracycle 0e73b24
Add method definition tracking for singleton methods
paracycle 0a0de3a
Change the way we store method definitions to disambiguate aliases
paracycle 2e771ae
Do not process method redefinitions triggered by Sorbet runtime
paracycle c1d05c8
Regenerate gem RBI files
paracycle a11f4ce
Pin minitest to < 5.25.0
paracycle 862f422
Change how method definitions are stored and retrieved
paracycle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,10 +71,30 @@ def compile_directly_owned_methods( | |
def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public.new) | ||
return unless method | ||
return unless method_owned_by_constant?(method, constant) | ||
return if @pipeline.symbol_in_payload?(symbol_name) && [email protected]_in_gem?(method) | ||
|
||
signature = lookup_signature_of(method) | ||
method = T.let(signature.method, UnboundMethod) if signature | ||
begin | ||
signature = signature_of!(method) | ||
method = T.let(signature.method, UnboundMethod) if signature | ||
|
||
case @pipeline.method_in_gem?(method) | ||
when nil | ||
# This means that this is a C-method. Thus, we want to | ||
# skip it only if the constant is an ignored one, since | ||
# that probably means that we've hit a C-method for a | ||
# core type. | ||
return if @pipeline.symbol_in_payload?(symbol_name) | ||
when false | ||
# Do not process this method, if it is not defined by the current gem | ||
return | ||
end | ||
rescue SignatureBlockError => error | ||
@pipeline.error_handler.call(<<~MSG) | ||
Unable to compile signature for method: #{method.owner}##{method.name} | ||
Exception raised when loading signature: #{error.cause.inspect} | ||
MSG | ||
|
||
signature = nil | ||
end | ||
|
||
method_name = method.name.to_s | ||
return unless valid_method_name?(method_name) | ||
|
@@ -211,18 +231,6 @@ def initialize_method_for(constant) | |
def ignore?(event) | ||
event.is_a?(Tapioca::Gem::ForeignScopeNodeAdded) | ||
end | ||
|
||
sig { params(method: UnboundMethod).returns(T.untyped) } | ||
def lookup_signature_of(method) | ||
signature_of!(method) | ||
rescue LoadError, StandardError => error | ||
@pipeline.error_handler.call(<<~MSG) | ||
Unable to compile signature for method: #{method.owner}##{method.name} | ||
Exception raised when loading signature: #{error.inspect} | ||
MSG | ||
|
||
nil | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,15 +129,19 @@ def qualified_name_of(constant) | |
end | ||
end | ||
|
||
SignatureBlockError = Class.new(StandardError) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a |
||
|
||
sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) } | ||
def signature_of!(method) | ||
T::Utils.signature_for_method(method) | ||
rescue LoadError, StandardError | ||
Kernel.raise SignatureBlockError | ||
end | ||
|
||
sig { params(method: T.any(UnboundMethod, Method)).returns(T.untyped) } | ||
def signature_of(method) | ||
signature_of!(method) | ||
rescue LoadError, StandardError | ||
rescue SignatureBlockError | ||
nil | ||
end | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment about
nil
meaning no source location