Skip to content

Infer lambda arguments/return type#18983

Merged
rmuir merged 1 commit intoelastic:masterfrom
rmuir:lambda_types
Jun 20, 2016
Merged

Infer lambda arguments/return type#18983
rmuir merged 1 commit intoelastic:masterfrom
rmuir:lambda_types

Conversation

@rmuir
Copy link
Copy Markdown
Contributor

@rmuir rmuir commented Jun 20, 2016

We setup lambdas with optional typing and return value of def. But if we know the functional interface, we should use the type info we have, and replace all def with the real type.

Today things work, but for example all Predicate's return values are boxed for no good reason.
Of course the worst case is primitive specializations of interfaces:

.mapToDouble(Double::valueOf).map(x -> x + 1)

Instead of:

  private static synthetic lambda$0(Ljava/lang/Object;)Ljava/lang/Object;
    ALOAD 0
    ICONST_1
    INVOKEDYNAMIC add(Ljava/lang/Object;I)Ljava/lang/Object; [
      // handle kind 0x6 : INVOKESTATIC
      org/elasticsearch/painless/DefBootstrap.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;I[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;
      // arguments:
      8, 
      0
    ]
    ARETURN

We do:

  private static synthetic lambda$0(D)D
    DLOAD 0
    DCONST_1
    DADD
    DRETURN

In order for things to be consistent, I added the ability to call methods on primitive types so that we can always replace def with its corresponding primitive if needed and it behaves the same.

@jdconrad
Copy link
Copy Markdown
Contributor

LGTM!

@jdconrad jdconrad mentioned this pull request Jun 20, 2016
18 tasks
@rmuir rmuir merged commit 1b7d35e into elastic:master Jun 20, 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-alpha4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants