This is an archive of the discontinued LLVM Phabricator instance.

[NFC][TableGen] Refactor the implementation of arguments
ClosedPublic

Authored by wangpc on Jun 29 2023, 4:49 AM.

Details

Summary

A new Init type ArgumentInit is added to represent arguments, the
original way that we pass arguments in positional way is represented
as PositionalArgument.

The index of argument in error message is removed.

Diff Detail

Event Timeline

wangpc created this revision.Jun 29 2023, 4:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2023, 4:49 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
wangpc requested review of this revision.Jun 29 2023, 4:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2023, 4:49 AM
tra accepted this revision.Jun 29 2023, 12:45 PM

LGTM in general, with a nit.

llvm/include/llvm/TableGen/Record.h
502

changeValue() does not seem to match what the function actually does.

Change implies that we're modifying something already exsting. Based on the implementation, it appears that the function *creates* a new ArgumentInit with the current Index, and the new value. I think the name should reflect it. Perhaps cloneWithValue() would match the intent better?

Also, it appears to be implemented for the PositionalArgumentInit only. If it's needed for other types, then we may need a sensible default implementation. If it's not intended to be used in other circumstances, perhaps we can just construct the new PositionalArgumentInit explicitly in the CheckTemplateArgValues which is the only place where it's used, and drop the virtual function?

This revision is now accepted and ready to land.Jun 29 2023, 12:45 PM
wangpc updated this revision to Diff 536108.Jun 29 2023, 10:01 PM
  • Rebase.
  • Rename changeValue to cloneWithValue.
wangpc added inline comments.Jun 29 2023, 10:25 PM
llvm/include/llvm/TableGen/Record.h
502

This virtual function will be overrided by PositionalArgumentInit, and NamedArgumentInit in D152998.

wangpc updated this revision to Diff 536115.Jun 29 2023, 10:44 PM

clang-format.

wangpc marked an inline comment as done.Jun 29 2023, 10:45 PM

Please collapse PositionalArgumentInit into ArgumentInit for this patch. As of this patch, there is no other kind, and the various dispatch logic is just confusing on it's own.

The main value of this patch, and the reason I suggested it, was the type signature change. Having ArgumentInit in place allows you to split it's subclasses in the next change, and focus the review on that.

wangpc updated this revision to Diff 538943.Jul 11 2023, 12:58 AM
  • Rebase.
  • Collapse PositionalArgumentInit into ArgumentInit.

@reames I don't know if I understond your comment correctly, and I just put PositionalArgumentInit code in followed patch.

This revision was landed with ongoing or failed builds.Jul 11 2023, 11:42 AM
This revision was automatically updated to reflect the committed changes.

I went ahead and landed this change after applying a number of stylistic fixes. I also removed a bit of complexity which seems to exist only for the follow up patch, and is worthy of a bit of discussion there.