Skip to content

Commit e686e18

Browse files
authored
Simpler regex constants in painless (#68486)
Replaces the double `Pattern.compile` invocations in painless scripts with the fancy constant injection we added in #68088. This caused one of the tests to fail. It turns out that we weren't fully iterating the IR tree during the constant folding phases. I started experimenting and added a ton of tests that failed. Then I fixed them by changing the IR tree walking code.
1 parent 92b59d9 commit e686e18

14 files changed

+80
-95
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreBraceDefNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreBraceNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreDotDefNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreDotNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreDotShortcutNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreFieldMemberNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2727

2828
@Override
2929
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
30-
// do nothing; terminal node
30+
getChildNode().visit(irTreeVisitor, scope);
3131
}
3232

3333
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreListShortcutNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreMapShortcutNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/ir/StoreVariableNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public <Scope> void visit(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
2222

2323
@Override
2424
public <Scope> void visitChildren(IRTreeVisitor<Scope> irTreeVisitor, Scope scope) {
25-
// do nothing; terminal node
25+
getChildNode().visit(irTreeVisitor, scope);
2626
}
2727

2828
/* ---- end visitor ---- */

modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultIRTreeToASMBytesPhase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,10 @@ public void visitConstant(ConstantNode irConstantNode, WriteScope writeScope) {
12161216
*/
12171217
String fieldName = irConstantNode.getDecorationValue(IRDConstantFieldName.class);
12181218
Type asmFieldType = MethodWriter.getType(irConstantNode.getDecorationValue(IRDExpressionType.class));
1219+
if (asmFieldType == null) {
1220+
throw irConstantNode.getLocation()
1221+
.createError(new IllegalStateException("Didn't attach constant to [" + irConstantNode + "]"));
1222+
}
12191223
methodWriter.getStatic(CLASS_TYPE, fieldName, asmFieldType);
12201224
}
12211225
}

0 commit comments

Comments
 (0)