Skip to content

Restore Bootsnap fallback for RBS rewriting#2630

Merged
KaanOzkan merged 1 commit into
mainfrom
kaan/fix-rbs-rewriter-bootsnap-default
May 21, 2026
Merged

Restore Bootsnap fallback for RBS rewriting#2630
KaanOzkan merged 1 commit into
mainfrom
kaan/fix-rbs-rewriter-bootsnap-default

Conversation

@KaanOzkan
Copy link
Copy Markdown
Contributor

@KaanOzkan KaanOzkan commented May 21, 2026

Fixes a bug on unreleased main that @dejmedus pointed out in the new rewriter implementation when the ENV variable is omitted.

Motivation

PR #2617 moved the old load_iseq bypass behind TAPIOCA_RBS_CACHE=1, so hosts that call Bootsnap.setup without the opt-in cache bypass RequireHooks and lose RBS comment signatures. Restore the default bypass after require-hooks setup while keeping the opt-in cache path intact.

Implementation

Bring back the overload from

module Bootsnap
module CompileCache
module ISeq
module InstructionSequenceMixin
#: (String) -> RubyVM::InstructionSequence
def load_iseq(path)
super if defined?(super)
end
end
end
end
end
rescue LoadError
# Bootsnap is not in the bundle, we don't need to do anything.
end

Tests

Included

@KaanOzkan KaanOzkan requested a review from a team as a code owner May 21, 2026 20:55
assert_success_status(result)
end

it "preserves RBS comment rewriting when the host sets up Bootsnap without TAPIOCA_RBS_CACHE" do
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Figured the test is worth it given last time this bug went through. It uses a custom compiler so that we don't boot rails but an existing compiler could also show this issue.

Comment thread lib/tapioca/rbs/rewriter.rb Outdated

require "require-hooks/setup"

unless rbs_cache_enabled
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used if and unless so that require "require-hooks/setup" call isn't duplicated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eh, I think a single if/else with a repeated require "require-hooks/setup" would be more clear, but that's just me

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does the order of requires matter here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does the order of requires matter here?

Yes, require-hooks/setup chooses a mode based on bootsnap being loaded or not. In TAPIOCA_RBS_CACHE (if) we want it after loading bootsnap. In else, we want it before bootsnap is loaded.

Comment thread lib/tapioca/rbs/rewriter.rb Outdated
module InstructionSequenceMixin
#: (String) -> RubyVM::InstructionSequence
def load_iseq(path)
super if defined?(super)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe just clarify:

Suggested change
super if defined?(super)
super if defined?(super) # Disable Bootsnaps' hook, but trigger any others

Comment thread lib/tapioca/rbs/rewriter.rb Outdated

require "require-hooks/setup"

unless rbs_cache_enabled
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eh, I think a single if/else with a repeated require "require-hooks/setup" would be more clear, but that's just me

PR #2617 moved the old `load_iseq` bypass behind `TAPIOCA_RBS_CACHE=1`, so hosts that call `Bootsnap.setup` without the opt-in cache bypass `RequireHooks` and lose RBS comment signatures. Restore the default bypass after `require-hooks` setup while keeping the opt-in cache path intact.

Add a CLI regression test that sets up host `Bootsnap` without `TAPIOCA_RBS_CACHE` and verifies an RBS comment produces a typed RBI.

Co-authored-by: Julia Boutin <julia.boutin@shopify.com>
@KaanOzkan KaanOzkan force-pushed the kaan/fix-rbs-rewriter-bootsnap-default branch from b768059 to 042fc36 Compare May 21, 2026 21:31
@KaanOzkan KaanOzkan merged commit fc4e78b into main May 21, 2026
19 checks passed
@KaanOzkan KaanOzkan deleted the kaan/fix-rbs-rewriter-bootsnap-default branch May 21, 2026 21:58
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.

3 participants