Skip to content

Commit b905519

Browse files
committed
[GR-67702] No warning at usages of nodes annotated with @GenerateInline(false)
PullRequest: graal/21497
2 parents 9a5f11a + 7cbe101 commit b905519

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

truffle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This changelog summarizes major changes between Truffle versions relevant to lan
55
## Version 26.0
66
* GR-65048: Introduced `InternalResource.OS.UNSUPPORTED` and `InternalResource.CPUArchitecture.UNSUPPORTED` to represent unsupported platforms. Execution on unsupported platforms must be explicitly enabled using the system property `-Dpolyglot.engine.allowUnsupportedPlatform=true`. If this property is not set, calls to `OS.getCurrent()` or `CPUArchitecture.getCurrent()` will throw an `IllegalStateException` when running on an unsupported platform. `InternalResource` implementations should handle the unsupported platform and describe possible steps in the error message on how to proceed.
77
* GR-66839: Deprecate `Location#isFinal()` as it always returns false.
8+
* GR-67702: Specialization DSL: For nodes annotated with `@GenerateInline`, inlining warnings emitted for `@Cached` expressions are now suppressed if the inlined node is explicitly annotated with `@GenerateInline(false)`. This avoids unnecessary warnings if inlining for a node was explicitly disabled.
89

910
## Version 25.0
1011
* GR-31495 Added ability to specify language and instrument specific options using `Source.Builder.option(String, String)`. Languages may describe available source options by implementing `TruffleLanguage.getSourceOptionDescriptors()` and `TruffleInstrument.getSourceOptionDescriptors()` respectively.

truffle/docs/DSLNodeObjectInlining.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ For example:
428428
/* ... */
429429

