Skip to content

Commit

Permalink
[Truffle] No-op on autoload if the constant is already loaded.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Jul 8, 2015
1 parent c4524a1 commit e165d8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/module/autoload_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:Module#autoload ignores the autoload request if the file is already loaded
fails:Module#autoload does not remove the constant from the constant table if the loaded files does not define it
fails:Module#autoload calls #to_path on non-string filenames
fails:Module#autoload calls #to_path on non-String filename arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ public abstract static class AutoloadNode extends CoreMethodNode {
@Child private StringNodes.EmptyNode emptyNode;
private final ConditionProfile invalidConstantName = ConditionProfile.createBinaryProfile();
private final ConditionProfile emptyFilename = ConditionProfile.createBinaryProfile();
private final ConditionProfile alreadyLoaded = ConditionProfile.createBinaryProfile();

public AutoloadNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
Expand Down Expand Up @@ -549,6 +550,10 @@ private RubyBasicObject autoload(RubyModule module, String name, RubyString file
throw new RaiseException(getContext().getCoreLibrary().argumentError("empty file name", this));
}

if (alreadyLoaded.profile(module.getConstants().get(name) != null)) {
return nil();
}

module.setAutoloadConstant(this, name, filename);

return nil();
Expand Down

0 comments on commit e165d8b

Please sign in to comment.