-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3269 from jruby/truffle-new-require
[Truffle] Refactor some of the require system
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
Showing
31 changed files
with
355 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
slow:ARGF.read reads the contents of stdin | ||
slow:ARGF.read reads a number of bytes from stdin | ||
slow:ARGF.read reads the contents of one file and stdin | ||
fails:ARGF.read reads the contents of stdin | ||
fails:ARGF.read reads a number of bytes from stdin | ||
fails:ARGF.read reads the contents of one file and stdin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
slow:Kernel#autoload when Object is frozen raises a RuntimeError before defining the constant | ||
fails:Kernel#autoload when Object is frozen raises a RuntimeError before defining the constant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fails:Kernel#caller returns an Array of caller locations using a custom offset | ||
fails:Kernel#caller returns the locations as String instances |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
spec/truffle/tags/core/thread/backtrace/location/inspect_tags.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fails:Thread::Backtrace::Location#inspect converts the call frame to a String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fails:Thread::Backtrace::Location#to_s converts the call frame to a String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
truffle/src/main/java/org/jruby/truffle/runtime/loader/SourceCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
|
||
package org.jruby.truffle.runtime.loader; | ||
|
||
import com.oracle.truffle.api.source.Source; | ||
|
||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
public class SourceCache { | ||
|
||
private final SourceLoader loader; | ||
|
||
private final Map<String, Source> sources = new HashMap<>(); | ||
|
||
public SourceCache(SourceLoader loader) { | ||
this.loader = loader; | ||
} | ||
|
||
public synchronized Source getSource(String canonicalPath) throws IOException { | ||
Source source = sources.get(canonicalPath); | ||
|
||
if (source == null) { | ||
source = loader.load(canonicalPath); | ||
sources.put(canonicalPath, source); | ||
} | ||
|
||
return source; | ||
} | ||
|
||
public synchronized Source getBestSourceFuzzily(final String fuzzyPath) { | ||
final List<Map.Entry<String, Source>> matches = new ArrayList<>(sources.entrySet()); | ||
|
||
Collections.sort(matches, new Comparator<Map.Entry<String, Source>>() { | ||
|
||
@Override | ||
public int compare(Map.Entry<String, Source> a, Map.Entry<String, Source> b) { | ||
return Integer.compare( | ||
lengthOfCommonPrefix(fuzzyPath, b.getKey()), | ||
lengthOfCommonPrefix(fuzzyPath, a.getKey())); | ||
} | ||
|
||
}); | ||
|
||
if (matches.isEmpty()) { | ||
return null; | ||
} else { | ||
return matches.get(0).getValue(); | ||
} | ||
} | ||
|
||
private int lengthOfCommonPrefix(String a, String b) { | ||
int n = 0; | ||
|
||
while (n < a.length() | ||
&& n < b.length() | ||
&& a.charAt(a.length() - n - 1) == b.charAt(b.length() - n - 1)) { | ||
n++; | ||
} | ||
|
||
return n; | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
truffle/src/main/java/org/jruby/truffle/runtime/loader/SourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.runtime.loader; | ||
|
||
import com.oracle.truffle.api.source.Source; | ||
import org.jruby.Ruby; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
|
||
import java.io.*; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Locale; | ||
|
||
public class SourceLoader { | ||
|
||
public static final String TRUFFLE_SCHEME = "truffle:"; | ||
public static final String JRUBY_SCHEME = "jruby:"; | ||
|
||
private final RubyContext context; | ||
|
||
public SourceLoader(RubyContext context) { | ||
this.context = context; | ||
} | ||
|
||
public Source load(String canonicalPath) throws IOException { | ||
if (canonicalPath.equals("-e")) { | ||
return loadInlineScript(); | ||
} else if (canonicalPath.startsWith(TRUFFLE_SCHEME) || canonicalPath.startsWith(JRUBY_SCHEME)) { | ||
return loadResource(canonicalPath); | ||
} else { | ||
assert new File(canonicalPath).getCanonicalPath().equals(canonicalPath) : canonicalPath; | ||
return Source.fromFileName(canonicalPath); | ||
} | ||
} | ||
|
||
private Source loadInlineScript() { | ||
return Source.fromText(new String(context.getRuntime().getInstanceConfig().inlineScript(), | ||
StandardCharsets.UTF_8), "-e"); | ||
} | ||
|
||
private Source loadResource(String canonicalPath) throws IOException { | ||
if (!canonicalPath.toLowerCase(Locale.ENGLISH).endsWith(".rb")) { | ||
throw new FileNotFoundException(canonicalPath); | ||
} | ||
|
||
final Class relativeClass; | ||
final String relativePath; | ||
|
||
if (canonicalPath.startsWith(TRUFFLE_SCHEME)) { | ||
relativeClass = RubyContext.class; | ||
relativePath = canonicalPath.substring(TRUFFLE_SCHEME.length()); | ||
} else if (canonicalPath.startsWith(JRUBY_SCHEME)) { | ||
relativeClass = Ruby.class; | ||
relativePath = canonicalPath.substring(JRUBY_SCHEME.length()); | ||
} else { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
final InputStream stream = relativeClass.getResourceAsStream(relativePath); | ||
|
||
if (stream == null) { | ||
throw new FileNotFoundException(canonicalPath); | ||
} | ||
|
||
return Source.fromReader(new InputStreamReader(stream, StandardCharsets.UTF_8), canonicalPath); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 0 additions & 85 deletions
85
truffle/src/main/java/org/jruby/truffle/runtime/subsystems/SourceManager.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters