Skip to content

Commit ceefbd3

Browse files
committed
Eager load autoloads registered before RBS rewriter is required
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.
1 parent dd3a727 commit ceefbd3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/tapioca/internal.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
# The rewriter needs to be loaded very early so RBS comments within Tapioca itself are rewritten
1818
require "spoom"
19+
# Eager load all the autoloads at this point, so that we don't enter into
20+
# a weird loop when the autoloads get triggered and we try to require the file.
21+
# This is especially important since Prism has a few autoloaded constants that
22+
# should NOT be rewritten (since they are needed for the rewriting itself), so
23+
# should be loaded as early as possible.
24+
Tapioca::Runtime::Trackers::Autoload.eager_load_all!
1925
require "tapioca/rbs/rewriter"
2026
# ^ Do not change the order of these requires
2127

lib/tapioca/rbs/rewriter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def load_iseq(path)
4949
if source =~ /^\s*#\s*typed: (ignore|false|true|strict|strong|__STDLIB_INTERNAL)/
5050
Spoom::Sorbet::Translate.rbs_comments_to_sorbet_sigs(source, file: path)
5151
end
52-
rescue RBI::RBS::MethodTypeTranslator::Error
52+
rescue Spoom::Sorbet::Translate::Error
5353
# If we can't translate the RBS comments back into Sorbet's signatures, we just skip the file.
5454
source
5555
end

0 commit comments

Comments
 (0)