This is an archive of the discontinued LLVM Phabricator instance.

[libTooling] Change Tranformer's consumer to take multiple changes
ClosedPublic

Authored by li.zhe.hua on Feb 14 2022, 10:57 AM.

Details

Summary

Previously, Transformer would invoke the consumer once per file modified per
match, in addition to any errors encountered. The consumer is not aware of which
AtomicChanges come from any particular match. It is unclear which sets of edits
may be related or whether an error invalidates any previously emitted changes.

Modify the signature of the consumer to accept a set of changes. This keeps
related changes (i.e. all edits from a single match) together, and clarifies
that errors don't produce partial changes.

Diff Detail

Event Timeline

li.zhe.hua requested review of this revision.Feb 14 2022, 10:57 AM
li.zhe.hua created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2022, 10:57 AM
ymandel accepted this revision.Feb 14 2022, 11:23 AM

Looks good. But, please add tests. Thanks!

clang/include/clang/Tooling/Transformer/Transformer.h
27

Maybe ChangeSetConsumer to be more clearly a different word than ChangeConsumer?

28

Maybe document the choice of MutableArrayRef vs passing by value? I think this is the right choice, but it's not totally obvious. My justification is that we assume most consumers are reading the data and not storing the whole array.

This revision is now accepted and ready to land.Feb 14 2022, 11:23 AM

Update based on comments.

Update test to switch off depreated constructor.
Fix assert.

ymandel accepted this revision.Feb 14 2022, 1:18 PM
li.zhe.hua marked 2 inline comments as done.

Add test

Looks good. But, please add tests. Thanks!

Done; added a test for a multi-AtomicChange edit.

Attempt fix for Windows compilation issue

Work around ambiguous function call by foregoing the delgating constructor.

Remove old constructor

Not sure how to resolve the ambiguous constructor issue on MSVC. This is
probably SFINAE-able, but not sure how to repro locally to iterate.