Skip to content

Eliminate templated STRING_TYPE and use a factory #4009

@headius

Description

@headius

Currently there are several templates that must be customized to either use java.lang.String or org.jruby.RubySymbol for various string or identifier representations. This is done via the JAVA_STRING_TYPE constant which is customized in template.rb to the specific types used by TruffleRuby and JRuby. Despite the name, this appears to only be used for representing identifiers, e.g. for variables, methods, and class names.

I'd like to eliminate this variability in the Java API by instead providing a factory class that can construct appropriate representations.

The interface might look something like this:

public interface IdentitierFactory<IDType> {
    public IDType newIdentifier();
}

The parser would be set up to accept such a factory on instantiation, and indentifiable nodes it produces would aggregate values of T rather than the templated String or RubySymbol that they do now. This would not change usage of the API significantly, other than requiring TruffleRuby and JRuby to both pass in a factory object for creating identifiers.

Nodes that aggregate identifiers (or aggregate nodes that aggregate identifiers) would be generified to propagate this IDType parameter.

public class Nodes {
    ...
    public static class LocalVariableReadNode<IDType> extends Node {
         ...
         public final IDType name;

This would allow a single Java API to be published that all JVM consumers of the Prism API could use, with only the backends differing (initially publishing a WASM version and later a multi-platform native backend).

As this will require some discussion I'm putting it here as an issue and will for now proceed with publishing a JRuby-specific API artifact so we can ship that in JRuby 10.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    javaPull requests that update Java code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions