Skip to content

Commit a1d2677

Browse files
committed
Swich identifiers to byte[]
* JAVA_STRING_TYPE and related change to IDENTIFIER * TruffleRuby still uses java.lang.String Fixes ruby#4009
1 parent aa6bce6 commit a1d2677

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

templates/java/org/ruby_lang/prism/Loader.java.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%- string_type = Prism::Template::JAVA_STRING_TYPE -%>
1+
<%- string_type = Prism::Template::JAVA_IDENTIFIER_TYPE -%>
22
package org.ruby_lang.prism;
33

44
import java.lang.Short;
@@ -31,7 +31,7 @@ public class Loader {
3131
<%- if string_type == "String" -%>
3232
return new String(bytes, encodingCharset).intern();
3333
<%- else -%>
34-
return null; // Must be implemented by subclassing Loader
34+
return bytes; // Must be implemented by subclassing Loader
3535
<%- end -%>
3636
}
3737

@@ -229,7 +229,7 @@ public class Loader {
229229
private <%= string_type %>[] loadConstants() {
230230
int length = loadVarUInt();
231231
if (length == 0) {
232-
return Nodes.EMPTY_STRING_ARRAY;
232+
return Nodes.EMPTY_IDENTIFIER_ARRAY;
233233
}
234234
<%= string_type %>[] constants = new <%= string_type %>[length];
235235
for (int i = 0; i < length; i++) {
@@ -395,7 +395,7 @@ public class Loader {
395395
int bufferPosition = buffer.position();
396396
int serializedLength = buffer.getInt();
397397
// Load everything except the body and locals, because the name, receiver, parameters are still needed for lazily defining the method
398-
Nodes.DefNode lazyDefNode = new Nodes.DefNode(<%= base_params.join(", ") -%>, -bufferPosition, this, loadConstant(), loadOptionalNode(), (Nodes.ParametersNode) loadOptionalNode(), null, Nodes.EMPTY_STRING_ARRAY);
398+
Nodes.DefNode lazyDefNode = new Nodes.DefNode(<%= base_params.join(", ") -%>, -bufferPosition, this, loadConstant(), loadOptionalNode(), (Nodes.ParametersNode) loadOptionalNode(), null, Nodes.EMPTY_IDENTIFIER_ARRAY);
399399
buffer.position(bufferPosition + serializedLength); // skip past the serialized DefNode
400400
return lazyDefNode;
401401
}

templates/java/org/ruby_lang/prism/Nodes.java.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%- string_type = Prism::Template::JAVA_STRING_TYPE -%>
1+
<%- string_type = Prism::Template::JAVA_IDENTIFIER_TYPE -%>
22
package org.ruby_lang.prism;
33

44
import java.lang.Override;
@@ -16,7 +16,7 @@ import java.util.Arrays;
1616
// @formatter:off
1717
public abstract class Nodes {
1818

19-
public static final <%= string_type %>[] EMPTY_STRING_ARRAY = {};
19+
public static final <%= string_type %>[] EMPTY_IDENTIFIER_ARRAY = {};
2020

2121
@Target(ElementType.FIELD)
2222
@Retention(RetentionPolicy.SOURCE)

templates/template.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module Template # :nodoc: all
1212
CHECK_FIELD_KIND = ENV.fetch("CHECK_FIELD_KIND", false)
1313

1414
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
15-
JAVA_STRING_TYPE = JAVA_BACKEND == "jruby" ? "org.jruby.RubySymbol" : "String"
15+
JAVA_IDENTIFIER_TYPE = JAVA_BACKEND == "truffleruby" ? "String" : "byte[]"
1616
INCLUDE_NODE_ID = !SERIALIZE_ONLY_SEMANTICS_FIELDS || JAVA_BACKEND == "jruby"
1717

1818
COMMON_FLAGS_COUNT = 2
@@ -272,7 +272,7 @@ def call_seq_type
272272
end
273273

274274
def java_type
275-
JAVA_STRING_TYPE
275+
JAVA_IDENTIFIER_TYPE
276276
end
277277
end
278278

@@ -292,7 +292,7 @@ def call_seq_type
292292
end
293293

294294
def java_type
295-
JAVA_STRING_TYPE
295+
JAVA_IDENTIFIER_TYPE
296296
end
297297
end
298298

@@ -312,7 +312,7 @@ def call_seq_type
312312
end
313313

314314
def java_type
315-
"#{JAVA_STRING_TYPE}[]"
315+
"#{JAVA_IDENTIFIER_TYPE}[]"
316316
end
317317
end
318318

0 commit comments

Comments
 (0)