Skip to content

Eager load autoloads that are registered before the RBS rewriter is loaded #2300

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

Merged
merged 2 commits into from
May 30, 2025

Conversation

paracycle
Copy link
Member

We need to eager load all the autoloads registered before we load the RBS rewriter, since we might enter into a weird loop when those constants are used for rewriting, which triggers their autoloads which tries to require their file, which we will try to rewrite, but fail since we need the constant to do the rewriting in the first place.

This is especially important since Prism has a few autoloaded constants whose associated file should NOT be rewritten (since they are needed for the rewriting itself), so should be loaded as early as possible.

Using the AutoloadTracker like this is appropriate since we continue to register autoloads even after the eager_load_all! is triggered, which makes calling eager_load_all! multiple times a safe operation.

We need to eager load all the autoloads registered before we load the RBS rewriter, since we might enter into a weird loop when those constants are used for rewriting, which triggers their autoloads which tries to require their file, which we will try to rewrite, but fail since we need the constant to do the rewriting in the first place.

This is especially important since Prism has a few autoloaded constants whose associated file should NOT be rewritten (since they are needed for the rewriting itself), so should be loaded as early as possible.

Using the `AutoloadTracker` like this is appropriate since we continue to register autoloads even after the `eager_load_all!` is triggered, which makes calling `eager_load_all!` multiple times a safe operation.
@paracycle paracycle requested a review from KaanOzkan May 30, 2025 00:51
@paracycle paracycle requested a review from a team as a code owner May 30, 2025 00:51
@paracycle paracycle requested a review from Morriar May 30, 2025 00:51
Some gems print a warning when particular files are loaded, since some dependencies that they might have been expecting to be loaded are not. These warnings are not useful when Tapioca is trying to eager load these constants, and they break our tests.

In particular, the `prism` gem checks for the availability of the `parser` gem and `ruby_parser` gem, and prints a warning if they are not available.

This commit silences warnings around the eager load operation.
@paracycle paracycle changed the title Eager load autoloads registered before RBS rewriter is required Eager load autoloads that are registered before the RBS rewriter is required May 30, 2025
@paracycle paracycle changed the title Eager load autoloads that are registered before the RBS rewriter is required Eager load autoloads that are registered before the RBS rewriter is loaded May 30, 2025
@paracycle paracycle added the enhancement New feature or request label May 30, 2025
@Morriar Morriar merged commit 1a7dc3c into main May 30, 2025
17 of 18 checks passed
@Morriar Morriar deleted the uk-trigger-prism-autoloads branch May 30, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants