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

Stop generating more methods than necessary #293

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Apr 23, 2021

  1. Stop generating more methods than necessary

    We used to treat methods that didn't have a source location the same as
    methods that explicitly were not defined in the current gem. That
    resulted in Tapioca creating more method definitions than necessary.
    
    We would only skip method generation for a method if the constant it was
    on was an ignored type (i.e. a built-in type), so that we wouldn't keep
    redefining methods for built-in types. However, for all other types,
    especially types that come from other gems, we would just keep on
    generating all the methods regardless of if they were defined by this
    gem or not.
    
    Moreover, the source location check was happening at the wrong location,
    before unwrapping the method signature. Thus, many methods with
    signatures would not be generated when the previous problem was fixed,
    since our code would see them as being defined in Sorbet runtime.
    
    The fix is to return a more fine-grained result from `method_in_gem?`
    which signals yes/no/don't-have-source-location. Based on that we can
    skip generating don't-have-source-location cases if they are for
    built-in types and totally ignore the methods that have a source
    location and are definitely not defined in the current gem.
    
    Additionally, if we try to unwrap the method signature and we get an
    exception, that means the signature block raised an error. If we
    continue with the method as is, the source location checks would think
    the method definition does not belong in the gem (since the method is
    still wrapped), and we would thus skip the method generation. To avoid
    that, the `signature_for` method is not raising a custom exception to
    signal that exceptional case, so that we can at least continue
    generating "a" method definition.
    paracycle committed Apr 23, 2021
    Configuration menu
    Copy the full SHA
    593bfa7 View commit details
    Browse the repository at this point in the history