RFR: JDK-8285932 Implementation of JEP-430 String Templates (Preview) [v11]
Jorn Vernee
jvernee at openjdk.org
Wed Nov 2 20:13:22 UTC 2022
On Wed, 2 Nov 2022 19:44:00 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:
>> Enhance the Java programming language with string templates, which are similar to string literals but contain embedded expressions. A string template is interpreted at run time by replacing each expression with the result of evaluating that expression, possibly after further validation and transformation. This is a [preview language feature and API](http://openjdk.java.net/jeps/12).
>
> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
>
> Internalize TemplateSupport
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1103:
> 1101: }
> 1102:
> 1103: MethodHandle mh = MethodHandles.dropArguments(newString(), 2, ttypes);
The code here us pretty dense. I suggest adding comments that show the type of `mh` as far as it is known. I think it makes it a much easier to keep track of what all the argument indexes mean. e.g.
Suggestion:
// (byte[],long,ttypes...) -> String
MethodHandle mh = MethodHandles.dropArguments(newString(), 2, ttypes);
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1118:
> 1116: MethodHandle prepender = prepender(lastFragment.isEmpty() ? null : fragment, ttype);
> 1117: initialLengthCoder = JLA.stringConcatMix(initialLengthCoder, fragment);
> 1118: mh = MethodHandles.filterArgumentsWithCombiner(mh, 1, prepender,1, 0, 2 + pos);
Suggestion:
Class<?> ttype = ttypes[pos];
// (long,byte[],ttype) -> String
MethodHandle prepender = prepender(lastFragment.isEmpty() ? null : fragment, ttype);
initialLengthCoder = JLA.stringConcatMix(initialLengthCoder, fragment);
// (byte[],long,ttypes...) -> String (unchanged)
mh = MethodHandles.filterArgumentsWithCombiner(mh, 1, prepender,1, 0, 2 + pos);
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1125:
> 1123: MethodHandle newArrayCombinator = lastFragment.isEmpty() ? newArray() :
> 1124: newArrayWithSuffix(lastFragment);
> 1125: mh = MethodHandles.foldArgumentsWithCombiner(mh, 0, newArrayCombinator,
Suggestion:
// (long,ttypes...) -> String
mh = MethodHandles.foldArgumentsWithCombiner(mh, 0, newArrayCombinator,
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java line 1143:
> 1141: 0, // old-index
> 1142: 1 + pos // selected argument
> 1143: );
Suggestion:
// (long,ttype) -> long
MethodHandle mix = mixer(ttypes[pos]);
boolean lastPType = pos == ttypes.length - 1;
if (lastPType) {
// (ttype) -> long
mix = MethodHandles.insertArguments(mix, 0, initialLengthCoder);
// (ttypes...) -> String
mh = MethodHandles.foldArgumentsWithCombiner(mh, 0, mix,
1 + pos // selected argument
);
} else {
// (long,ttypes...) -> String
mh = MethodHandles.filterArgumentsWithCombiner(mh, 0, mix,
0, // old-index
1 + pos // selected argument
);
-------------
PR: https://git.openjdk.org/jdk/pull/10889
More information about the compiler-dev
mailing list