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 constant resolution strict for Module#include #291

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

mame
Copy link
Member

@mame mame commented Feb 27, 2025

In Ruby, include A; include B tries to include A::B if any. TypeProf tried to reproduce this behavior, but it turned out to be difficult to keep it. This change makes constant resolution not respect the inheritance for the arguments of Module#include.

TypeProf retried constant resolution whenever its constant scope is changed, including the inheritance is changed. However, this retry mechanism caused infinite loop when there is a constant like A::A. include A tries to include the outer A, which changes the inheritance, so the include A is reanalyzed, and then it tries to include the inner A::A, which changes the inheritance again, and then it tries to include the outer A again, which returns the first state.

By this change, include A no longer tries to include the inner A::A, so it can avoid the infinite loop.

This fixes #285

In Ruby, `include A; include B` tries to include `A::B` if any.
TypeProf tried to reproduce this behavior, but it turned out to be
difficult to keep it. This change makes constant resolution not respect
the inheritance for the arguments of Module#include.

TypeProf retried constant resolution whenever its constant scope is
changed, including the inheritance is changed. However, this retry
mechanism caused infinite loop when there is a constant like `A::A`.
`include A` tries to include the outer `A`, which changes the
inheritance, so the `include A` is reanalyzed, and then it tries to
include the inner `A::A`, which changes the inheritance again, and then
it tries to include the outer `A` again, which returns the first state.

By this change, `include A` no longer tries to include the inner `A::A`,
so it can avoid the infinite loop.

This fixes #285
@mame mame force-pushed the change-include-const-resolution branch from 0b931c1 to 220cc30 Compare March 5, 2025 09:02
@mame mame enabled auto-merge (rebase) March 5, 2025 09:03
@mame mame merged commit 1ee4931 into master Mar 5, 2025
14 checks passed
@mame mame deleted the change-include-const-resolution branch March 5, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant