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

Inconsistencies when reconstructing with closures #821

Closed
Ellpeck opened this issue May 24, 2024 · 2 comments · Fixed by #823
Closed

Inconsistencies when reconstructing with closures #821

Ellpeck opened this issue May 24, 2024 · 2 comments · Fixed by #823
Assignees
Labels
bug Something isn't working dataflow Related to dataflow extraction reconstruct code deals with the code reoncsutrction at the end of the static slicing

Comments

@Ellpeck
Copy link
Member

Ellpeck commented May 24, 2024

Specifically, these two tests produce (seemingly) unexpected results.

The first test's reconstruction doesn't include the implicit return value of f, which I'm not 100% sure is an error:

		assertSliced(label('nested closures w/ default arguments', ['name-normal', ...OperatorDatabase['<-'].capabilities, 'formals-default', 'numbers', 'newlines', 'lambda-syntax', 'implicit-return', ...OperatorDatabase['+'].capabilities, 'closures', 'grouping']),
			shell, `f <- function(x = 1) {
  (\\(y = 2) function(z = 3) x + y + z)()
}
g <- f(8)
print(g())`, ['5@g'], `f <- function(x=1) {} 
g <- f(8)
g()`)

The second test's reconstruction only calls f once, meaning x's new value will never actually be set.

		assertSliced(label('closure w/ side effects', ['name-normal', ...OperatorDatabase['<-'].capabilities, 'normal-definition', 'newlines', 'closures', ...OperatorDatabase['<<-'].capabilities, 'side-effects-in-function-call', ...OperatorDatabase['+'].capabilities, 'numbers']),
			shell, `f <- function() {
  function() {
    x <<- x + 1
    x
  }
}
x <- 2
f()()
print(x)`, ['9@x'], `f <- function() { function() x <<- x + 1 }
x <- 2
f()
x`)
@Ellpeck Ellpeck added bug Something isn't working reconstruct code deals with the code reoncsutrction at the end of the static slicing labels May 24, 2024
@EagleoutIce
Copy link
Member

This was caused by two independent errors.
The first one was due to unnamed function calls linking the body as entry point, and not the call itself, leading to the df-graph being incapable of detecting that the implicit return of the function (i.e., the inner lambda with \) is actually called.
The second one was an old and outdated guard in the reconstruction which just plainly prevented two () from being set right after each other.

@EagleoutIce EagleoutIce added the dataflow Related to dataflow extraction label May 24, 2024
@EagleoutIce EagleoutIce linked a pull request May 24, 2024 that will close this issue
@EagleoutIce
Copy link
Member

The test-updates should happen in #800.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dataflow Related to dataflow extraction reconstruct code deals with the code reoncsutrction at the end of the static slicing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants