This is an archive of the discontinued LLVM Phabricator instance.

[mlir][NFC] GreedyPatternRewriteDriver: Make classes single-use
ClosedPublic

Authored by springerm on Jan 17 2023, 9:09 AM.

Details

Summary

Less mutable state, more const. This is to address a concern about complexity of state in D140304.

Depends On: D141934

Diff Detail

Event Timeline

springerm created this revision.Jan 17 2023, 9:09 AM
springerm requested review of this revision.Jan 17 2023, 9:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2023, 9:09 AM
mehdi_amini accepted this revision.Jan 26 2023, 4:51 PM
mehdi_amini added inline comments.
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
528

Is this comment update intended here or is it outdated?

This revision is now accepted and ready to land.Jan 26 2023, 4:51 PM
mehdi_amini added inline comments.Jan 26 2023, 5:22 PM
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
46

Actually I'm not sure about this pattern, this is a bit unusual to have to see something like std::move(driver).simplifyLocally(ops, changed); to be able to use the API.

This revision was landed with ongoing or failed builds.Jan 27 2023, 2:02 AM
This revision was automatically updated to reflect the committed changes.
springerm marked an inline comment as done.
springerm marked an inline comment as done.Jan 27 2023, 2:03 AM
springerm added inline comments.
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
46

I haven't seen this before either, but I found this pattern online when looking for C++ ways to indicate that an object is single use.
E.g.: https://www.foonathan.net/2018/03/rvalue-references-api-guidelines/ (4. Mark One Time Operations that Destroy the Objects)

The rvalue reference forces the caller to std::move(driver). That is an indicator for the C++ programmer that driver can no longer be used afterwards. It was already "moved" and is in an invalid state now.

Or from another website (https://crascit.com/2015/11/29/member-function-overloading-choices-you-didnt-know-you-had/):

This means the object can be modified [...] and the state of the object at the end of the call does not have to be well defined other than it must be safe to destroy the object.