Skip to content

[5.9][move-only] Fix SIL representation and SILOptimizer to preserve value deinits. #66357

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 13 commits into from
Jun 6, 2023

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Jun 6, 2023

--- CCC ---

Explanation:

Many basic SIL passes were silently deleting the struct and enum deinits:

  • SROA
  • Mem2Reg
  • RLE
  • DSE
  • FunctionSignatureOpts
  • LowerAggregates
  • SILCombine
  • EarlyCodeMotion
  • ReleaseHoisting
  • many passes that rely on ARC analysis (RCIndentity)

Major Changes:

  • add SIL verification for drop_deinit
  • fix ownership lowering to handle drop_deinit
  • disable deinit devirtualization (until the optimizer is tested)
  • fix 'shouldExpand' to recognize value deinits; impacts many passes
  • fix dead function elimination to collect and preserve value deinits
  • fix RCIdentity to recognize value deinits; impacts many passes
  • fix SILCombine special cases to preserve value deinits
  • fix TypeLowering to preserve value deinits; mainly fixes LowerAggregates

Scope of Issue: In some cases, deinitialization would run recursively, hanging the system. In other cases, a struct's deinit would silently fail to run when the struct was a member within another type. In the most trivial cases, with no type composition, and earlier MoveOnlyDeinitInsertion pass was hiding the problem.

Risk: Low risk to regular copyable code. And non-copyable was already broken.

PR to main: [move-only] Fix SIL representation and SILOptimizer to preserve value deinits #66314
#66314

Reviewed By: Erik Eckstein and Joe Groff

Resolves:

rdar://109849028 ([move-only] LowerAggregateInstrs eliminates struct deinitialization)

rdar://109863801 ([move-only] DCE removes drop_deinit, so user-defined deinitializers call themselves recursively at -O)

rdar://110079028 ([move-only] Finish SIL support for drop_deinit)

@atrick atrick requested a review from a team as a code owner June 6, 2023 09:23
@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2023

@swift-ci test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

optimizer changes LGTM

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

I think I found a potential problem inSILCombine's isTrivial function

atrick added 8 commits June 6, 2023 08:46
rdar://109863801 ([move-only] DCE removes drop_deinit, so user-defined
deinitializers call themselves recursively at -O)

(cherry picked from commit af49f62)
drop_deinit ultimately only affects the semantics of its
destroy_value. Avoid generating releases for destroys in which the
deinit has been dropped. Instead, individually release the members.

(cherry picked from commit a6f65f0)
drop_deinit only exists in ownership SIL. Remove IRGen support.

A drop_deinit can only ever be destroyed or destructured.

A destructure of a struct-with-deinit requires a drop_deinit operand.

(cherry picked from commit 3efd122)
to MoveOnlyDeinitDevirtualization

(cherry picked from commit 9855edd)
It is not needed for correctness and hides most of the deinit related
optimizer bugs.

(cherry picked from commit 84bee24)
Many basic SIL passes were silently deleting the struct deinit:
- SROA
- Mem2Reg
- RLE
- DSE
- FunctionSignatureOpts
- LowerAggregates

Fixes rdar://109849028 ([move-only] LowerAggregateInstrs eliminates struct deinitialization)

(cherry picked from commit 4a37b00)
@atrick atrick force-pushed the 5.9-fix-dropdeinit branch from 30fe52e to e2a6e00 Compare June 6, 2023 15:53
@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2023

@swift-ci test

@atrick atrick requested a review from eeckstein June 6, 2023 16:19
@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2023

@swift-ci test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm!

@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2023

@swift-ci clean test macOS

@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2023

@swift-ci test

atrick added 5 commits June 6, 2023 11:12
Multiple code motion and ARC related passes were removing struct/enum
deinits.

Passes fixed include:
- SILCombine
- EarlyCodeMotion
- ReleaseHoisting
- *many* passes that rely on ARC analysis (RCIndentity)

(cherry picked from commit 6756ed7)
Fix a special case in visitReleaseValueInst for enum-with-deinit.

(cherry picked from commit 58f96a9)
MoveOnlyLoadableStruct should only lower to memberwise destroys if it
has no deinit.

(cherry picked from commit 986cd42)
The -Onone passes fail to remove struct_extract, so the CHECK
lines will fail.

(cherry picked from commit d55ca8a)
@atrick atrick force-pushed the 5.9-fix-dropdeinit branch from ca051cb to 0fa4d98 Compare June 6, 2023 18:14
@atrick
Copy link
Contributor Author

atrick commented Jun 6, 2023

@swift-ci test

@atrick atrick merged commit bfdec5c into swiftlang:release/5.9 Jun 6, 2023
@atrick atrick deleted the 5.9-fix-dropdeinit branch June 6, 2023 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants