@@ -229,7 +229,7 @@ public ModuleChain getFirstModuleChain() {
229
229
}
230
230
231
231
@ TruffleBoundary
232
- public void initCopy (RubyModule from ) {
232
+ public void initCopy (RubyContext context , RubyModule from , Node node ) {
233
233
// Do not copy name, the copy is an anonymous module
234
234
final ModuleFields fromFields = from .fields ;
235
235
@@ -246,7 +246,12 @@ public void initCopy(RubyModule from) {
246
246
for (Entry <String , ConstantEntry > entry : fromFields .constants .entrySet ()) {
247
247
final RubyConstant constant = entry .getValue ().getConstant ();
248
248
if (constant != null ) {
249
- this .constants .put (entry .getKey (), new ConstantEntry (constant ));
249
+ if (constant .isAutoload ()) {
250
+ var autoloadConstant = constant .getAutoloadConstant ();
251
+ setAutoloadConstant (context , node , constant .getName (), autoloadConstant .getFeature ());
252
+ } else {
253
+ this .constants .put (entry .getKey (), new ConstantEntry (constant .copy (rubyModule )));
254
+ }
250
255
}
251
256
}
252
257
@@ -439,30 +444,28 @@ public RubyConstant setConstant(RubyContext context, Node currentNode, String na
439
444
}
440
445
441
446
@ TruffleBoundary
442
- public void setAutoloadConstant (RubyContext context , Node currentNode , String name , Object filename ,
443
- String javaFilename ) {
444
- RubyConstant autoloadConstant = setConstantInternal (context , currentNode , name , null ,
445
- new AutoloadConstant (filename ));
446
- if (autoloadConstant == null ) {
447
+ public void setAutoloadConstant (RubyContext context , Node currentNode , String name , Object filename ) {
448
+ RubyConstant constant = setConstantInternal (context , currentNode , name , null , new AutoloadConstant (filename ));
449
+ if (constant == null ) {
447
450
return ;
448
451
}
449
452
450
453
if (context .getOptions ().LOG_AUTOLOAD ) {
451
454
RubyLanguage .LOGGER .info (() -> String .format (
452
455
"%s: setting up autoload %s with %s" ,
453
456
context .fileLine (context .getCallStack ().getTopMostUserSourceSection ()),
454
- autoloadConstant ,
457
+ constant ,
455
458
filename ));
456
459
}
457
460
final ReentrantLockFreeingMap <String > fileLocks = context .getFeatureLoader ().getFileLocks ();
458
- final ReentrantLock lock = fileLocks .get (javaFilename );
461
+ final ReentrantLock lock = fileLocks .get (constant . getAutoloadConstant (). getAutoloadPath () );
459
462
if (lock .isLocked ()) {
460
463
// We need to handle the new autoload constant immediately
461
464
// if Object.autoload(name, filename) is executed from filename.rb
462
- GetConstantNode .autoloadConstantStart (context , autoloadConstant , currentNode );
465
+ GetConstantNode .autoloadConstantStart (context , constant , currentNode );
463
466
}
464
467
465
- context .getFeatureLoader ().addAutoload (autoloadConstant );
468
+ context .getFeatureLoader ().addAutoload (constant );
466
469
}
467
470
468
471
private RubyConstant setConstantInternal (RubyContext context , Node currentNode , String name , Object value ,
0 commit comments