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

Make Class generic in its attached class #6781

Merged
merged 43 commits into from
May 11, 2023
Merged

Make Class generic in its attached class #6781

merged 43 commits into from
May 11, 2023

Conversation

jez
Copy link
Collaborator

@jez jez commented Feb 25, 2023

Motivation

Fixes #62

image

Test plan

See included automated tests.

@jez
Copy link
Collaborator Author

jez commented Feb 25, 2023

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_NQ7H7u7bqmkoBn
https://go/builds/bui_NQ7HuiDQ7RT2pS

@jez
Copy link
Collaborator Author

jez commented Feb 25, 2023

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_NQ8JRPoOUUAqBB
https://go/builds/bui_NQ8JB0qGZRz75G

@jez
Copy link
Collaborator Author

jez commented Feb 25, 2023

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_NQ8UKcD7YkM3Ik
https://go/builds/bui_NQ8Ub0iogoeZVx

@jez jez force-pushed the jez-attachable branch 2 times, most recently from 7384135 to 651b14a Compare March 31, 2023 21:45
Base automatically changed from jez-attachable to master April 5, 2023 17:22
@jez jez force-pushed the jez-t-class branch 2 times, most recently from 6d250f6 to ee5222d Compare April 30, 2023 21:25
@jez jez changed the base branch from master to jez-legacy-stdlib April 30, 2023 22:05
@jez
Copy link
Collaborator Author

jez commented Apr 30, 2023

Base automatically changed from jez-legacy-stdlib to master May 3, 2023 20:07
@jez jez changed the title wip: T::Class Make Class generic in its attached class May 3, 2023
@jez jez marked this pull request as ready for review May 3, 2023 22:32
@jez jez requested a review from a team as a code owner May 3, 2023 22:32
@jez jez requested review from neilparikh and removed request for a team May 3, 2023 22:32
namer/namer.cc Outdated
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changes in here are one of the subtle points—previously we used rewriter to say "you can only do this in a module" but now we use namer. It still shows up correctly on the fast path, but shows up in a place where we can allow Symbols::Class as the one class that allows this too (no other classes).

Comment on lines 72 to 75
extend T::Generic
has_attached_class!(:out)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The hard part of this change is just two lines. (before has_attached_class!, this change involved a lot of work and scoping).

@jez jez mentioned this pull request May 3, 2023
Comment on lines 1955 to 1959
// TODO(jez) After T::Class change:
// We have some weird handling for `initialize` in dispatchCallSymbol to avoid reporting
// "method does not exist" error. We can simply delete that, and check
// `res.main.method.exists()` and only report the res.main.errors if we actually dispatched
// to a real `initialize` method.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related: we can delete the SelfNew intrinsic after this T::Class of PR

#6978

Comment on lines +1023 to +1032
// TODO(jez) After T::Class change: fix the payload, fix all the codebases, and remove this check.
// (Leaving at least one version in between, so that there is a published version that
// supports both `Class` and `T::Class` as valid syntax.)
if (klass != core::Symbols::Class() &&
(klass.isBuiltinGenericForwarder() || klass.data(ctx)->typeArity(ctx) > 0)) {
// Class is not isLegacyStdlibGeneric (because its type members don't default to T.untyped),
// but we want to report this syntax error at `# typed: strict` like other stdlib classes.
auto level = klass.isLegacyStdlibGeneric() || klass == core::Symbols::Class()
? core::errors::Resolver::GenericClassWithoutTypeArgsStdlib
: core::errors::Resolver::GenericClassWithoutTypeArgs;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should let users incrementally migrate, so there will be at least one version published that allows T::Class but does not require it.

jez added 12 commits May 10, 2023 17:30
I don't think that this refactoring is worth doing. I spent a few
minutes looking more carefully at it and decided it wasn't going to work
the way I had expected it might.
@jez jez merged commit d94b3e0 into master May 11, 2023
@jez jez deleted the jez-t-class branch May 11, 2023 23:45
@elliottt
Copy link
Contributor

This is so cool!

egiurleo added a commit to Shopify/rbi-central that referenced this pull request Jun 12, 2023
Sorbet now considers `Class` to be a generic
(sorbet/sorbet#6781), which means that
annotations continuing to use the bare `Class` in type signatures will
cause type checking errors on newer versions of Sorbet.
ilyailya pushed a commit that referenced this pull request Sep 6, 2023
* wip: Relax constraint that `initializable!` can only be in module

* Add T::Class

* wip

* wip

* Fix Object#class

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Fixup tests

* wip

* wip

* wip

* wip

* Remove special case

* fixup

* Write the docs

* Add another test

* wip

* update cli tests

* wip

* update exp files

* wip

* Actually, delete this TODO

I don't think that this refactoring is worth doing. I spent a few
minutes looking more carefully at it and decided it wasn't going to work
the way I had expected it might.

* Fix rubocop

* Code review fixes

* Forgot to implement a T::Types::Base method

* Fix the tests

* Another subtyping problem

* I write so many of these
paracycle added a commit to Shopify/tapioca that referenced this pull request Dec 20, 2023
Since sorbet/sorbet#6781 was merged and released as 0.5.10820, we no longer need to check for the existence of generic class support in Sorbet. Since we are moving to >= 0.5.10820, we can remove all code related to the `generic_class` flag.
paracycle added a commit to Shopify/tapioca that referenced this pull request Dec 20, 2023
Since sorbet/sorbet#6781 was merged and released as 0.5.10820, we no longer need to check for the existence of generic class support in Sorbet. Since we are moving to >= 0.5.10820, we can remove all code related to the `generic_class` flag.
@jez jez added this to the Module metaprogramming milestone Aug 4, 2024
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.

Build T::Class[AttachedClass]
3 participants