Skip to content
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

fix: move analyzer regression with variants #1311

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented May 16, 2024

Summary

Separate the switch lowering and destructor injection into two proper
passes and apply them concurrently, fixing a move analyzer regression.

Details

  • move the switch lowering out of injectDestructorCalls
  • pass a Changeset instead of a mutable MirBody to the two passes
    in injectdestructors
  • destructor injection and switch lowering are applied in a single
    batch by backends.process
  • the switch lowering is still disabled for the VM backend
  • update the doc comment of injectDestructorCalls to reflect reality

Move Analyzer

Applying both passes concurrently - instead of the destructor-
injection/move-analysis after switch lowering - fixes a regression
from ae54312

The move analyzer now sees a discriminator assignment as:

x.discr = y

instead of:

if x.discr != y:
  =destroy(x) # variant destructor
x.discr = y

allowing it to perform automatic moves from non-variant fields again
(refer to tmove_from_non_variant_field.nim).

Misc

  • fix MIR pretty-printing for object/ref constructors -- the colon was
    missing between the field and value

zerbina added 3 commits May 16, 2024 18:27
* move switch lowering into separate procedure
* don't require a mutable `MirBody`, use the `MirTree`s + mutable
  `Changeset` signature
* apply destructor-injection/move-analysis and switch lowering
  concurrently in a single batch
The field name and argument were not separated by a colon.
@zerbina zerbina added bug Something isn't working compiler/backend Related to backend system of the compiler labels May 16, 2024
@zerbina zerbina added this to the MIR phase milestone May 16, 2024
@saem
Copy link
Collaborator

saem commented May 16, 2024

Separate the switch lowering and destructor injection into two proper passes and apply them concurrently, fixing a move analyzer regression.

Aren't they applied more sequentially, and not concurrently?

Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

One minor question about the PR message body, but otherwise it's good to go.

@zerbina
Copy link
Collaborator Author

zerbina commented May 17, 2024

Separate the switch lowering and destructor injection into two proper passes and apply them concurrently, fixing a move analyzer regression.

Aren't they applied more sequentially, and not concurrently?

Previously, both passes were implemented in the injectDestructoCalls procedure, with application working as follows:

input ----(`switch` lowering)----> X ----(destructor injection)----> output

now, application change to:

input ----(`switch` lowering)----> output
    \                              /
      ---(destructor injection)---

that is, both passes are applied to the same tree and the changes are then (effectively) merged. While it would have been possibly to keep injectDestructorCalls applying both passes, I separated them so that the decision-making of whether to actually apply the passes moves can move to the callsite.

@saem
Copy link
Collaborator

saem commented May 17, 2024

/merge

Thanks for the detailed explanation, the diagrams are super handy.

Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue May 17, 2024
Merged via the queue into nim-works:devel with commit a6d4723 May 17, 2024
31 checks passed
@zerbina zerbina deleted the concurrent-destructor-injection-passes branch May 22, 2024 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/backend Related to backend system of the compiler
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants