Skip to content

Move variable slotting to the IR tree#51452

Merged
jdconrad merged 4 commits intoelastic:masterfrom
jdconrad:trees2
Jan 28, 2020
Merged

Move variable slotting to the IR tree#51452
jdconrad merged 4 commits intoelastic:masterfrom
jdconrad:trees2

Conversation

@jdconrad
Copy link
Copy Markdown
Contributor

Currently, variable slotting (a variable's index on the ASM stack) is generated by the user tree during semantic checking. With the split it no longer makes sense to have the user tree generate a variable's slot. This PR moves variable slot allocation to the IR tree using the class ScopeTable. This class holds variables currently in scope and calculates an appropriate slot for them. This also allows for optimization phases to occur on the IR tree because now variables can be injected without having to update slotting.

For review the most important class to look at in this PR is the newly added ScopeTable. The majority of this PR is boilerplate adding ScopeTable to the IR nodes write method signature.

@jdconrad jdconrad added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >refactoring v8.0.0 labels Jan 24, 2020
@elasticmachine
Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
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.

Looks good, a couple minor suggestions


public class DoWhileLoopNode extends LoopNode {

public DoWhileLoopNode() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need an explicit empty ctor the same as the default ctor?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Missed this during the merge.

methodWriter.visitVarInsn(MethodWriter.getType(variable.clazz).getOpcode(Opcodes.ISTORE), variable.getSlot());
methodWriter.visitVarInsn(variable.getAsmType().getOpcode(Opcodes.ISTORE), variable.getSlot());

Variable loop = scopeTable.getVariable("#loop");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we could have another method for special/private/hidden (whatever we want to call them) variables? I'd rather have a dedicated method than have to remember # is outside our grammar and so this cannot collide with user variables.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added defineInternalVariable and getInternalVariable to address this specific issue. Let me know if you'd prefer a different name, but I like "internal" because I think it makes it clear this is something defined by the compiler rather than a user.

@jdconrad
Copy link
Copy Markdown
Contributor Author

@rjernst Thanks for the review!

@jdconrad
Copy link
Copy Markdown
Contributor Author

jdconrad commented Jan 28, 2020

@stu-elastic I'd like to continue to make progress on this, so I'm going to go ahead and merge with the approval from @rjernst. When you have more time, I'm happy to go over the code here and make follow up PR changes if necessary.

@jdconrad jdconrad merged commit 9d2c579 into elastic:master Jan 28, 2020
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 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants