Skip to content

Sema: Ban forward references of captured values from 'defer' body #36441

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 2 commits into from
Mar 16, 2021

Conversation

slavapestov
Copy link
Contributor

While 'defer' is implemented as a local function, it doesn't
behave as one. In particular, since SILGen runs it after
destroying all local bindings that appear after the 'defer'
definition, the body of a 'defer' cannot forward reference
captured bindings the way that local functions can.

Fixes rdar://problem/75088379.

@slavapestov slavapestov changed the title Ban defer forward reference Sema: Ban forward references of captured values from 'defer' body Mar 15, 2021
@slavapestov slavapestov requested a review from jckarter March 15, 2021 20:31
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Slava!

@jckarter
Copy link
Contributor

@swift-ci Please test source compatibility

While 'defer' is implemented as a local function, it doesn't
behave as one. In particular, since SILGen runs it after
destroying all local bindings that appear after the 'defer'
definition, the body of a 'defer' cannot forward reference
captured bindings the way that local functions can.

Note that I had to remove a SILGen test case for an older,
related issue. The new diagnostic in Sema catches these cases
earlier.

Fixes rdar://problem/75088379.
@slavapestov slavapestov force-pushed the ban-defer-forward-reference branch from 8e9f86d to b6381d4 Compare March 15, 2021 21:21
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@slavapestov
Copy link
Contributor Author

slavapestov commented Mar 16, 2021

The source compat failure is an unrelated build system issue in Kickstarter-ReactiveExtensions.

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.

2 participants