Skip to content

polish up the noncopyable diagnostics #66090

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 10 commits into from
May 25, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented May 23, 2023

🚧 here be lots of find-replace 🚧

  • replaces "move-only" terminology with "noncopyable"
  • replaces compiler jargon like "guaranteed parameters"
    and "lvalue" with corresponding language-level notions
  • simplifies diagnostics about closures.

and probably more.

rdar://109281444

@kavon kavon marked this pull request as draft May 23, 2023 19:26
@kavon kavon force-pushed the noncopyable-diagnostics-cleanup branch from 76d7c6f to ee63610 Compare May 23, 2023 23:22
@kavon
Copy link
Member Author

kavon commented May 23, 2023

@swift-ci smoke test linux

@kavon kavon force-pushed the noncopyable-diagnostics-cleanup branch 2 times, most recently from 875933e to 7af33a5 Compare May 24, 2023 04:25
@kavon kavon changed the title Noncopyable diagnostics cleanup polish up the noncopyable diagnostics May 24, 2023
@kavon
Copy link
Member Author

kavon commented May 24, 2023

@swift-ci please test

@kavon kavon marked this pull request as ready for review May 24, 2023 04:40
@kavon kavon requested review from zoecarver, hyp and egorzhdan as code owners May 24, 2023 04:40
"'%0' consumed in closure. This is illegal since if the closure is invoked more than once the binding will be uninitialized on later invocations", (StringRef))
"'%0' is borrowed and cannot be consumed by closure capture", (StringRef))

ERROR(sil_moveonlychecker_capture_consumed_in_closure, none,
Copy link
Contributor

Choose a reason for hiding this comment

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

I looked through the patch and I think you are using this for escaping closures. I think there are two problems here:

  1. I think the information that the closure is escaping is important for the user to understand. We should tell the user that especially since we made the change to make non-escaping lets non-escaping. That provides a lot of clarity to the user.
  2. This diagnostic as shown below also occurs when a value that is captured by an escaping closure is used outside of the closure itself (the property is not flow sensitive). So the diagnostic says the use is in a closure, but it clearly isn't which is misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like the main thing we need to communicate is that a mutable capture can be consumed in a closure, but an immutable one cannot. That doesn't change whether the closure is passed to an @escaping parameter or not.

@kavon kavon force-pushed the noncopyable-diagnostics-cleanup branch from 07eb7ad to 8340753 Compare May 25, 2023 03:15
kavon added 6 commits May 24, 2023 20:56
- replaces "move-only" terminology with "noncopyable"
- replaces compiler jargon like "guaranteed parameters"
  and "lvalue" with corresponding language-level notions
- simplifies diagnostics about closures.

and probably more.

rdar://109281444
also moves the error to the invalid partial consume.

rdar://109281444
kavon added 3 commits May 24, 2023 20:56
- refer to a "consuming use" as simply a "consume", to reserve "use" for non-consuming uses.
- refer to "non-consuming uses" as just a "use".
- don't call it a "user defined deinit" and instead a "deinitializer" to match Sema
- be specific about what binding a closure is capturing that is preventing consumption.

rdar://109281444
…more consistent word tense

sil_movekillscopyablevalue_* and sil_moveonlychecker_* can share diagnostics.

rdar://109281444
this also fixes a bug where sometimes we simply emit
'consumed here' twice and other times we'd said 'other
consume here' for the same "consumed more than once"
message. so I went through and changed all of the 2nd
consumes into "consumed again".

rdar://109281444
@kavon kavon force-pushed the noncopyable-diagnostics-cleanup branch from 8340753 to 03d2017 Compare May 25, 2023 03:56
@kavon
Copy link
Member Author

kavon commented May 25, 2023

@swift-ci please test and merge

@swift-ci swift-ci merged commit 4720673 into swiftlang:main May 25, 2023
@kavon kavon deleted the noncopyable-diagnostics-cleanup branch May 26, 2023 20:59
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.

3 participants