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

Do not pass T.untyped to ObjectSpace::WeakMap #1303

Merged
merged 5 commits into from
Dec 14, 2022

Conversation

LTe
Copy link
Contributor

@LTe LTe commented Dec 12, 2022

Motivation

In sorbet/sorbet#6610 type_member changed from out to fixed: T.untyped. From this point we should not pass explicit T.untyped as argument to generic type.

Implementation

There is no need to special case for ObjectSpace::WeakMap anymore.

Tests

I added specs

In sorbet/sorbet#6610 type_member changed from
`out` to `fixed: T.untyped`. From this point we should not pass explicit
`T.untyped` as argument to generic type.
@LTe LTe requested a review from a team as a code owner December 12, 2022 08:33
@LTe LTe changed the title Do not pass T.untyped to ObjectSpace::WeakMap Do not pass T.untyped to ObjectSpace::WeakMap Dec 12, 2022
lib/tapioca/gem/pipeline.rb Outdated Show resolved Hide resolved
spec/tapioca/gem/pipeline_spec.rb Show resolved Hide resolved
Adds support for using `ObjectSpace::WeakMap` without
a generic type argument. This change is guarded by a
check for the availability of a specific Sorbet
feature (`non_generic_weak_map`), which is required
for this change to be applied. This update allows
Tapioca to use the non-generic version of `WeakMap`
when running on a version of Sorbet that supports it,
while still providing support for earlier versions that
require the generic type argument.
Copy link
Collaborator

@Morriar Morriar left a comment

Choose a reason for hiding this comment

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

Very nice!

I wonder if we could add two tests under spec/tapioca/cli/gem_spec where we install different versions of Sorbet and check the output.

Something like this:

        it "generates `ObjectSpace::WeakMap` as a generic type with Sorbet < X.Y.Z" do
          foo = mock_gem("foo", "0.0.1") do
            write("lib/foo.rb", <<~RB)
              Foo = ObjectSpace::WeakMap.new
            RB
          end
          @project.require_mock_gem(foo)
          @project.require_real_gem("sorbet-static", "X.Y.Z")
          @project.bundle_install
          result = @project.tapioca("gem")
          assert_project_file_equal("sorbet/rbi/gems/foo@0.0.1.rbi", <<~RBI)
             Foo = T.let(T.unsafe(nil), ObjectSpace::WeakMap[T.untyped])
          RBI
        end

        it "generates `ObjectSpace::WeakMap` as a non-generic type with Sorbet >= X.Y.Z" do
          foo = mock_gem("foo", "0.0.1") do
            write("lib/foo.rb", <<~RB)
              Foo = ObjectSpace::WeakMap.new
            RB
          end
          @project.require_mock_gem(foo)
          @project.require_real_gem("sorbet-static", "X.Y.Z")
          @project.bundle_install
          result = @project.tapioca("gem")
          assert_project_file_equal("sorbet/rbi/gems/foo@0.0.1.rbi", <<~RBI)
             Foo = T.let(T.unsafe(nil), ObjectSpace::WeakMap)
          RBI
        end

Copy link
Contributor

@KaanOzkan KaanOzkan left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR and the prompt back and forth.

Copy link
Collaborator

@Morriar Morriar left a comment

Choose a reason for hiding this comment

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

Thank you for adding the other test 🙏

This allows us to run a before block that sets the mock project without
a strict Sorbet version dependency, and an after block to cleanup that
project afterwards.
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

Thank you! The work in this PR is very much appreciated. ❤️

@paracycle paracycle merged commit 062c5d6 into Shopify:main Dec 14, 2022
@shopify-shipit shopify-shipit bot temporarily deployed to production December 19, 2022 22:14 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants