Skip to content

Rust: add documentation for AST nodes - #19630

Merged
aibaars merged 12 commits into
mainfrom
aibaars/qldoc-ast
Jun 4, 2025
Merged

Rust: add documentation for AST nodes#19630
aibaars merged 12 commits into
mainfrom
aibaars/qldoc-ast

Conversation

@aibaars

@aibaarsaibaars commented May 30, 2025

Copy link
Copy Markdown
Contributor

This pull request adds missing documentation for Rust AST nodes. Best reviewed commit-by-commit, skipping the codegen ones. The most important changed files is rust/schema/annotations.py where the missing documentation was added.

@github-actionsgithub-actionsBot added the Rust Pull requests that update Rust code label May 30, 2025
@aibaars
aibaarsforce-pushed the aibaars/qldoc-ast branch from 353c39f to 628a741CompareMay 30, 2025 09:41
@aibaars
aibaarsforce-pushed the aibaars/qldoc-ast branch from 628a741 to 858e372CompareMay 30, 2025 16:58
@aibaars
aibaarsforce-pushed the aibaars/qldoc-ast branch from 858e372 to 943dd8eCompareMay 30, 2025 21:00
@aibaars
aibaarsforce-pushed the aibaars/qldoc-ast branch from 883aa89 to ae0c547CompareJune 2, 2025 14:38
@aibaars
aibaars marked this pull request as ready for review June 2, 2025 15:06
CopilotAI review requested due to automatic review settings June 2, 2025 15:06
@aibaars
aibaars requested a review from a team as a code ownerJune 2, 2025 15:06

CopilotAI 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.

Pull Request Overview

This PR adds detailed documentation comments for various Rust AST node classes and updates the .gitattributes to include generated test files that were previously marked as missing.

  • Enriches QLL class docs with clear descriptions and examples for associated items, inline assembly elements, array types, argument lists, and ABI specs.
  • Introduces a constructor predicate in ControlFlowGraphImpl.qll to filter out macro pattern calls.
  • Replaces MISSING_SOURCE.txt entries in .gitattributes with actual .ql test paths for inline assembly and other elements.

Reviewed Changes

Copilot reviewed 644 out of 644 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
rust/ql/lib/codeql/rust/elements/AssocTypeArg.qllAdded a descriptive doc comment and example for associated type arguments.
rust/ql/lib/codeql/rust/elements/AssocItemList.qllExtended doc to mention Impl contexts; refined formatting.
rust/ql/lib/codeql/rust/elements/AssocItem.qllUpdated comment to describe associated items in traits/impls with example.
rust/ql/lib/codeql/rust/elements/Asm*.qllAdded docs and examples for inline assembly symbols, registers, options, etc.
rust/ql/lib/codeql/rust/elements/ArrayTypeRepr.qllDocumented array type representations with example.
rust/ql/lib/codeql/rust/elements/ArgList.qllClarified argument list usage in calls with example.
rust/ql/lib/codeql/rust/elements/Abi.qllDocumented ABI specs for extern functions/blocks.
rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qllAdded MacroCallTree() predicate to exclude calls in macro patterns.
rust/ql/.gitattributesReplaced missing-source placeholders with actual generated .ql test entries.

Comment threadrust/ql/lib/codeql/rust/elements/AssocItemList.qll Outdated
| test.rs:455:13:455:25 | [match(false)] 1 \| 2 | no-match | test.rs:455:13:455:25 | one_or_two!... |
| test.rs:455:13:455:25 | [match(false)] 1 \| 2 | no-match | test.rs:456:13:456:13 | _ |
| test.rs:455:13:455:25 | [match(true)] 1 \| 2 | match | test.rs:455:13:455:25 | one_or_two!... |
| test.rs:455:13:455:25 | [match(true)] 1 \| 2 | match | test.rs:455:30:455:30 | 3 |

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.

🎉

Foo<'a>
// ^^
let text: Text<'a>;
// ^^

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.

Improvements to examples 👍.

| gen_arg_list.rs:5:5:5:11 | ArgList | 0 | gen_arg_list.rs:5:5:5:11 | "not yet implemented" |
| gen_arg_list.rs:7:8:7:16 | ArgList | 0 | gen_arg_list.rs:7:9:7:9 | 1 |
| gen_arg_list.rs:7:8:7:16 | ArgList | 1 | gen_arg_list.rs:7:12:7:12 | 2 |
| gen_arg_list.rs:7:8:7:16 | ArgList | 2 | gen_arg_list.rs:7:15:7:15 | 3 |

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.

Why are we getting better test results from doc changes? Are these the tests of the example code you were talking about earlier today?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

All the examples in triple backticks are place in source files for QL tests. That way we can test that the examples in the docs are actually valid. The "not yet implemented" stuff comes from the expansion of the todo!() macro.

```rust
todo!()
extern "C" fn foo() {}
// ^^^

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.

New documentation 👍 (I won't claim to have picked through it with a fine-toothed comb, but it all looks good at a glance, and is certainly an improvement on all those todo!()s).

```rust
todo!()
fn foo<T, U>(t: T, u: U) {}
// ^ ^

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.

The ^ are a helpful addition in many of these examples.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

They were co-piliot's idea, and I quite like them too. Ideally we make those ^^ things inline expectation markers, so we get even stronger testing of the documentation examples. @redsun82 perhaps something for a rainy afternoon ;-)

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.

Comment threadrust/schema/annotations.py Outdated
Comment threadrust/schema/annotations.py Outdated
Comment threadrust/schema/annotations.py Outdated
Comment threadrust/schema/annotations.py Outdated
Comment threadrust/schema/annotations.py Outdated
Comment threadrust/schema/annotations.py Outdated
@@ -1069,9 +1142,17 @@ class _:
@annotate(ForTypeRepr)
class _:
"""
A ForTypeRepr. For example:
A higher-ranked trait bound(HRTB) type.

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.

Suggested change
Ahigher-rankedtraitbound(HRTB)type.
Ahigher-rankedtraitbound(HRTB).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I dropped the acronym, actually not much point defining a fancy acronym if it is not used anywhere in the text

Comment threadrust/schema/annotations.py Outdated
println!("{} {}!", "Hello", "world");
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
```

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.

Suggested change
```
```rust

redsun82
redsun82 previously approved these changes Jun 3, 2025

@redsun82redsun82 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.

LGTM, that's a very good improvement in both documentation and testing 👍

Some minor cosmetic nits, but this is really neat!

@geoffw0

Copy link
Copy Markdown
Contributor

My comments have all been addressed and I'm [very] happy with the PR. @redsun82 please approve if you're happy your comments have been addressed as well.

@aibaars
aibaarsforce-pushed the aibaars/qldoc-ast branch from 58b0e41 to 39851bcCompareJune 4, 2025 13:45

@redsun82redsun82 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.

thanks a lot!

@aibaars
aibaars merged commit 189c16b into mainJun 4, 2025
@aibaars
aibaars deleted the aibaars/qldoc-ast branch June 4, 2025 14:04
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RustPull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@aibaars@geoffw0@redsun82@hvitved