Skip to content

go: make package comment more ergonomic - #392

Closed
Meng Zhuo (mengzhuo) wants to merge 1 commit into
riscv:masterfrom
mengzhuo:go
Closed

go: make package comment more ergonomic#392
Meng Zhuo (mengzhuo) wants to merge 1 commit into
riscv:masterfrom
mengzhuo:go

Conversation

@mengzhuo

Copy link
Copy Markdown
Contributor

Go use explict extension, as extensions grows
it's harder for developer to add extentions without change the whole generated line.
This PR generate right aligned comments and split lines by four sorted extensions
i.e.

make inst.go EXTENSIONS='\
   rv64_a rv64_c rv64_d rv64_f \
 rv64_i rv64_m rv64_q rv64_zba \
   rv64_zbb rv64_zbs rv_a rv_c \
         rv_c_d rv_d rv_f rv_i \
      rv_m rv_q rv_s rv_system \
     rv_v rv_zba rv_zbb rv_zbs \
            rv_zicond rv_zicsr \
'

So that developers can add more extensions by copy/paste on terminal without pain.

@mengzhuo

Copy link
Copy Markdown
Contributor Author

cc Joel Sing (@4a6f656c)

@codecov

codecov Bot commented Nov 19, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.10%. Comparing base (383cbca) to head (727b88a).
⚠️ Report is 60 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
+ Coverage   96.53%   97.10%   +0.56%     
==========================================
  Files          10       14       +4     
  Lines         750      932     +182     
==========================================
+ Hits          724      905     +181     
- Misses         26       27       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Go use explict extension, as extensions grows
it's harder for developer to add extentions without change the
whole generated line.
This PR generate right aligned comments and split line by four
sorted extensions
i.e.
```
make inst.go EXTENSIONS='\
   rv64_a rv64_c rv64_d rv64_f \
 rv64_i rv64_m rv64_q rv64_zba \
   rv64_zbb rv64_zbs rv_a rv_c \
         rv_c_d rv_d rv_f rv_i \
      rv_m rv_q rv_s rv_system \
     rv_v rv_zba rv_zbb rv_zbs \
            rv_zicond rv_zicsr \
'
```
So that developers can add more extensions by copy/paste on terminal
without pain.

Also change the original `python parse.py` command line into `make`
@4a6f656c

Copy link
Copy Markdown
Contributor

Meng Zhuo (@mengzhuo) while I agree that it is getting slightly unwieldy, I'm not convinced that this is substantially better. I have to wonder if listing the extensions (one per line) in a separate file (possibly even added to the Go repo) might be preferable... that said, it's also not that difficult to put the existing list into a file, edit and sort it, then feed it in to the current tooling.

@IIITM-Jay Jay Dev Jha (IIITM-Jay) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Meng Zhuo (@mengzhuo) Thanks for the PR!

I have left some comments which I felt to be addressed. Feel free to keep your opinions as well.

Comment on lines +17 to +20
n = 4
exts = sorted(extensions)
for i in range(0, len(exts), 4):
ext_line = " ".join(exts[i : i + n])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Meng Zhuo (@mengzhuo) , This is a bit misleading. The piece of code will end up in breaking the logic intended. The chunk size is controlled by n and the iteration is hardcoded as 4 and again inner logic still depends on n. If someone later changes n to 8 (thinking it controls grouping), the code breaks because, outer loop still advances by 4, but inner slice chooses 8. Consequently, creating duplicated extensions and overlapping groups, leading to generating incorrect outputs.

exts = sorted(extensions)
for i in range(0, len(exts), 4):
ext_line = " ".join(exts[i : i + n])
comment += f"{ext_line:>30} \\\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMO, it would be better to have adjusting logic to support variable-length, instead of making it as a hardcoded limit

for i in range(0, len(exts), 4):
ext_line = " ".join(exts[i : i + n])
comment += f"{ext_line:>30} \\\n"
comment += "'\n*/\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If extensions is empty the code will behave adversely causing the generated Go file to treat everything as inside the comment block. The code must handle the exception cases as well.

if extensions:
comment += " EXTENSIONS='\\\n"
n = 4
exts = sorted(extensions)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure with the sorting of extension here as if suppose a tool relies on a particular order (for readability, or minimal diff when adding one extension), this change may cause larger diffs than necessary each time a new extension is added.

/*
make inst.go"""
if extensions:
comment += " EXTENSIONS='\\\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As these are going to be inside comment /*...*/, I believe that the backslashes have no effect on Go compilation.

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