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

[TVMScript] Text underlining in DocPrinter based on Doc's source_paths #12344

Merged
merged 4 commits into from
Aug 11, 2022

Conversation

gbonik
Copy link
Contributor

@gbonik gbonik commented Aug 9, 2022

This adds an ability to print a "diagnostic marker" based on a given ObjectPath. For example, say we are printing a fragment of TIR like

for i in T.serial(10):
    a[i] = 5

and we would like bring the user's attention to the bound of the loop:

for i in T.serial(10):
                  ^^
    a[i] = 5

In this case we would give the doc printer an object path that represents this loop bound, i.e. something like path_to_underline=ObjectPath.root().attr("extent")

Tracking issue: #11912
cc @yelite @junrushao1994

src/script/printer/base_doc_printer.cc Outdated Show resolved Hide resolved
num_spaces -= 1;
printed_extra_caret = false;
}
*out += std::string(num_spaces, ' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it skip printing carets under the indentation spaces for multi-line underline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, I could see arguments either way.

for i in T.serial(10):
^^^^^^^^^^^^^^^^^^^^^^
    a[i] = 5
^^^^^^^^^^^^
for i in T.serial(10):
^^^^^^^^^^^^^^^^^^^^^^
    a[i] = 5
    ^^^^^^^^

I'd say that the first option can provide a better sense of "continuity". make it clear that this is one chunk of text being highlighted, as opposed to two different chunks. Also it seems to simplify the implementation :)

Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense. What I was thinking about is the deeply nested code, like

                  for i in T.serial(10):
                  ^^^^^^^^^^^^^^^^^^^^^^
                     a[i] = 5
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     b[i] = 6
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

But it does add more complexity to the implementation. We can keep it as is for now and make improvement in the future if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point about the nested code. But let's give the simpler implementation a shot and then add more complexity if people hate this behavior.

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

LGTM

@junrushao
Copy link
Member

Let's fix the lint and get it in :-)

@junrushao junrushao merged commit f5f5a75 into apache:main Aug 11, 2022
@junrushao
Copy link
Member

Thanks for the PR! It's merged :-)

xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
apache#12344)

This adds an ability to print a "diagnostic marker" based on a given ObjectPath. For example, say we are printing a fragment of TIR like
```
for i in T.serial(10):
    a[i] = 5
```
and we would like bring the user's attention to the bound of the loop:
```
for i in T.serial(10):
                  ^^
    a[i] = 5
```
In this case we would give the doc printer an object path that represents this loop bound, i.e. something like `path_to_underline=ObjectPath.root().attr("extent")`

Tracking issue: apache#11912
mikeseven pushed a commit to mikeseven/tvm that referenced this pull request Sep 27, 2023
apache#12344)

This adds an ability to print a "diagnostic marker" based on a given ObjectPath. For example, say we are printing a fragment of TIR like
```
for i in T.serial(10):
    a[i] = 5
```
and we would like bring the user's attention to the bound of the loop:
```
for i in T.serial(10):
                  ^^
    a[i] = 5
```
In this case we would give the doc printer an object path that represents this loop bound, i.e. something like `path_to_underline=ObjectPath.root().attr("extent")`

Tracking issue: apache#11912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants