Skip to content

[move-only] Implement escaping closure semantics part 1 #63783

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 9 commits into from
Feb 21, 2023

Conversation

gottesmm
Copy link
Contributor

This patch series does a bunch of things:

  1. Patch 1 changes SILGen/MoveCheckers to emit vars in a boxed eagerly retroject manner.
  2. Patch 2 changes "" to also emit lets to be emitted as boxes like vars.
  3. Patch 3 changes "" to emit owned arguments again as boxed.
  4. Part 4 implements on top of this escaping closure semantics.

This basically required me to rewrite a large part of SILGen for non copyable types and redesign parts of the checker as well. I also had to do a bunch of work in alloc box to stack to massage its output since it semantically is what controls whether we use non-escaping or escaping semantics when we emit these errors.

…gerly projected box form.

This is the first slice of bringing up escaping closure support. The support is
based around introducing a new type of SILGen VarLoc: a VarLoc with a box and
without a value. Because the VarLoc only has a box, we have to in SILGen always
eagerly reproject out the address from the box. The reason why I am doing this
is that it makes it easy for the move checker to distinguish in between
different accesses to the box that we want to check separately. As such every
time that we open the box, we insert a mark_must_check
[assignable_but_not_consumable] on that project. If allocbox_to_stack manages to
determine that the box can be stack allocated, we eliminate all of the
mark_must_check and place a new mark_must_check [consumable_and_assignable] on
the alloc_stack.  The end result is that we get the old model that we had before
and also can support escaping closures.
Some notes:

1. This ensures that if we capture them, we just capture the box by reference.

2. We are still using the old incorrect semantics for captures. I am doing this
   so I can bring this up in separate easy to understand patches all of which
   pass all of the moveonly tests.

3. Most of the test edits are due to small differences in error messages in
   between the object and address checker.

4. I had to add a little support to the move only address checker for a small
   pattern that doesn't occur with vars but do es occur for lets when we codegen
   like this, specifically around enums. The pattern is we perform a load_borrow
   and then copy_value and then use the result of the copy_value. Rather than fight
   SILGen pattern I introduced a small canonicalization into the address checker which
   transforms that pattern into a load [copy] + begin_borrow to restore the codegen
   to a pattern the checker expects.

5. I left noimplicitcopy alone for now. But we should come back around and fix
   it in a similar way. I just did not have time to do so.
NOTE: A few of the test patterns need to be made better, but this patch series
is large enough, I want to get it into tree and iterate.
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

Thanks to JoeG for seeing this quickly and preventing me from having to track
this down!
…escaping closure since we will already emit a more specific capture error.
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci build toolchain

@gottesmm
Copy link
Contributor Author

Linux failure was unrelated problem in dispatch.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test linux platform

@gottesmm
Copy link
Contributor Author

Windows failed b/c I left in some optnone by mistake from when I was debugging

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

@swift-ci build toolchain

@gottesmm
Copy link
Contributor Author

@swift-ci clean smoke test linux platform

@gottesmm gottesmm merged commit 598ac05 into swiftlang:main Feb 21, 2023
@gottesmm gottesmm deleted the no-escaping-closure-part-1 branch February 21, 2023 03:46
ludwwwig added a commit to ludwwwig/swift that referenced this pull request May 3, 2025
This header was supposed to be deleted by swiftlang#63783.
ludwwwig added a commit to ludwwwig/swift that referenced this pull request May 3, 2025
This header was supposed to be deleted by swiftlang#63783.
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