430430
@ExportMessage
431-
final long abs(@Bind("$node") Node node,
431+
final long abs(@Bind Node node,
432432
@Cached InlinedConditionProfile profile) {
433433
if (profile.profile(node, this.value >= 0)) {
434434
return this.value;

truffle/src/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/GenerateInlineTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ public abstract static class ErrorMultiInstanceInliningNeedsNode extends Node {
17451745

17461746
abstract Object execute(Object arg);
17471747

1748-
@ExpectError("For this specialization with inlined cache parameters a '@Bind(\"this\") Node node' parameter must be declared. %")
1748+
@ExpectError("For this specialization with inlined cache parameters a '@Bind Node node' parameter must be declared. %")
17491749
@Specialization(guards = "arg == cachedArg", limit = "3")
17501750
static Object doInt(int arg,
17511751
@Cached(inline = true) SimpleNode simpleNode,
@@ -1796,7 +1796,8 @@ public abstract static class ErrorNotInlinableNode extends Node {
17961796

17971797
@Specialization()
17981798
Object doInt(int arg,
1799-
@ExpectError("The cached node type does not support object inlining. Add @GenerateInline on the node type or disable inline using @Cached(inline=false) to resolve this.") @Cached(inline = true) NoInliningNode simpleNode) {
1799+
@ExpectError("The cached node type does not support object inlining. " +
1800+
"Add @GenerateInline or @GenerateInline(false) on the node type or disable inlining using @Cached(inline=false) to resolve this.") @Cached(inline = true) NoInliningNode simpleNode) {
18001801
return "";
18011802
}
18021803

@@ -2327,7 +2328,7 @@ final boolean isPointer() {
23272328
return false;
23282329
}
23292330

2330-
@ExpectError("For this specialization with inlined cache parameters a '@Bind(\"$node\") Node node' parameter must be declared.%")
2331+
@ExpectError("For this specialization with inlined cache parameters a '@Bind Node node' parameter must be declared.%")
23312332
@ExportMessage
23322333
long asPointer(@Cached InlinedBranchProfile profile) {
23332334
return 0L;
@@ -2346,7 +2347,7 @@ final boolean isPointer() {
23462347

23472348
@ExportMessage
23482349
static class AsPointer {
2349-
@ExpectError("For this specialization with inlined cache parameters a '@Bind(\"$node\") Node node' parameter must be declared.%")
2350+
@ExpectError("For this specialization with inlined cache parameters a '@Bind Node node' parameter must be declared.%")
23502351
@Specialization
23512352
static long asPointer(ErrorUseBindParamterInLibraryExport2 receiver, @Cached InlinedBranchProfile profile) {
23522353
return 0L;

truffle/src/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/NodeParser.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ private void verifyRecommendationWarnings(NodeData node, boolean recommendInline
608608

609609
if (recommendInline && !node.isGenerateInline() && mode == ParseMode.DEFAULT && node.isGenerateCached()) {
610610

611-
AnnotationMirror annotation = getGenerateInlineAnnotation(node.getTemplateType());
611+
AnnotationMirror annotation = getGenerateInlineAnnotation(node.getTemplateType().asType());
612612
if (annotation == null) {
613613

614614
NodeSizeEstimate estimate = computeInlinedSizeEstimate(FlatNodeGenFactory.createInlinedFields(node));
@@ -709,13 +709,7 @@ private void verifyRecommendationWarnings(NodeData node, boolean recommendInline
709709
}
710710

711711
if (!hasNodeParameter) {
712-
String nodeParameter;
713-
if (mode == ParseMode.EXPORTED_MESSAGE) {
714-
nodeParameter = String.format("@%s(\"$node\") Node node", getSimpleName(types.Bind));
715-
} else {
716-
nodeParameter = String.format("@%s(\"this\") Node node", getSimpleName(types.Bind));
717-
}
718-
712+
String nodeParameter = String.format("@%s Node node", getSimpleName(types.Bind));
719713
String message = String.format(
720714
"For this specialization with inlined cache parameters a '%s' parameter must be declared. " + //
721715
"This parameter must be passed along to inlined cached values. " +
@@ -954,7 +948,7 @@ private boolean initializeInlinable(DSLExpressionResolver resolver, NodeData nod
954948
VariableElement instanceField = getNodeFirstInstanceField(node.getTemplateType());
955949
if (instanceField != null) {
956950
if (emitErrors) {
957-
node.addError(getGenerateInlineAnnotation(node.getTemplateType()), null, "Failed to generate code for @%s: The node must not declare any instance variables. " +
951+
node.addError(getGenerateInlineAnnotation(node.getTemplateType().asType()), null, "Failed to generate code for @%s: The node must not declare any instance variables. " +
958952
"Found instance variable %s.%s. Remove instance variable to resolve this.",
959953
getSimpleName(types.GenerateInline),
960954
getSimpleName(instanceField.getEnclosingElement().asType()), instanceField.getSimpleName().toString());
@@ -1024,16 +1018,16 @@ public static boolean isGenerateUncached(TypeElement templateType) {
10241018
}
10251019

10261020
static boolean isGenerateInline(TypeElement templateType) {
1027-
AnnotationMirror annotation = getGenerateInlineAnnotation(templateType);
1021+
AnnotationMirror annotation = getGenerateInlineAnnotation(templateType.asType());
10281022
Boolean value = Boolean.FALSE;
10291023
if (annotation != null) {
10301024
value = ElementUtils.getAnnotationValue(Boolean.class, annotation, "value");
10311025
}
10321026
return value;
10331027
}
10341028

1035-
static AnnotationMirror getGenerateInlineAnnotation(TypeElement templateType) {
1036-
return findGenerateAnnotation(templateType.asType(), ProcessorContext.getInstance().getTypes().GenerateInline);
1029+
static AnnotationMirror getGenerateInlineAnnotation(TypeMirror type) {
1030+
return findGenerateAnnotation(type, ProcessorContext.getInstance().getTypes().GenerateInline);
10371031
}
10381032

10391033
public static AnnotationMirror findGenerateAnnotation(TypeMirror nodeType, DeclaredType annotationType) {
@@ -3767,13 +3761,15 @@ private void parseCached(CacheExpression cache, SpecializationData specializatio
37673761
if (declaresInline) {
37683762
cache.addError(cachedAnnotation, getAnnotationValue(cachedAnnotation, "inline"),
37693763
"The cached node type does not support object inlining." + //
3770-
" Add @%s on the node type or disable inline using @%s(inline=false) to resolve this.",
3764+
" Add @%s or @%s(false) on the node type or disable inlining using @%s(inline=false) to resolve this.",
3765+
getSimpleName(types.GenerateInline),
37713766
getSimpleName(types.GenerateInline),
37723767
getSimpleName(types.Cached));
3773-
} else if (node.isGenerateInline()) {
3768+
} else if (node.isGenerateInline() && NodeCodeGenerator.isSpecializedNode(cache.getParameter().getType()) && !isGenerateInlineFalse(cache)) {
37743769
cache.addSuppressableWarning(TruffleSuppressedWarnings.INLINING_RECOMMENDATION,
37753770
"The cached node type does not support object inlining." + //
3776-
" Add @%s on the node type or disable inline using @%s(inline=false) to resolve this.",
3771+
" Add @%s or @%s(false) on the node type or disable inlining using @%s(inline=false) to resolve this.",
3772+
getSimpleName(types.GenerateInline),
37773773
getSimpleName(types.GenerateInline),
37783774
getSimpleName(types.Cached));
37793775
inline = false;
@@ -4148,7 +4144,7 @@ private List<InlineFieldData> parseInlineMethod(MessageContainer errorContainer,
41484144
* on. This enables that @Cached InlinedBranchProfile inlines by default even if a cached
41494145
* version is generated and no warning is printed.
41504146
*/
4151-
private boolean forceInlineByDefault(CacheExpression cache) {
4147+
private static boolean forceInlineByDefault(CacheExpression cache) {
41524148
AnnotationMirror cacheAnnotation = cache.getMessageAnnotation();
41534149
TypeElement parameterType = ElementUtils.castTypeElement(cache.getParameter().getType());
41544150
if (parameterType == null) {
@@ -4158,8 +4154,8 @@ private boolean forceInlineByDefault(CacheExpression cache) {
41584154
if (defaultCached && !hasDefaultCreateCacheMethod(parameterType.asType())) {
41594155
return hasInlineMethod(cache);
41604156
}
4161-
if (ElementUtils.isAssignable(parameterType.asType(), types.Node)) {
4162-
AnnotationMirror inlineAnnotation = getGenerateInlineAnnotation(parameterType);
4157+
if (NodeCodeGenerator.isSpecializedNode(parameterType.asType())) {
4158+
AnnotationMirror inlineAnnotation = getGenerateInlineAnnotation(parameterType.asType());
41634159
if (inlineAnnotation != null) {
41644160
return getAnnotationValue(Boolean.class, inlineAnnotation, "value") &&
41654161
getAnnotationValue(Boolean.class, inlineAnnotation, "inlineByDefault");
@@ -4168,6 +4164,18 @@ private boolean forceInlineByDefault(CacheExpression cache) {
41684164
return false;
41694165
}
41704166

4167+
private static boolean isGenerateInlineFalse(CacheExpression cache) {
4168+
TypeMirror type = cache.getParameter().getType();
4169+
if (!NodeCodeGenerator.isSpecializedNode(type)) {
4170+
return false;
4171+
}
4172+
AnnotationMirror inlineAnnotation = getGenerateInlineAnnotation(type);
4173+
if (inlineAnnotation != null && getAnnotationValue(Boolean.class, inlineAnnotation, "value") == false) {
4174+
return true;
4175+
}
4176+
return false;
4177+
}
4178+
41714179
private static boolean hasInlineMethod(CacheExpression cache) {
41724180
TypeMirror type = cache.getParameter().getType();
41734181
TypeElement parameterType = ElementUtils.castTypeElement(type);

0 commit comments

Comments
 (0)