Skip to content

Conversation

@jez
Copy link
Collaborator

@jez jez commented Dec 17, 2025

Motivation

This change makes CFG builder directly desugar a ClassDef::rhs, without first
needing to collect all code into MethodDef bodies.

This should be a performance optimization on its own, because it means we do one
less traversal of the tree and don't do all the allocating/moving/sorting of
classes.

It also removes the last place where we are mutating the trees post resolver,
which means after this we can start caching the resolved trees. Another alternative I considered to achieve this was to simply move class_flatten into resolve, but that would mean bloating the blocking Typechecking... time, preventing us from getting to Typechecking in background... sooner.

The other thing that class_flatten did was to remove all the ClassDef
nesting structure. It's not clear that we necessarily need that. The only thing
I could think it would do is a performance optimization in stack depth of the
definition_validator and CFGCollectorAndTyper traversals? But the absolute
amount of code that would need to be traversed doesn't change, so I'm not sure
that matters in practice.

Test plan

See included automated tests.

  • @jez Double check whether this affects definition_validator

Base automatically changed from jez-static-init to master December 17, 2025 22:24
@jez jez force-pushed the jez-no-static-init branch from 0c4b1bf to 7ccd8f3 Compare December 18, 2025 19:25
jez added 9 commits December 18, 2025 11:37
This doesn't actually matter for us, because we don't allow putting a
sig on a `<static-init>` and thus you can't actually use the result
of evaluating a class def.

But I'm working on a change that removes class_flatten, and it's easier
to model the "true" Ruby behavior where the last thing is returned, than
it is to model the current behavior. So for the sake of showing the
change to the exp files, I want to make this as a separate change.
@jez jez force-pushed the jez-no-static-init branch from 7ccd8f3 to d4e1edc Compare December 18, 2025 19:49
@jez
Copy link
Collaborator Author

jez commented Dec 18, 2025

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_Td3LgyKRdDigej
https://go/builds/bui_Td3L31ArCRis6J
https://go/builds/bui_Td3LbTlDv8dRiu

@jez jez force-pushed the jez-no-static-init branch from d4e1edc to 49be9e7 Compare December 18, 2025 19:58
@jez jez marked this pull request as ready for review December 18, 2025 19:58
@jez jez requested a review from a team as a code owner December 18, 2025 19:58
@jez jez requested review from elliottt and removed request for a team December 18, 2025 19:58
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.

2 participants