Skip to content

fix(hover): expand every attribute of a macro nesting a specifier - #1090

Open
DarkSharpness wants to merge 1 commit into
clice-io:mainfrom
DarkSharpness:fix/hover-nested-attribute-macros
Open

DarkSharpness wants to merge 1 commit into
clice-io:mainfrom
DarkSharpness:fix/hover-nested-attribute-macros

Conversation

@DarkSharpness

Copy link
Copy Markdown

(auto generated by Claude)

Related issue

#1089: this fixes the nested case it reports. The forms listed below stay wrong, so the PR does not close the issue on merge.

What changed

A macro use whose expansion writes a specifier names no attribute on hover (FORCE_INLINE in 05_written_attributes), but written() decided that per attribute, from attributes_only() along the attribute's own macro chain. With #define DEVICE __forceinline__ __device__, always_inline comes through __forceinline__ (__inline__ __attribute__((always_inline))) and printed expanded, while device never passes __forceinline__'s body and printed as DEVICE, with a note listing device alone. written() now makes the decision once per macro use: any attribute of the use coming out of a macro that writes a specifier makes the whole use print expanded. This is the usual CUDA spelling of device qualifiers (CUTLASS_DEVICE, CUTE_HOST_DEVICE and the like are __forceinline__ __device__ ...).

Forms still shown wrong, and why they are not in this PR

attributes_only() judges a macro by the #define text on each attribute's chain, so it cannot see tokens that reach the expansion another way:

Form Example Hover today
A nested macro writing only a specifier #define INL __inline__, #define M INL __attribute__((cold)) M inline int f, "M is __attribute__((cold))"
A specifier passed as an argument #define SPEC(x) x __attribute__((cold)), SPEC(inline) SPEC(inline) inline int f
A specifier pasted with ## PASTE(inl, ine) PASTE(inl, ine) inline int f
A type written by the macro #define WITH_TYPE my_int __attribute__((cold)) WITH_TYPE my_int f

Judging these needs the macro use's expanded tokens, and neither source available is a small change:

  • TokenMap holds the expanded stream, but not the text a preamble PCH parsed, where the declarations hovered most (those of included headers) live.
  • CompilationUnit::macro_definitions reaches every macro, preamble ones included, but using it means a small expander (arguments, ##, nested macros) in display and passing the lookup through display::definition() to its hover callers: an API change to agree on first.
  • A guess without expansion (treating a nested macro on no attribute's chain as writing a specifier) misreads a macro that expands to nothing, as export macros often do, and would break hovers that are right today.

A scan of the CUDA 13.2 toolkit, CUTLASS/CuTe, PyTorch and libstdc++ headers found one use of these forms (__DEVICE_FP128_FUNCTIONS_DECL__ in the CUDA toolkit, the first form) and none of the others, so this PR leaves them as they are. If the expander approach is wanted, it can follow as its own PR.

Tests

  • New nested_macro_with_specifiers in tests/hover/attributes/05_written_attributes: it fails on v1.0.0 (__attribute__((always_inline)) NESTED_INLINE with a note for hot) and passes here.
  • pixi run test on Linux x64 (RelWithDebInfo): 2125 unit tests and 2587 cases pass.
  • pixi run format leaves the tree unchanged.

🤖 Generated with Claude Code

A macro whose expansion writes a specifier names no attribute, but the
check ran per attribute along its own macro chain: in `#define DEVICE
__forceinline__ __device__`, `always_inline` passes `__forceinline__`'s
`__inline__` and printed expanded, while `device` did not and printed as
`DEVICE` with a note listing only itself. Decide once per macro use.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T20:09:13.722872Z 9f22a74 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change updates how DeclarationPrinter::written associates macro-origin attributes with macro uses. It adds a nested attribute macro, a function that uses it, and a hover fixture showing the expanded attributes.

Changes: Macro attribute display

Layer / File(s) Summary
Macro attribute handling and hover coverage
src/semantic/display.cpp, tests/hover/attributes/05_written_attributes/*
written collects eligible attributes and tracks macro expansions that write non-attribute content. The test adds NESTED_INLINE, applies it to thrice, and records the hover output with the expanded attributes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: 16bit-ykiko

Merge Risk: Minimal · up to 9f22a

This change makes hover show the whole macro use expanded when any attribute comes through a macro that writes a specifier. The change is localized to hover output, and a regression fixture covers it. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix for hover on macros that nest a specifier, which is the main change in display.cpp. The summary and objectives confirm that the expansion decision now applies to the whole macr…
Description check Passed The description follows the template. It has a Related issue section that explains #1089 is only partly addressed and is not closed by this PR. It has a What changed section that explains the cause, t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix for hover on macros that nest a specifier, which is the main change in display.cpp. The summary and objectives confirm that the expansion decision now applies to the whole macro use. The title is specific and matches the changeset, though it does not mention the remaining unfixed forms.

Full details: Description check

Explanation

The description follows the template. It has a Related issue section that explains #1089 is only partly addressed and is not closed by this PR. It has a What changed section that explains the cause, the fix, and the forms still unhandled with reasons. It has a Tests section that lists the new fixture, the v1.0.0 failure check, the unit and case test runs, and the format check. The template comment about deleting the section is not an issue because the section is used.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 92d26ad and 9f22a74.

Files selected for processing: 3

  • src/semantic/display.cpp
  • tests/hover/attributes/05_written_attributes/main.cpp
  • tests/hover/attributes/05_written_attributes/snap.toml

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
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.

2 participants