Skip to content

Add nodes to handle types #49785

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

Merged
merged 4 commits into from
Dec 6, 2019
Merged

Add nodes to handle types #49785

merged 4 commits into from
Dec 6, 2019

Conversation

jdconrad
Copy link
Contributor

@jdconrad jdconrad commented Dec 2, 2019

This PR adds 3 nodes to handle types defined by a front-end creating a Painless AST. These types are decided with data immutability in mind - hence the reason for more than a single node.

DType - base class to allow for a getType call
DUnresolvedType - stores a String to be resolved to a type
DResolvedType - stores a Class<?> representative of a type

Initially this accomplishes consistency in how types are resolved in Painless instead of having loose types across multiple nodes. This PR replaces the type in SDeclaration as an example of usage, and follow up PRs will replace them in all nodes that have defined types.

Secondarily, this will be used allow future Painless improvements including making the AST more generic with the removal of custom try/catch handling as an example because now if we know a type internally we can just use a DResolvedType node instead of being forced to define a String type and resolve it multiple times.

Finally, this will be helpful if/when we decide to create a separate IR for valid semantic trees.

Edit: Adding @stu-elastic for visibility.

@jdconrad jdconrad added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >refactoring v8.0.0 v7.6.0 labels Dec 2, 2019
@jdconrad jdconrad requested a review from rjernst December 2, 2019 22:23
@elasticmachine
Copy link
Collaborator

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

@jdconrad jdconrad requested a review from stu-elastic December 2, 2019 22:24

import java.util.Objects;

public class DResolvedType extends DType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add javadoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

public class DResolvedType extends DType {

protected final Class<?> type;
protected final boolean check;
Copy link
Contributor

Choose a reason for hiding this comment

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

check means check against the whitelist, correct? Please add a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Also renamed to checkInLookup.

}

return new DResolvedType(location, type, false);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do if (check == false) { return this; } to reduce the indention level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@stu-elastic stu-elastic left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -37,13 +37,13 @@
*/
public final class SDeclaration extends AStatement {

private final String type;
private DType type;
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment here explaining why this is mutable and what are plans are moving forward here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to final instead. Will add mutable DResolvedType nodes where necessary as the conversions take place. These should be removed with the creation of a second tree.

@jdconrad
Copy link
Contributor Author

jdconrad commented Dec 5, 2019

@rjernst @stu-elastic Thanks for the reviews. I believe I've addressed the feedback, and I will commit as soon as CI passes.

@jdconrad jdconrad merged commit f2d25f5 into elastic:master Dec 6, 2019
jdconrad added a commit that referenced this pull request Dec 6, 2019
This PR adds 3 nodes to handle types defined by a front-end creating a 
Painless AST. These types are decided with data immutability in mind - 
hence the reason for more than a single node.
SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this pull request Jan 23, 2020
This PR adds 3 nodes to handle types defined by a front-end creating a 
Painless AST. These types are decided with data immutability in mind - 
hence the reason for more than a single node.
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 >refactoring v7.6.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants