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

Script: track this pointer capture from blocks within lambdas #82228

Merged

Conversation

stu-elastic
Copy link
Contributor

@stu-elastic stu-elastic commented Jan 4, 2022

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the this pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
illegal_state_exception:

no 'this' pointer within static method

BlockScope now forwards setUsesInstanceMethod calls to
it's parent, which may be a LambdaScope.

LambdaScope will also forward setUsesInstanceMethod to
it's parent after setting it's own usesInstanceMethod flag,
propagating this pointer capture in the case of nested lambdas.

Fixes: #82224

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
Propagating `this` pointer capture in the case of nested lambdas.

Fixes: elastic#82224
@stu-elastic stu-elastic requested a review from jdconrad January 4, 2022 20:15
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Jan 4, 2022
@elasticmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @stu-elastic, I've created a changelog YAML for you.

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! Thanks for the fast fix. I would suggest updating the comment for setUsesInstanceMethod as part of the base Scope class as well since BlockScope is also changed now.

@stu-elastic
Copy link
Contributor Author

Comment is updated.

@stu-elastic stu-elastic merged commit 57ac810 into elastic:master Jan 4, 2022
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this pull request Jan 4, 2022
…c#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: elastic#82224
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this pull request Jan 4, 2022
…c#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: elastic#82224
stu-elastic added a commit to stu-elastic/elasticsearch that referenced this pull request Jan 4, 2022
…c#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: elastic#82224
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.0
7.17
7.16

elasticsearchmachine pushed a commit that referenced this pull request Jan 4, 2022
#82235)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: #82224
elasticsearchmachine pushed a commit that referenced this pull request Jan 4, 2022
…82228) (#82237)

* Script: track this pointer capture from blocks within lambdas (#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: #82224

* org.elasticsearch.core.Map.of
elasticsearchmachine pushed a commit that referenced this pull request Jan 4, 2022
…82228) (#82236)

* Script: track this pointer capture from blocks within lambdas (#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: #82224

* org.elasticsearch.core.Map.of
astefan pushed a commit to astefan/elasticsearch that referenced this pull request Jan 7, 2022
…c#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: elastic#82224
astefan pushed a commit to astefan/elasticsearch that referenced this pull request Jan 7, 2022
…c#82228)

* Script: track this pointer capture from blocks within lambdas

If a lambda contains a block that calls into a user function,
the painless compiler was not tracking that the lambda needs
to capture the `this` pointer.

Scripts that attempted to use a lambda that calls a user
function from inside a block would trigger an
`illegal_state_exception`:

> no 'this' pointer within static method

`BlockScope` now forwards `setUsesInstanceMethod` calls to
it's parent, which may be a `LambdaScope`.

`LambdaScope` will also forward `setUsesInstanceMethod` to
it's parent after setting it's own `usesInstanceMethod` flag,
propagating `this` pointer capture in the case of nested lambdas.

Fixes: elastic#82224
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache Team:Core/Infra Meta label for core/infra team v7.16.3 v7.17.0 v8.0.0-rc2 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calling user-defined methods within an if/else block in a lambda causes a failure
5 participants