Skip to content

Commit

Permalink
No need to create a hierarchy Assumption for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Apr 25, 2023
1 parent deae78c commit c1702b0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/truffleruby/core/module/ModuleFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static void debugModuleChain(RubyModule module) {
* map of refined classes and modules (C) to refinement modules (R). */
private final ConcurrentMap<RubyModule, RubyModule> refinements = new ConcurrentHashMap<>();

/** Only set for a Module and not a Class since there is no usage of it for a Class */
private final CyclicAssumption hierarchyUnmodifiedAssumption;

// Concurrency: only modified during boot
Expand Down Expand Up @@ -141,7 +142,9 @@ public ModuleFields(
this.lexicalParent = lexicalParent;
this.givenBaseName = givenBaseName;
this.rubyModule = rubyModule;
this.hierarchyUnmodifiedAssumption = new CyclicAssumption("hierarchy is unmodified");
this.hierarchyUnmodifiedAssumption = rubyModule instanceof RubyClass
? null
: new CyclicAssumption("hierarchy is unmodified");
classVariables = new ClassVariableStorage(language);
start = new PrependMarker(this);
this.includedBy = rubyModule instanceof RubyClass ? null : new ConcurrentWeakSet<>();
Expand Down Expand Up @@ -799,6 +802,10 @@ public boolean isAnonymous() {
return !this.hasFullName;
}

private boolean isClass() {
return rubyModule instanceof RubyClass;
}

public boolean isRefinement() {
return isRefinement;
}
Expand All @@ -824,7 +831,9 @@ public String toString() {
}

public void newHierarchyVersion() {
hierarchyUnmodifiedAssumption.invalidate(getName());
if (!isClass()) {
hierarchyUnmodifiedAssumption.invalidate(getName());
}

if (isRefinement()) {
getRefinedModule().fields.invalidateBuiltinsAssumptions();
Expand Down Expand Up @@ -884,6 +893,7 @@ private void newMethodVersion(String methodToInvalidate) {
}

public Assumption getHierarchyUnmodifiedAssumption() {
assert !isClass();
return hierarchyUnmodifiedAssumption.getAssumption();
}

Expand Down

0 comments on commit c1702b0

Please sign in to comment.