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

Fix llvm highlighting of variables with : in name #54405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Pangoraw
Copy link
Contributor

@Pangoraw Pangoraw commented May 8, 2024

This prevents values with : in their name to be printed as labels.

Before

image

After

image

@Pangoraw Pangoraw changed the title Make llvm label regex more robust in InteractiveUtils Fix llvm highlighting of variables with : in name May 8, 2024
@tecosaur tecosaur added the domain:display and printing Aesthetics and correctness of printed representations of objects. label May 9, 2024
@@ -353,7 +353,7 @@ const llvm_types =
const llvm_cond = r"^(?:[ou]?eq|[ou]?ne|[uso][gl][te]|ord|uno)$" # true|false

function print_llvm_tokens(io, tokens)
m = match(r"^((?:[^\s:]+:)?)(\s*)(.*)", tokens)
m = match(r"^((?:[^(%\")\s:]+:)?)(\s*)(.*)", tokens)
Copy link
Contributor

@kimikage kimikage May 9, 2024

Choose a reason for hiding this comment

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

Suggested change
m = match(r"^((?:[^(%\")\s:]+:)?)(\s*)(.*)", tokens)
m = match(r"^((?:[^%@][^\s:]*:)?)(\s*)(.*)", tokens)

MY SUGGESTION IS NOT TESTED

I have my doubts if your regex is what you intended.
I think it is clearer in intent that it is not a variable, i.e., it does not start with % and @.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, this didn't match the sequence %" but rather either one of (%"). I updated with matching the % at the beginning and added a case of string labels which is valid.

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, what I am referring to is either one of:

bla-bla: ; pred = %"another%block"
  br label %"another%block"
"another%block": ; pred = %bla-bla
  br label %bla-bla

image

Sorry, I meant matching % as actually not matching it (using [^%]), in the end I just removed % from the set of allowed character for the first case (bla-bla style).

Copy link
Contributor Author

@Pangoraw Pangoraw May 10, 2024

Choose a reason for hiding this comment

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

Instead of using an banlist, we could also use the following pattern:

https://github.com/llvm/llvm-project/blob/52271a5c11f6abde1fa1221db304212b5eb8ec7c/llvm/lib/AsmParser/LLLexer.cpp#L140

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

We do not need a formal parser or lexer, since we can assume that the output of code_llvm is syntactically correct.
There are no formal assurances, but we can easily fix the problem, as we can do with this PR.

This prevents values with `:` in their name to be printed as labels.
Co-authored-by: kimikage <kimikage.ceo@gmail.com>
@fingolfin
Copy link
Contributor

@kimikage does this look OK to you now?

Copy link
Contributor

@kimikage kimikage left a comment

Choose a reason for hiding this comment

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

LGTM

Note that this approval does not mean that it has been cross-checked, since it is in effect my suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants