Optimize annotations without object bodies (#1843)

This skips some unnecessary steps when evaluating annotations that
have no attached object bodies by returning an EmptyObjectLiteralNode
instead of a PropertiesLiteralNode
This commit is contained in:
Daniel Chao
2026-09-02 13:04:26 -07:00
committed by GitHub
parent 0035199176
commit 92b26aca17
2 changed files with 3 additions and 12 deletions
@@ -2224,17 +2224,7 @@ public class AstBuilder extends AbstractAstBuilder<Object> {
var bodyCtx = annotation.getBody();
if (bodyCtx == null) {
var currentScope = symbolTable.getCurrentScope();
//noinspection ConstantConditions
return PropertiesLiteralNodeGen.create(
createSourceSection(annotation),
language,
currentScope.getQualifiedName(),
currentScope.isCustomThisScope(),
null,
new UnresolvedTypeNode[0],
EconomicMaps.create(),
verifyNode);
return EmptyObjectLiteralNodeGen.create(createSourceSection(annotation), verifyNode);
}
return symbolTable.enterAnnotationScope(
@@ -24,7 +24,7 @@ import org.pkl.core.ast.type.UnresolvedTypeNode;
import org.pkl.core.runtime.*;
public final class CheckIsAnnotationClassNode extends ExpressionNode {
@Child private UnresolvedTypeNode unresolvedTypeNode;
@Child private @Nullable UnresolvedTypeNode unresolvedTypeNode;
@Child private @Nullable TypeNode typeNode;
public CheckIsAnnotationClassNode(UnresolvedTypeNode unresolvedTypeNode) {
@@ -37,6 +37,7 @@ public final class CheckIsAnnotationClassNode extends ExpressionNode {
if (typeNode == null) {
// invalidation is done by insert()
CompilerDirectives.transferToInterpreter();
assert unresolvedTypeNode != null;
typeNode = insert(unresolvedTypeNode.execute(frame));
unresolvedTypeNode = null;
}