Merge pull request #9848 from sferik/string-literal-file · jruby/jruby@5e32991 · GitHub
Skip to content

Commit 5e32991

Browse files
authored
Merge pull request #9848 from sferik/string-literal-file
Keep file and line on compiled string range endpoints
2 parents cd33744 + 195f4a1 commit 5e32991

6 files changed

Lines changed: 42 additions & 14 deletions

File tree

‎core/src/main/java/org/jruby/ir/targets/JVMVisitor.java‎

Lines changed: 2 additions & 2 deletions

‎core/src/main/java/org/jruby/ir/targets/ValueCompiler.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ public interface ValueCompiler {
134134
*
135135
* @param begin begin value
136136
* @param end end value
137+
* @param file file containing the range, for frozen string debugging
138+
* @param beginLine line of the begin value, for frozen string debugging
139+
* @param endLine line of the end value, for frozen string debugging
137140
* @param exclusive whether this is an exclusive range
138141
*/
139-
void pushRange(ByteList begin, int beginCR, ByteList end, int endCR, boolean exclusive);
142+
void pushRange(ByteList begin, int beginCR, ByteList end, int endCR, String file, int beginLine, int endLine, boolean exclusive);
140143

141144
/**
142145
* Build and save a literal regular expression.

‎core/src/main/java/org/jruby/ir/targets/indy/IndyValueCompiler.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public void pushBeginlessRange(long begin, boolean exclusive) {
180180
compiler.adapter.invokedynamic(RangeObjectSite.RANGE_BEGINLESS, sig(RubyRange.class, ThreadContext.class), RangeObjectSite.BOOTSTRAP_LONG, begin, exclusive ? 1 : 0);
181181
}
182182

183-
public void pushRange(ByteList begin, int beginCR, ByteList end, int endCR, boolean exclusive) {
183+
public void pushRange(ByteList begin, int beginCR, ByteList end, int endCR, String file, int beginLine, int endLine, boolean exclusive) {
184184
compiler.loadContext();
185-
compiler.adapter.invokedynamic("range", sig(RubyRange.class, ThreadContext.class), RangeObjectSite.BOOTSTRAP_STRING_STRING, RubyEncoding.decodeRaw(begin), begin.getEncoding().toString(), beginCR, RubyEncoding.decodeRaw(end), end.getEncoding().toString(), endCR, exclusive ? 1 : 0);
185+
compiler.adapter.invokedynamic("range", sig(RubyRange.class, ThreadContext.class), RangeObjectSite.BOOTSTRAP_STRING_STRING, RubyEncoding.decodeRaw(begin), begin.getEncoding().toString(), beginCR, RubyEncoding.decodeRaw(end), end.getEncoding().toString(), endCR, file, beginLine, endLine, exclusive ? 1 : 0);
186186
}
187187

188188
public void pushRegexp(ByteList source, int options) {

‎core/src/main/java/org/jruby/ir/targets/indy/RangeObjectSite.java‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,33 +92,39 @@ public IRubyObject construct(ThreadContext context) throws Throwable {
9292
Opcodes.H_INVOKESTATIC,
9393
p(RangeObjectSite.class),
9494
"bootstrapStrings",
95-
sig(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, String.class, String.class, int.class, String.class, String.class, int.class, int.class),
95+
sig(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, String.class, String.class, int.class, String.class, String.class, int.class, String.class, int.class, int.class, int.class),
9696
false);
9797

98-
public static CallSite bootstrapStrings(MethodHandles.Lookup lookup, String name, MethodType type, String begin, String beginEnc, int beginCR, String end, String endEnc, int endCR, int exclusive) {
99-
return new StringRangeObjectSite(type, StringBootstrap.bytelist(begin, beginEnc), beginCR, StringBootstrap.bytelist(end, endEnc), endCR, exclusive != 0).bootstrap(lookup);
98+
public static CallSite bootstrapStrings(MethodHandles.Lookup lookup, String name, MethodType type, String begin, String beginEnc, int beginCR, String end, String endEnc, int endCR, String file, int beginLine, int endLine, int exclusive) {
99+
return new StringRangeObjectSite(type, StringBootstrap.bytelist(begin, beginEnc), beginCR, StringBootstrap.bytelist(end, endEnc), endCR, file, beginLine, endLine, exclusive != 0).bootstrap(lookup);
100100
}
101101

102102
public static class StringRangeObjectSite extends RangeObjectSite {
103103
protected final ByteList begin;
104104
protected final int beginCR;
105105
protected final ByteList end;
106106
protected final int endCR;
107+
protected final String file;
108+
protected final int beginLine;
109+
protected final int endLine;
107110

108-
public StringRangeObjectSite(MethodType type, ByteList begin, int beginCR, ByteList end, int endCR, boolean exclusive) {
111+
public StringRangeObjectSite(MethodType type, ByteList begin, int beginCR, ByteList end, int endCR, String file, int beginLine, int endLine, boolean exclusive) {
109112
super(type, exclusive);
110113

111114
this.begin = begin;
112115
this.beginCR = beginCR;
113116
this.end = end;
114117
this.endCR = endCR;
118+
this.file = file;
119+
this.beginLine = beginLine;
120+
this.endLine = endLine;
115121
}
116122

117123
public IRubyObject construct(ThreadContext context) throws Throwable {
118124
return RubyRange.newRange(
119125
context,
120-
IRRuntimeHelpers.newFrozenString(context, begin, beginCR),
121-
IRRuntimeHelpers.newFrozenString(context, end, endCR),
126+
IRRuntimeHelpers.newFrozenString(context, begin, beginCR, file, beginLine),
127+
IRRuntimeHelpers.newFrozenString(context, end, endCR, file, endLine),
122128
exclusive);
123129
}
124130
}

‎core/src/main/java/org/jruby/ir/targets/simple/NormalValueCompiler.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ public void pushBeginlessRange(long begin, boolean exclusive) {
237237
});
238238
}
239239

240-
public void pushRange(ByteList begin, int beginCR, ByteList end, int endCR, boolean exclusive) {
240+
public void pushRange(ByteList begin, int beginCR, ByteList end, int endCR, String file, int beginLine, int endLine, boolean exclusive) {
241241
cacheValuePermanentlyLoadContext("range", RubyRange.class, null, () -> {
242242
compiler.loadContext();
243-
pushFrozenStringUncached(begin, beginCR);
244-
pushFrozenStringUncached(end, endCR);
243+
pushFrozenStringUncached(begin, beginCR, file, beginLine);
244+
pushFrozenStringUncached(end, endCR, file, endLine);
245245
if (exclusive) {
246246
compiler.adapter.invokestatic(p(RubyRange.class), "newExclusiveRange", sig(RubyRange.class, ThreadContext.class, IRubyObject.class, IRubyObject.class));
247247
} else {

‎spec/compiler/general_spec.rb‎

Lines changed: 19 additions & 0 deletions

0 commit comments

Comments
 (0)