Skip to content

Commit a06117d

Browse files
bjfisheregon
authored andcommitted
Fix bug in expanded load path caching
(cherry picked from commit cbc48bb)
1 parent a6d4c58 commit a06117d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/main/java/org/truffleruby/core/TruffleSystemNodes.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,17 @@ protected Object setTruffleWorkingDir(RubyString dir) {
146146
}
147147
}
148148

149+
@Primitive(name = "working_directory")
150+
public abstract static class GetTruffleWorkingDirNode extends PrimitiveArrayArgumentsNode {
151+
@Specialization
152+
protected RubyString getTruffleWorkingDir(
153+
@Cached StringNodes.MakeStringNode makeStringNode) {
154+
final String cwd = getContext().getFeatureLoader().getWorkingDirectory();
155+
final Encoding externalEncoding = getContext().getEncodingManager().getDefaultExternalEncoding();
156+
return makeStringNode.executeMake(cwd, externalEncoding, CodeRange.CR_UNKNOWN);
157+
}
158+
}
159+
149160
@CoreMethod(names = "get_java_property", onSingleton = true, required = 1)
150161
public abstract static class GetJavaPropertyNode extends CoreMethodArrayArgumentsNode {
151162

src/main/java/org/truffleruby/language/loader/FeatureLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public void setWorkingDirectory(String cwd) {
170170
this.cwd = cwd;
171171
}
172172

173+
@TruffleBoundary
173174
public String getWorkingDirectory() {
174175
if (cwd != null) {
175176
return cwd;

src/main/ruby/truffleruby/core/truffle/feature_loader.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ module FeatureLoader
2121
@expanded_load_path = []
2222
# A snapshot of $LOAD_PATH, to check if the @expanded_load_path cache is up to date.
2323
@load_path_copy = []
24+
@working_directory_copy = ''
2425

2526
def self.clear_cache
2627
@loaded_features_index.clear
2728
@loaded_features_copy.clear
2829
@expanded_load_path.clear
2930
@load_path_copy.clear
31+
@working_directory_copy.clear
3032
end
3133

3234
class FeatureEntry
@@ -278,9 +280,10 @@ def self.features_index_add(feature, offset)
278280
end
279281

280282
def self.get_expanded_load_path
281-
unless Primitive.array_storage_equal?(@load_path_copy, $LOAD_PATH)
283+
unless Primitive.array_storage_equal?(@load_path_copy, $LOAD_PATH) && Primitive.working_directory == @working_directory_copy
282284
@expanded_load_path = $LOAD_PATH.map { |path| Primitive.canonicalize_path(Truffle::Type.coerce_to_path(path)) }
283-
@loaded_features_copy = $LOAD_PATH.dup
285+
@load_path_copy = $LOAD_PATH.dup
286+
@working_directory_copy = Primitive.working_directory
284287
end
285288
@expanded_load_path
286289
end

0 commit comments

Comments
 (0)