Skip to content

Commit 6ecf074

Browse files
committed
log.autoload option
1 parent d845846 commit 6ecf074

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

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/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)