Skip to content

Commit 3a8b2c2

Browse files
committed
[GR-14450] Work around autoloading bugs
PullRequest: truffleruby/698
2 parents c2c6b7d + 4cd500f commit 3a8b2c2

File tree

8 files changed

+44
-1
lines changed

8 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Bug fixes:
1111
* Combining multiple `**` arguments containing duplicate keys produced
1212
an incorrect hash. This has now been fixed (#1469).
1313
* `IO#read_nonblock` now returns the passed buffer object, if one is supplied.
14+
* Worked out autoloading issue (#1614).
1415

1516
New features:
1617

lib/mri/net/http.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222

2323
require_relative 'protocol'
2424
require 'uri'
25-
autoload :OpenSSL, 'openssl'
25+
26+
if RUBY_ENGINE == 'truffleruby'
27+
# See tagged specs around autoload
28+
require 'openssl'
29+
else
30+
autoload :OpenSSL, 'openssl'
31+
end
2632

2733
module Net #:nodoc:
2834

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ public RubyConstant setConstant(RubyContext context, Node currentNode, String na
320320
@TruffleBoundary
321321
public void setAutoloadConstant(RubyContext context, Node currentNode, String name, DynamicObject filename) {
322322
assert RubyGuards.isRubyString(filename);
323+
if (context.getOptions().LOG_AUTOLOAD) {
324+
RubyLanguage.LOGGER.info(() -> String.format("%s: setting up autoload %s::%s with %s",
325+
context.fileLine(context.getCallStack().getTopMostUserSourceSection()),
326+
getName(), name, filename));
327+
}
323328
setConstantInternal(context, currentNode, name, filename, true);
324329
}
325330

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ public RubyNode coerceToBoolean(RubyNode inherit) {
879879
}
880880

881881
// Symbol
882+
882883
@Specialization(guards = { "inherit", "isRubySymbol(name)" })
883884
public Object getConstant(DynamicObject module, DynamicObject name, boolean inherit) {
884885
return getConstant(module, Layouts.SYMBOL.getString(name));
@@ -890,6 +891,7 @@ public Object getConstantNoInherit(DynamicObject module, DynamicObject name, boo
890891
}
891892

892893
// String
894+
893895
@Specialization(guards = { "inherit", "isRubyString(name)", "equalNode.execute(rope(name), cachedRope)", "!scoped" }, limit = "getLimit()")
894896
public Object getConstantStringCached(DynamicObject module, DynamicObject name, boolean inherit,
895897
@Cached("privatizeRope(name)") Rope cachedRope,

src/main/java/org/truffleruby/language/constants/GetConstantNode.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.oracle.truffle.api.profiles.ConditionProfile;
1818

1919
import org.truffleruby.Layouts;
20+
import org.truffleruby.RubyLanguage;
2021
import org.truffleruby.core.module.ModuleFields;
2122
import org.truffleruby.core.module.ModuleOperations;
2223
import org.truffleruby.core.string.StringOperations;
@@ -76,10 +77,22 @@ protected Object autoloadConstant(LexicalScope lexicalScope, DynamicObject modul
7677
// We found an autoload constant while we are already require-ing the autoload file,
7778
// consider it missing to avoid circular require warnings and calling #require twice.
7879
// For instance, autoload :RbConfig, "rbconfig"; require "rbconfig" causes this.
80+
if (getContext().getOptions().LOG_AUTOLOAD) {
81+
RubyLanguage.LOGGER.info(() -> String.format("%s: %s::%s is being treated as missing while loading %s",
82+
getContext().fileLine(getContext().getCallStack().getTopMostUserSourceSection()),
83+
Layouts.MODULE.getFields(module).getName(), name, expandedPath));
84+
}
7985
return doMissingConstant(module, name, getSymbol(name));
8086
}
8187

8288
autoloadConstant.startAutoLoad();
89+
90+
if (getContext().getOptions().LOG_AUTOLOAD) {
91+
RubyLanguage.LOGGER.info(() -> String.format("%s: autoloading %s::%s with %s",
92+
getContext().fileLine(getContext().getCallStack().getTopMostUserSourceSection()),
93+
Layouts.MODULE.getFields(autoloadConstantModule).getName(), name, autoloadConstant.getAutoloadPath()));
94+
}
95+
8396
try {
8497

8598
// We need to notify cached lookup that we are autoloading the constant, as constant

src/main/java/org/truffleruby/options/Options.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class Options {
7676
public final String[] CEXTS_LIBRARY_REMAP;
7777
public final boolean OPTIONS_LOG;
7878
public final boolean LOG_LOAD;
79+
public final boolean LOG_AUTOLOAD;
7980
public final boolean LOG_FEATURE_LOCATION;
8081
public final boolean CEXTS_LOG_LOAD;
8182
public final boolean CEXTS_LOG_WARNINGS;
@@ -208,6 +209,7 @@ public Options(Env env, OptionValues options) {
208209
CEXTS_LIBRARY_REMAP = options.get(OptionsCatalog.CEXTS_LIBRARY_REMAP_KEY);
209210
OPTIONS_LOG = options.get(OptionsCatalog.OPTIONS_LOG_KEY);
210211
LOG_LOAD = options.get(OptionsCatalog.LOG_LOAD_KEY);
212+
LOG_AUTOLOAD = options.get(OptionsCatalog.LOG_AUTOLOAD_KEY);
211213
LOG_FEATURE_LOCATION = options.get(OptionsCatalog.LOG_FEATURE_LOCATION_KEY);
212214
CEXTS_LOG_LOAD = options.get(OptionsCatalog.CEXTS_LOG_LOAD_KEY);
213215
CEXTS_LOG_WARNINGS = options.get(OptionsCatalog.CEXTS_LOG_WARNINGS_KEY);
@@ -392,6 +394,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
392394
return OPTIONS_LOG;
393395
case "ruby.log.load":
394396
return LOG_LOAD;
397+
case "ruby.log.autoload":
398+
return LOG_AUTOLOAD;
395399
case "ruby.log.feature_location":
396400
return LOG_FEATURE_LOCATION;
397401
case "ruby.cexts.log.load":

src/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ EXPERT:
7272

7373
# Tracing loading of Ruby files and C extensions
7474
LOG_LOAD: [log.load, boolean, false, Log loading files]
75+
LOG_AUTOLOAD: [log.autoload, boolean, false, Log autoloading]
7576
LOG_FEATURE_LOCATION: [log.feature_location, boolean, false, Log the process of finding features]
7677
CEXTS_LOG_LOAD: [cexts.log.load, boolean, false, Log loading of cexts]
7778
CEXTS_LOG_WARNINGS: [cexts.log.warnings, boolean, false, Log cexts warnings]

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class OptionsCatalog {
7171
public static final OptionKey<String[]> CEXTS_LIBRARY_REMAP_KEY = new OptionKey<>(new String[]{}, StringArrayOptionType.INSTANCE);
7272
public static final OptionKey<Boolean> OPTIONS_LOG_KEY = new OptionKey<>(false);
7373
public static final OptionKey<Boolean> LOG_LOAD_KEY = new OptionKey<>(false);
74+
public static final OptionKey<Boolean> LOG_AUTOLOAD_KEY = new OptionKey<>(false);
7475
public static final OptionKey<Boolean> LOG_FEATURE_LOCATION_KEY = new OptionKey<>(false);
7576
public static final OptionKey<Boolean> CEXTS_LOG_LOAD_KEY = new OptionKey<>(false);
7677
public static final OptionKey<Boolean> CEXTS_LOG_WARNINGS_KEY = new OptionKey<>(false);
@@ -502,6 +503,13 @@ public class OptionsCatalog {
502503
.stability(OptionStability.EXPERIMENTAL)
503504
.build();
504505

506+
public static final OptionDescriptor LOG_AUTOLOAD = OptionDescriptor
507+
.newBuilder(LOG_AUTOLOAD_KEY, "ruby.log.autoload")
508+
.help("Log autoloading")
509+
.category(OptionCategory.EXPERT)
510+
.stability(OptionStability.EXPERIMENTAL)
511+
.build();
512+
505513
public static final OptionDescriptor LOG_FEATURE_LOCATION = OptionDescriptor
506514
.newBuilder(LOG_FEATURE_LOCATION_KEY, "ruby.log.feature_location")
507515
.help("Log the process of finding features")
@@ -1164,6 +1172,8 @@ public static OptionDescriptor fromName(String name) {
11641172
return OPTIONS_LOG;
11651173
case "ruby.log.load":
11661174
return LOG_LOAD;
1175+
case "ruby.log.autoload":
1176+
return LOG_AUTOLOAD;
11671177
case "ruby.log.feature_location":
11681178
return LOG_FEATURE_LOCATION;
11691179
case "ruby.cexts.log.load":
@@ -1409,6 +1419,7 @@ public static OptionDescriptor[] allDescriptors() {
14091419
LAZY_TRANSLATION_LOG,
14101420
LAZY_TRANSLATION_USER,
14111421
LOAD_PATHS,
1422+
LOG_AUTOLOAD,
14121423
LOG_FEATURE_LOCATION,
14131424
LOG_LOAD,
14141425
METHOD_LOOKUP_CACHE,

0 commit comments

Comments
 (0)