Skip to content

Commit bfa68bf

Browse files
committed
Pass the AutoloadConstant to setConstantInternal()
* Do not use the RubyConstant#value field to store the path for an autoload, it is already stored in the AutoloadConstant. * Now it is clear the RubyConstant#value is null for an autoload.
1 parent 6f5a242 commit bfa68bf

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.truffleruby.core.string.ImmutableRubyString;
4040
import org.truffleruby.core.string.StringUtils;
4141
import org.truffleruby.core.symbol.RubySymbol;
42+
import org.truffleruby.language.AutoloadConstant;
4243
import org.truffleruby.language.Nil;
4344
import org.truffleruby.language.RubyConstant;
4445
import org.truffleruby.language.RubyDynamicObject;
@@ -174,7 +175,7 @@ public RubyConstant getAdoptedByLexicalParent(
174175
currentNode,
175176
name,
176177
rubyModule,
177-
false);
178+
null);
178179

179180
if (!hasFullName()) {
180181
// Tricky, we need to compare with the Object class, but we only have a Class at hand.
@@ -427,14 +428,15 @@ public RubyConstant setConstant(RubyContext context, Node currentNode, String na
427428
name,
428429
currentNode);
429430
} else {
430-
return setConstantInternal(context, currentNode, name, value, false);
431+
return setConstantInternal(context, currentNode, name, value, null);
431432
}
432433
}
433434

434435
@TruffleBoundary
435436
public void setAutoloadConstant(RubyContext context, Node currentNode, String name, Object filename,
436437
String javaFilename) {
437-
RubyConstant autoloadConstant = setConstantInternal(context, currentNode, name, filename, true);
438+
RubyConstant autoloadConstant = setConstantInternal(context, currentNode, name, null,
439+
new AutoloadConstant(filename));
438440
if (autoloadConstant == null) {
439441
return;
440442
}
@@ -458,14 +460,14 @@ public void setAutoloadConstant(RubyContext context, Node currentNode, String na
458460
}
459461

460462
private RubyConstant setConstantInternal(RubyContext context, Node currentNode, String name, Object value,
461-
boolean autoload) {
463+
AutoloadConstant autoloadConstant) {
462464
checkFrozen(context, currentNode);
463465

464466
SharedObjects.propagate(context.getLanguageSlow(), rubyModule, value);
465467

466-
final String autoloadPath = autoload
467-
? RubyGuards.getJavaString(value)
468-
: null;
468+
final boolean autoload = autoloadConstant != null;
469+
final String autoloadPath = autoload ? autoloadConstant.getAutoloadPath() : null;
470+
469471
RubyConstant previous;
470472
RubyConstant newConstant;
471473
ConstantEntry previousEntry;
@@ -483,7 +485,7 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
483485
return null;
484486
}
485487
}
486-
newConstant = newConstant(currentNode, name, value, autoload, previous);
488+
newConstant = newConstant(currentNode, name, value, autoloadConstant, previous);
487489
} while (!ConcurrentOperations.replace(constants, name, previousEntry, new ConstantEntry(newConstant)));
488490

489491
if (previousEntry != null) {
@@ -497,12 +499,12 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
497499
return autoload ? newConstant : previous;
498500
}
499501

500-
private RubyConstant newConstant(Node currentNode, String name, Object value, boolean autoload,
502+
private RubyConstant newConstant(Node currentNode, String name, Object value, AutoloadConstant autoloadConstant,
501503
RubyConstant previous) {
502504
final boolean isPrivate = previous != null && previous.isPrivate();
503505
final boolean isDeprecated = previous != null && previous.isDeprecated();
504506
final SourceSection sourceSection = currentNode != null ? currentNode.getSourceSection() : null;
505-
return new RubyConstant(rubyModule, name, value, isPrivate, autoload, isDeprecated, sourceSection);
507+
return new RubyConstant(rubyModule, name, value, isPrivate, autoloadConstant, isDeprecated, sourceSection);
506508
}
507509

508510
@TruffleBoundary

src/main/java/org/truffleruby/language/AutoloadConstant.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import org.truffleruby.core.mutex.MutexOperations;
1818
import org.truffleruby.language.library.RubyStringLibrary;
1919

20-
public class AutoloadConstant {
20+
public final class AutoloadConstant {
2121

2222
private final Object feature;
2323
private final String autoloadPath;
2424
private volatile ReentrantLock autoloadLock;
2525

26-
AutoloadConstant(Object feature) {
26+
public AutoloadConstant(Object feature) {
2727
assert RubyStringLibrary.getUncached().isRubyString(feature);
2828
this.feature = feature;
2929
this.autoloadPath = RubyGuards.getJavaString(this.feature);

src/main/java/org/truffleruby/language/RubyConstant.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public RubyConstant(
4242
String name,
4343
Object value,
4444
boolean isPrivate,
45-
boolean autoload,
45+
AutoloadConstant autoloadConstant,
4646
boolean isDeprecated,
4747
SourceSection sourceSection) {
4848
this(
4949
declaringModule,
5050
name,
5151
value,
5252
isPrivate,
53-
autoload ? new AutoloadConstant(value) : null,
53+
autoloadConstant,
5454
false,
5555
isDeprecated,
5656
sourceSection);

src/main/java/org/truffleruby/language/loader/RequireNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ private boolean requireConsideringAutoload(String feature, String expandedPath,
130130
final List<RubyConstant> releasedConstants = featureLoader.getAutoloadConstants(expandedPath);
131131
for (RubyConstant constant : releasedConstants) {
132132
if (constant.getAutoloadConstant().isAutoloadingThread() && !alreadyAutoloading.contains(constant)) {
133-
final boolean undefined = GetConstantNode
134-
.autoloadUndefineConstantIfStillAutoload(constant);
133+
final boolean undefined = GetConstantNode.autoloadUndefineConstantIfStillAutoload(constant);
135134
GetConstantNode.logAutoloadResult(getContext(), constant, undefined);
136135
GetConstantNode.autoloadConstantStop(constant);
137136
featureLoader.removeAutoload(constant);

0 commit comments

Comments
 (0)