Skip to content

Special-case Pattern Binding Decls Created by LLDB #3020

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

Merged
merged 1 commit into from
Jun 4, 2021

Conversation

CodaFi
Copy link

@CodaFi CodaFi commented Jun 2, 2021

When LLDB wraps a user-defined expression in the REPL, it takes something like this

<expr>

and turns it into (very very abstractly)

var result
do {
  result = <expr>
}
print(result)

In the process, it creates an implicit pattern binding and an implicit do block. Of these, only the implicit do is considered by ASTScope lookup to be relevant. This presents a problem when <expr> is or contains a closure, as the parameters of that closure are defined within a scope that will never be expanded. Thus,

> [42].map { x in x } // <- cannot find 'x' in scope

This patch provides the LLDB half of the fix wherein we consume the
infrastructure in the Swift half and readjust the source locations of
the implicit braced block so ASTScope is happy to look up variables
defined in its body.

rdar://78256873

When LLDB wraps a user-defined expression in the REPL, it takes something like this
```
<expr>
```

and turns it into (very very abstractly)

```
var result
do {
  result = <expr>
}
print(result)
```

In the process, it creates an implicit pattern binding and an implicit do block. Of these, only the implicit do is considered by ASTScope lookup to be relevant. This presents a problem when <expr> is or contains a closure, as the parameters of that closure are defined within a scope that will never be expanded. Thus,

```
> [42].map { x in x } // <- cannot find 'x' in scope
```

This patch provides the LLDB half of the fix wherein we consume the
infrastructure in the Swift half and readjust the source locations of
the implicit braced block so ASTScope is happy to look up variables
defined in its body.

rdar://78256873
@CodaFi
Copy link
Author

CodaFi commented Jun 2, 2021

swiftlang/swift#37742

@swift-ci test

@CodaFi CodaFi merged commit 875ab94 into swiftlang:swift/main Jun 4, 2021
@CodaFi CodaFi deleted the kaleidoscope branch June 4, 2021 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant