Skip to content

Use better typing for dynamic method calls#18234

Merged
rmuir merged 1 commit intoelastic:masterfrom
rmuir:more_indy_type_data
May 10, 2016
Merged

Use better typing for dynamic method calls#18234
rmuir merged 1 commit intoelastic:masterfrom
rmuir:more_indy_type_data

Conversation

@rmuir
Copy link
Copy Markdown
Contributor

@rmuir rmuir commented May 10, 2016

Today painless boxes/casts all the parameters as Object. But I think instead we should pass the parameter types we have and let asType take care? It may be able to e.g. avoid boxing or other conversions in some situations.

FYI: I thought about this a lot, I like doing it here in the bytecode emitter, even though it looks strange, because its an implementation detail of how we make the call work.

@uschindler @jdconrad

@uschindler
Copy link
Copy Markdown
Contributor

uschindler commented May 10, 2016

+1

We should be able to do the same for array loads and stores and field stores, so index ints are passed as integers not as Integer. You just have to remove the static DESCRIPTOR from WriterConstants which is currently used and build one with MethodType.methodType(Object.class, arg, arg) or ASM's Type.getMethodDescriptor() for array setters and field setters.

@rmuir
Copy link
Copy Markdown
Contributor Author

rmuir commented May 10, 2016

@uschindler yeah, in that case it is just less clear how to get to the type information and disable casting. The same applies to regular Def loads and stores too, and also return values :)

Basically we should make use of all the typing we have and not issue our own casts/conversion to Object.

@jdconrad
Copy link
Copy Markdown
Contributor

LGTM!

@uschindler
Copy link
Copy Markdown
Contributor

uschindler commented May 10, 2016

@jdconrad What we would need is a hit to do the same for field stores and array stores. The method to write the field store only writes the instruction, but the types are not available from context. For array loads/stores we also dont have the type of the "index".

@rmuir are you sure that the PR logic works? To me it is strange that you try to prevent the casting so late! At this point in time the arguments were already pushed to stack, so they are already objects. Or do I miss something?

@rmuir
Copy link
Copy Markdown
Contributor Author

rmuir commented May 10, 2016

At this point in time the arguments were already pushed to stack, so they are already objects. Or do I miss something?

Wait thats not true. They arent pushed until visit is called: line 724 in the loop.

@jdconrad
Copy link
Copy Markdown
Contributor

@uschindler For the question addressed to @rmuir -- this does work as he changes the cast then visits the argument which is responsible for writing its own cast after it's written whatever expression is contains. As for the first part, I'll see what I can do to get the other types available for consumption of the array/field indices.

@uschindler
Copy link
Copy Markdown
Contributor

uschindler commented May 10, 2016

Hi,

sorry my fault. I missed the writer.visit(). Reason for this is because it was not a call on the execute objects, so I did not see it. The writer writes to the same execute object (the GeneratorAdaptor). Sorry for this.

@jdconrad: The main difference to field stores/loads and array stores/loads is that those arguments are indeed before actual call on stack, so you have no access to types anymore. If we could change this, it would be great! I am not only talking about the array index type, for field-/array-stores also about the type of the object to store.

@jdconrad
Copy link
Copy Markdown
Contributor

@uschindler On the array/field loads/stores, this is definitely a tricky issue. It's a good point you make about not being able to do it the same way as we are for call here. I need to give it a bit of thought about the best way to provide this.

@rmuir rmuir merged commit ddc2c1f into elastic:master May 10, 2016
@rmuir
Copy link
Copy Markdown
Contributor Author

rmuir commented May 10, 2016

I pushed this for the dynamic method calls. I agree, we should fix this for other cases too if we can, and try to reduce overhead in those cases!

@jdconrad jdconrad mentioned this pull request May 12, 2016
18 tasks
@clintongormley clintongormley changed the title painless: use better typing for dynamic method calls Use better typing for dynamic method calls May 17, 2016
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Plugin Lang Painless labels Feb 14, 2018
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 >enhancement v5.0.0-alpha3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants