swift icon indicating copy to clipboard operation
swift copied to clipboard

[move-only] Add memory verifier support for struct-deinit

Open atrick opened this issue 2 years ago • 1 comments

When a value has a deinit, it cannot be memberwise destroyed. This verification catches cases where we fail to run the structs' deinit and cases where we incorrectly run a member's deinit more than once. It also handles structs that have a deinit but have only trivial members.

This fix adds an extra flag to the MemoryLocation but otherwise reuses the location's 'self' bit. This is not a good long term fix, but it solves an urgent problem of using the verifier with move-only types without adding any new SIL support.

Long-term, the verifier should instead use mark_uninitialized as the placeholder for value initialization, and DI should insert a new mark_initialized instruction for values with deinits after their members are initialized.

atrick avatar Jun 08 '23 07:06 atrick

I'm still adding unit tests. Then we need to decide whether to block this on fixing SILGen where it currently emits invalid SIL for move-only types, or put this under a flag.

atrick avatar Jun 08 '23 07:06 atrick