Skip to content

Commit bfe53f9

Browse files
committed
Clarify and document the invalidation logic
1 parent e71e8ab commit bfe53f9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/main/java/org/truffleruby/core/module/ModuleFields.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ public void include(RubyContext context, Node currentNode, RubyModule module) {
295295
private void performIncludes(ModuleChain inclusionPoint, Deque<RubyModule> moduleAncestors) {
296296
while (!moduleAncestors.isEmpty()) {
297297
RubyModule mod = moduleAncestors.pop();
298+
// Module#include only adds modules between the current class and the super class,
299+
// so invalidating the current class is enough as all affected lookups would go through the current class.
298300
newMethodsVersion(mod.fields.getMethodNames());
299301
inclusionPoint.insertAfter(mod);
300302
}
@@ -324,16 +326,11 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
324326

325327
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, module);
326328

327-
ModuleChain mod = module.fields.start;
328-
final ModuleChain topPrependedModule = start.getParentModule();
329-
330-
final ModuleFields moduleFieldsToInvalidate;
331-
if (topPrependedModule != this) {
332-
moduleFieldsToInvalidate = topPrependedModule.getActualModule().fields;
333-
} else {
334-
moduleFieldsToInvalidate = this;
335-
}
329+
// Previous calls on instances of the current class must have looked up through the first prepended module,
330+
// so invalidate that one.
331+
final ModuleFields moduleFieldsToInvalidate = getFirstModuleChain().getActualModule().fields;
336332

333+
ModuleChain mod = module.fields.start;
337334
ModuleChain cur = start;
338335
while (mod != null &&
339336
!(mod instanceof ModuleFields && ((ModuleFields) mod).rubyModule instanceof RubyClass)) {

0 commit comments

Comments
 (0)