Skip to content

[RemoveDIs] Update syntax highlighting to include debug records #93660

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

Merged
merged 3 commits into from
May 30, 2024

Conversation

SLTozer
Copy link
Contributor

@SLTozer SLTozer commented May 29, 2024

This patch updates the vim and vscode syntax highlighters to recognize debug records. I wasn't able to build the vscode extensions locally, so I've only tested this pattern by checking that the pattern works in vscode search.

@SLTozer SLTozer self-assigned this May 29, 2024
@llvmbot
Copy link
Member

llvmbot commented May 29, 2024

@llvm/pr-subscribers-debuginfo

Author: Stephen Tozer (SLTozer)

Changes

This patch updates the vim and vscode syntax highlighters to recognize debug records. I wasn't able to build the vscode extensions locally, so I've only tested this pattern by checking that the pattern works in vscode search.


Full diff: https://github.com/llvm/llvm-project/pull/93660.diff

2 Files Affected:

  • (modified) llvm/utils/vim/syntax/llvm.vim (+3)
  • (modified) llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml (+2-1)
diff --git a/llvm/utils/vim/syntax/llvm.vim b/llvm/utils/vim/syntax/llvm.vim
index d86e3d1ddbc27..c45391477f2c2 100644
--- a/llvm/utils/vim/syntax/llvm.vim
+++ b/llvm/utils/vim/syntax/llvm.vim
@@ -36,6 +36,9 @@ syn keyword llvmStatement sle slt srem store sub switch trunc udiv ueq uge ugt
 syn keyword llvmStatement uitofp ule ult umax umin une uno unreachable unwind
 syn keyword llvmStatement urem va_arg xchg xor zext
 
+" Debug records.
+syn match llvmStatement /\v#dbg_(assign|declare|label|value)/
+
 " Keywords.
 syn keyword llvmKeyword
       \ acq_rel
diff --git a/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml b/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
index d80c3778bbe78..da07491c9d88d 100644
--- a/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
+++ b/llvm/utils/vscode/llvm/syntaxes/ll.tmLanguage.yaml
@@ -34,7 +34,8 @@ patterns:
     captures:
       1:
         name: storage.type.llvm
-  - match: "\\badd\\b|\
+  - match: "(?<=\\s|^)#dbg_(assign|declare|label|value)\\b\
+            \\badd\\b|\
             \\baddrspacecast\\b|\
             \\balloca\\b|\
             \\band\\b|\

Copy link
Contributor

@OCHyams OCHyams left a comment

Choose a reason for hiding this comment

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

Is there someone else you can add to the review that has edited the file or reviewed a recent edit?

Rather than using "fancy" regex I would rather just have #dbg_assign #dbg_label etc checked separately. Less error prone, easier to read (for me!), but I won't push strongly for it.

Any chance we can get emacs too (https://github.com/llvm/llvm-project/blob/main/llvm/utils/emacs/llvm-mode.el) - I can look at adding later if you're not sure about emacs.

@@ -34,7 +34,8 @@ patterns:
captures:
1:
name: storage.type.llvm
- match: "\\badd\\b|\
- match: "(?<=\\s|^)#dbg_(assign|declare|label|value)\\b\
Copy link
Contributor

Choose a reason for hiding this comment

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

The other lines end |\ - I assume this one should too?

Can you explain what (?<=\\s|^) is doing please for the uninitiated?

Copy link
Contributor Author

@SLTozer SLTozer May 29, 2024

Choose a reason for hiding this comment

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

The other lines end |\ - I assume this one should too?

Yes, it should - I'll fix that.

Can you explain what (?<=\s|^) is doing please for the uninitiated?

Look-behind - it lets us make sure that this is preceded by the start of the line or whitespace without including that whitespace in the match (so if you had a custom background for instructions, it wouldn't highlight the space behind the "#").

@@ -36,6 +36,9 @@ syn keyword llvmStatement sle slt srem store sub switch trunc udiv ueq uge ugt
syn keyword llvmStatement uitofp ule ult umax umin une uno unreachable unwind
syn keyword llvmStatement urem va_arg xchg xor zext

" Debug records.
syn match llvmStatement /\v#dbg_(assign|declare|label|value)/
Copy link
Contributor

Choose a reason for hiding this comment

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

What's \v, and why do we need to wrap in /? (Not familiar with this stuff)

Copy link
Contributor

@felipepiovezan felipepiovezan May 29, 2024

Choose a reason for hiding this comment

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

/ is just what you type in vim when you're about to start a search
\v is to control the "very magic" behaviour of regex spelling:

Vim's default 'magic' setting makes characters have the same meaning as in grep, and \v (very magic) makes them the same as the extended regular expressions used by egrep.

In practice, it means fewer escape sequences for the regex operators

Copy link
Contributor

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

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

vim changes LGTM

Copy link
Member

@jryans jryans left a comment

Choose a reason for hiding this comment

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

VS Code changes look good to me.

@OCHyams
Copy link
Contributor

OCHyams commented May 30, 2024

Tested the emacs change locally, that LGTM (not super familiar, but it works and looks reasonable).

@SLTozer SLTozer merged commit 2705c60 into llvm:main May 30, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants