Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simpler regex constants in painless #68486

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Feb 3, 2021

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.

@nik9000 nik9000 added >non-issue :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v8.0.0 v7.12.0 labels Feb 3, 2021
@nik9000 nik9000 requested a review from jdconrad February 3, 2021 20:18
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Feb 3, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Replaces the double `Pattern.compile` invocations in painless scripts
with the fancy constant injection we added in elastic#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.
@nik9000
Copy link
Member Author

nik9000 commented Feb 3, 2021

I've marked this a non-issue because it fixes a bug in unreleased code - the grok and dissect functions in runtime fields wouldn't work without the tree rewriting fixes I bumped into.

assertEquals(true, exec("return 'foo' ==~ /foo/ ? true : false"));
assertEquals(1, exec("def i = 0; i += 'foo' ==~ /foo/ ? 1 : 1; return i"));
assertEquals(1, exec("def i = 0; i += 'foo' ==~ /foo/ ? 1 : 0; return i"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a mistake.

@@ -232,6 +232,30 @@ public void testReplaceFirstQuoteReplacement() {
exec("'the quick brown fox'.replaceFirst(/[aeiou]/, m -> '$' + m.group().toUpperCase(Locale.ROOT))"));
}

public void testStoreInMap() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be useful to have similar tests in the constant folding tests that verify that we fold constants in these positions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the bytecode assertion for that kind of test.

Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for fixing this up.

@@ -1216,6 +1216,10 @@ public void visitConstant(ConstantNode irConstantNode, WriteScope writeScope) {
*/
String fieldName = irConstantNode.getDecorationValue(IRDConstantFieldName.class);
Type asmFieldType = MethodWriter.getType(irConstantNode.getDecorationValue(IRDExpressionType.class));
if (asmFieldType == null) {
throw irConstantNode.getLocation()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to say this should never happen outside of bugs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I just wanted to get a better error message for my debugging. Is ok? Should I throw the exception in another way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good. I just wanted to make sure I wasn't missing something user related.

@nik9000 nik9000 merged commit e686e18 into elastic:master Feb 3, 2021
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Feb 3, 2021
Replaces the double `Pattern.compile` invocations in painless scripts
with the fancy constant injection we added in elastic#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.
nik9000 added a commit that referenced this pull request Feb 4, 2021
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >non-issue Team:Core/Infra Meta label for core/infra team v7.12.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants