39
39
import org .truffleruby .core .string .ImmutableRubyString ;
40
40
import org .truffleruby .core .string .StringUtils ;
41
41
import org .truffleruby .core .symbol .RubySymbol ;
42
+ import org .truffleruby .language .AutoloadConstant ;
42
43
import org .truffleruby .language .Nil ;
43
44
import org .truffleruby .language .RubyConstant ;
44
45
import org .truffleruby .language .RubyDynamicObject ;
@@ -174,7 +175,7 @@ public RubyConstant getAdoptedByLexicalParent(
174
175
currentNode ,
175
176
name ,
176
177
rubyModule ,
177
- false );
178
+ null );
178
179
179
180
if (!hasFullName ()) {
180
181
// 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
427
428
name ,
428
429
currentNode );
429
430
} else {
430
- return setConstantInternal (context , currentNode , name , value , false );
431
+ return setConstantInternal (context , currentNode , name , value , null );
431
432
}
432
433
}
433
434
434
435
@ TruffleBoundary
435
436
public void setAutoloadConstant (RubyContext context , Node currentNode , String name , Object filename ,
436
437
String javaFilename ) {
437
- RubyConstant autoloadConstant = setConstantInternal (context , currentNode , name , filename , true );
438
+ RubyConstant autoloadConstant = setConstantInternal (context , currentNode , name , null ,
439
+ new AutoloadConstant (filename ));
438
440
if (autoloadConstant == null ) {
439
441
return ;
440
442
}
@@ -458,14 +460,14 @@ public void setAutoloadConstant(RubyContext context, Node currentNode, String na
458
460
}
459
461
460
462
private RubyConstant setConstantInternal (RubyContext context , Node currentNode , String name , Object value ,
461
- boolean autoload ) {
463
+ AutoloadConstant autoloadConstant ) {
462
464
checkFrozen (context , currentNode );
463
465
464
466
SharedObjects .propagate (context .getLanguageSlow (), rubyModule , value );
465
467
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
+
469
471
RubyConstant previous ;
470
472
RubyConstant newConstant ;
471
473
ConstantEntry previousEntry ;
@@ -483,7 +485,7 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
483
485
return null ;
484
486
}
485
487
}
486
- newConstant = newConstant (currentNode , name , value , autoload , previous );
488
+ newConstant = newConstant (currentNode , name , value , autoloadConstant , previous );
487
489
} while (!ConcurrentOperations .replace (constants , name , previousEntry , new ConstantEntry (newConstant )));
488
490
489
491
if (previousEntry != null ) {
@@ -497,12 +499,12 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
497
499
return autoload ? newConstant : previous ;
498
500
}
499
501
500
- private RubyConstant newConstant (Node currentNode , String name , Object value , boolean autoload ,
502
+ private RubyConstant newConstant (Node currentNode , String name , Object value , AutoloadConstant autoloadConstant ,
501
503
RubyConstant previous ) {
502
504
final boolean isPrivate = previous != null && previous .isPrivate ();
503
505
final boolean isDeprecated = previous != null && previous .isDeprecated ();
504
506
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 );
506
508
}
507
509
508
510
@ TruffleBoundary
0 commit comments