This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Add `!dump` and `dump`.
Needs ReviewPublic

Authored by fpetrogalli on Aug 9 2023, 4:29 AM.

Details

Summary
This allows dumping expressions `(Init *)` as soon as they become
concrete. Both of these take a string as the first operand that
prefixes the dump of the expression.

`!dump` can be used in a expression/functional context. For example:

    !foreach(i, lst, !dump(i))

`dump` can be used in a "statement" context:

    def c: C<3>;
    dump c;

`dump` is implemented as a syntactic sugar. The above `dump` is parsed into:

    assert 1, !cast<string>(!dump(c));

Original patch from Adam Nemet <anemet@apple.com>

Diff Detail

Event Timeline

fpetrogalli created this revision.Aug 9 2023, 4:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 4:29 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fpetrogalli requested review of this revision.Aug 9 2023, 4:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2023, 4:29 AM

Following the decision to abandon D156420, I have updated this patch with the correct docs, comments and tests.

fpetrogalli edited the summary of this revision. (Show Details)Aug 10 2023, 1:00 AM
fpetrogalli added reviewers: tra, wangpc, simon_tatham.

Update some of the test cases to show how dump can be used to produce the labels that can be useful for tracking the dump of a variable in debugging
sessions.

tra added a comment.Aug 10 2023, 11:07 AM

I think we're commingling two different things here.

  • representing a value as a string
  • printing something out for debugging purposes.

While for debugging we may usually want to do both, it would be very useful to be able to use them independently. That would allow doing things like dump("got a pair of values [" # !repr(value_A) # " : " # !repr(value_B # "]")).

We could add some glue to dump/!dump() so that they wrap non-string arguments into !repr() automatically.

llvm/docs/TableGen/ProgRef.rst
1252–1253

I'm still not fun of dump or !dump printing anything other than what the user passed to it. The The value of X is part should not be hardcoded and should be up to the user what they may want to print in addition to the value itself. If they need something extra, they are free to add more dump statements.

1695

This may need updating as dump only accepts a single value argument w/o prefix.

llvm/lib/TableGen/TGParser.cpp
1345

No more String.

Matt added a subscriber: Matt.Aug 13 2023, 9:35 PM

I think we're commingling two different things here.

  • representing a value as a string
  • printing something out for debugging purposes.

While for debugging we may usually want to do both, it would be very useful to be able to use them independently. That would allow doing things like dump("got a pair of values [" # !repr(value_A) # " : " # !repr(value_B # "]")).

We could add some glue to dump/!dump() so that they wrap non-string arguments into !repr() automatically.

I like this idea.

llvm/docs/TableGen/ProgRef.rst
1252–1253

Is this part of the documentation still correct? It doesn't appear to match the test cases.

llvm/lib/TableGen/Record.cpp
805

Use '\n' for single-character output.

llvm/lib/TableGen/TGParser.cpp
3862

Typo: Expected

Also: why "second" operand?