|
17 | 17 |
|
18 | 18 | import org.truffleruby.Layouts;
|
19 | 19 | import org.truffleruby.RubyContext;
|
| 20 | +import org.truffleruby.collections.Memo; |
20 | 21 | import org.truffleruby.core.string.StringUtils;
|
21 | 22 | import org.truffleruby.language.LexicalScope;
|
22 | 23 | import org.truffleruby.language.RubyConstant;
|
@@ -501,74 +502,76 @@ public static MethodLookupResult lookupSuperMethod(InternalMethod currentMethod,
|
501 | 502 |
|
502 | 503 | assert RubyGuards.isRubyModule(objectMetaClass);
|
503 | 504 | final String name = currentMethod.getSharedMethodInfo().getName(); // use the original name
|
| 505 | + Memo<Boolean> foundDeclaringModule = new Memo<>(false); |
504 | 506 | return lookupSuperMethod(
|
505 | 507 | currentMethod.getDeclaringModule(),
|
506 |
| - new SuperMethodLookup(null, false, null), |
| 508 | + null, |
507 | 509 | name,
|
508 | 510 | objectMetaClass,
|
509 |
| - declarationContext).getResult(); |
| 511 | + foundDeclaringModule, |
| 512 | + declarationContext); |
510 | 513 | }
|
511 | 514 |
|
512 | 515 |
|
513 | 516 | @TruffleBoundary
|
514 |
| - private static SuperMethodLookup lookupSuperMethod(DynamicObject declaringModule, SuperMethodLookup lookup, |
515 |
| - String name, DynamicObject objectMetaClass, DeclarationContext declarationContext) { |
| 517 | + private static MethodLookupResult lookupSuperMethod(DynamicObject declaringModule, DynamicObject lookupTo, |
| 518 | + String name, DynamicObject objectMetaClass, Memo<Boolean> foundDeclaringModule, |
| 519 | + DeclarationContext declarationContext) { |
516 | 520 | assert RubyGuards.isRubyModule(declaringModule);
|
517 | 521 | assert RubyGuards.isRubyModule(objectMetaClass);
|
518 | 522 |
|
519 | 523 | final ArrayList<Assumption> assumptions = new ArrayList<>();
|
520 |
| - final DynamicObject lookupTo = lookup.getLookupTo(); |
521 | 524 | final boolean isRefinedMethod = Layouts.MODULE.getFields(declaringModule).isRefinement();
|
522 | 525 |
|
523 | 526 | for (DynamicObject ancestor : Layouts.MODULE.getFields(objectMetaClass).ancestors()) {
|
524 | 527 | if (ancestor == lookupTo) {
|
525 |
| - return lookup.withResult(new MethodLookupResult(null, toArray(assumptions))); |
| 528 | + return new MethodLookupResult(null, toArray(assumptions)); |
526 | 529 | }
|
527 | 530 |
|
528 | 531 | final DynamicObject[] refinements = getRefinementsFor(declarationContext, ancestor);
|
529 | 532 |
|
530 | 533 | if (refinements != null) {
|
531 | 534 | for (DynamicObject refinement : refinements) {
|
532 |
| - lookup = lookupSuperMethod( |
| 535 | + final MethodLookupResult superMethodInRefinement = lookupSuperMethod( |
533 | 536 | declaringModule,
|
534 |
| - lookup.withLookupTo(ancestor), |
| 537 | + ancestor, |
535 | 538 | name,
|
536 | 539 | refinement,
|
| 540 | + foundDeclaringModule, |
537 | 541 | null);
|
538 |
| - final MethodLookupResult superMethodInRefinement = lookup.getResult(); |
539 | 542 | for (Assumption assumption : superMethodInRefinement.getAssumptions()) {
|
540 | 543 | assumptions.add(assumption);
|
541 | 544 | }
|
542 | 545 | if (superMethodInRefinement.isDefined()) {
|
543 | 546 | InternalMethod method = superMethodInRefinement.getMethod();
|
544 |
| - return lookup.withResult(new MethodLookupResult( |
| 547 | + return new MethodLookupResult( |
545 | 548 | rememberUsedRefinements(method, declarationContext),
|
546 |
| - toArray(assumptions))); |
| 549 | + toArray(assumptions)); |
547 | 550 | }
|
548 |
| - if (lookup.getFoundDeclaringModule() && isRefinedMethod) { |
| 551 | + if (foundDeclaringModule.get() && isRefinedMethod) { |
549 | 552 | // if method is defined in refinement module (R)
|
550 | 553 | // we should lookup only in this active refinement and skip other
|
551 | 554 | break;
|
552 | 555 | }
|
553 | 556 | }
|
554 | 557 | }
|
555 | 558 |
|
556 |
| - if (!lookup.getFoundDeclaringModule()) { |
| 559 | + if (!foundDeclaringModule.get()) { |
557 | 560 | if (ancestor == declaringModule) {
|
558 |
| - lookup = lookup.withFoundDeclaringModule(true); |
| 561 | + foundDeclaringModule.set(true); |
559 | 562 | }
|
560 | 563 | } else {
|
561 | 564 | final ModuleFields fields = Layouts.MODULE.getFields(ancestor);
|
562 | 565 | assumptions.add(fields.getMethodsUnmodifiedAssumption());
|
563 | 566 | final InternalMethod method = fields.getMethod(name);
|
564 | 567 | if (method != null) {
|
565 |
| - return lookup.withResult(new MethodLookupResult(method, toArray(assumptions))); |
| 568 | + return new MethodLookupResult(method, toArray(assumptions)); |
566 | 569 | }
|
567 | 570 | }
|
568 | 571 | }
|
569 | 572 |
|
570 | 573 | // Nothing found
|
571 |
| - return lookup.withResult(new MethodLookupResult(null, toArray(assumptions))); |
| 574 | + return new MethodLookupResult(null, toArray(assumptions)); |
572 | 575 | }
|
573 | 576 |
|
574 | 577 | private static InternalMethod rememberUsedRefinements(InternalMethod method,
|
|
0 commit comments