Skip to content

Rust: Fix bad join #19714

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 1 commit into from
Jun 11, 2025
Merged

Rust: Fix bad join #19714

merged 1 commit into from
Jun 11, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jun 10, 2025

#19584 follow-up. The bad join appears to only happen when running the SummaryStats.ql query.

[2025-06-10 15:21:37] (83s) Tuple counts for TypeMention::PathTypeReprMention.aliasResolveTypeAt/1#dispred#ae16f47b#fbf#cpe#13/2@i5#5a5451wi after 57.7s:
                      205999      ~1028%     {3} r1 = JOIN `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_1_0_2#prev_delta` WITH `_TypeAlias::Generated::TypeAlias.getTypeRepr/0#dispred#5fd7e521_TypeMention::PathTypeReprMention#a35__#join_rhs#1` ON FIRST 2 OUTPUT Rhs.2, Lhs.2 'result', Rhs.3 'this'
                                             {3}    | AND NOT `project#TypeMention::pathGetTypeParameter/2#fd301eed#2`(FIRST 2)
                      204000      ~982%      {2}    | SCAN OUTPUT In.2 'this', In.1 'result'

                      5499        ~448%      {7} r2 = JOIN `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1#prev_delta` WITH `_GenericArgList::GenericArgList.getTypeArg/1#dispred#1c780027_PathSegment::Generated::PathSegment.ge__#join_rhs#1` ON FIRST 1 OUTPUT Rhs.1, Rhs.2 'this', Rhs.3, Lhs.1 'result', _, Lhs.2, _
                                             {5}    | REWRITE WITH Tmp.4 := "", Tmp.6 := "", Out.4 := InverseAppend(Tmp.4,In.5,Tmp.6) KEEPING 5
                      2500        ~398%      {5}    | SCAN OUTPUT In.0, In.2, In.4, In.1 'this', In.3 'result'
                      0           ~0%        {2}    | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1#prev` ON FIRST 3 OUTPUT Lhs.3 'this', Lhs.4 'result'

                      9000        ~489%      {7} r3 = JOIN `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1#prev_delta` WITH `_PathSegment::Generated::PathSegment.getGenericArgList/0#dispred#e072653b__Path::Generated::Path.get__#join_rhs#1` ON FIRST 1 OUTPUT Rhs.1, Rhs.2 'this', Rhs.3, Lhs.1, _, Lhs.2, _
                                             {5}    | REWRITE WITH Tmp.4 := "", Tmp.6 := "", Out.4 := InverseAppend(In.5,Tmp.4,Tmp.6) KEEPING 5
                      5000        ~411%      {5}    | SCAN OUTPUT In.4, In.0, In.1 'this', In.2, In.3
                      10461919500 ~610%      {6}    | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_1_0_2#prev` ON FIRST 1 OUTPUT Lhs.3, Rhs.1, Lhs.1, Lhs.2 'this', Lhs.4, Rhs.2 'result'
                      500         ~0%        {5}    | JOIN WITH `GenericArgList::GenericArgList.getTypeArg/1#dispred#1c780027_021#join_rhs` ON FIRST 2 OUTPUT Lhs.2, Rhs.2, Lhs.4, Lhs.3 'this', Lhs.5 'result'
                      0           ~0%        {2}    | JOIN WITH `TypeMention::pathGetTypeParameter/2#fd301eed` ON FIRST 3 OUTPUT Lhs.3 'this', Lhs.4 'result'

                      204000      ~982%      {2} r4 = r1 UNION r2 UNION r3
                      203964      ~982%      {2}    | AND NOT `TypeMention::PathTypeReprMention.aliasResolveTypeAt/1#dispred#ae16f47b#fbf#cpe#13#prev`(FIRST 2)
                                             return r4

DCA reports an average 75 % analysis time speedup.

```
[2025-06-10 15:21:37] (83s) Tuple counts for TypeMention::PathTypeReprMention.aliasResolveTypeAt/1#dispred#ae16f47b#fbf#cpe#13/2@i5#5a5451wi after 57.7s:
                      205999      ~1028%     {3} r1 = JOIN `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_1_0_2#prev_delta` WITH `_TypeAlias::Generated::TypeAlias.getTypeRepr/0#dispred#5fd7e521_TypeMention::PathTypeReprMention#a35__#join_rhs#1` ON FIRST 2 OUTPUT Rhs.2, Lhs.2 'result', Rhs.3 'this'
                                             {3}    | AND NOT `project#TypeMention::pathGetTypeParameter/2#fd301eed#2`(FIRST 2)
                      204000      ~982%      {2}    | SCAN OUTPUT In.2 'this', In.1 'result'

                      5499        ~448%      {7} r2 = JOIN `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1#prev_delta` WITH `_GenericArgList::GenericArgList.getTypeArg/1#dispred#1c780027_PathSegment::Generated::PathSegment.ge__#join_rhs#1` ON FIRST 1 OUTPUT Rhs.1, Rhs.2 'this', Rhs.3, Lhs.1 'result', _, Lhs.2, _
                                             {5}    | REWRITE WITH Tmp.4 := "", Tmp.6 := "", Out.4 := InverseAppend(Tmp.4,In.5,Tmp.6) KEEPING 5
                      2500        ~398%      {5}    | SCAN OUTPUT In.0, In.2, In.4, In.1 'this', In.3 'result'
                      0           ~0%        {2}    | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1#prev` ON FIRST 3 OUTPUT Lhs.3 'this', Lhs.4 'result'

                      9000        ~489%      {7} r3 = JOIN `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_0_2_1#prev_delta` WITH `_PathSegment::Generated::PathSegment.getGenericArgList/0#dispred#e072653b__Path::Generated::Path.get__#join_rhs#1` ON FIRST 1 OUTPUT Rhs.1, Rhs.2 'this', Rhs.3, Lhs.1, _, Lhs.2, _
                                             {5}    | REWRITE WITH Tmp.4 := "", Tmp.6 := "", Out.4 := InverseAppend(In.5,Tmp.4,Tmp.6) KEEPING 5
                      5000        ~411%      {5}    | SCAN OUTPUT In.4, In.0, In.1 'this', In.2, In.3
                      10461919500 ~610%      {6}    | JOIN WITH `TypeMention::TypeMention.resolveTypeAt/1#dispred#a125c821#bff#reorder_1_0_2#prev` ON FIRST 1 OUTPUT Lhs.3, Rhs.1, Lhs.1, Lhs.2 'this', Lhs.4, Rhs.2 'result'
                      500         ~0%        {5}    | JOIN WITH `GenericArgList::GenericArgList.getTypeArg/1#dispred#1c780027_021#join_rhs` ON FIRST 2 OUTPUT Lhs.2, Rhs.2, Lhs.4, Lhs.3 'this', Lhs.5 'result'
                      0           ~0%        {2}    | JOIN WITH `TypeMention::pathGetTypeParameter/2#fd301eed` ON FIRST 3 OUTPUT Lhs.3 'this', Lhs.4 'result'

                      204000      ~982%      {2} r4 = r1 UNION r2 UNION r3
                      203964      ~982%      {2}    | AND NOT `TypeMention::PathTypeReprMention.aliasResolveTypeAt/1#dispred#ae16f47b#fbf#cpe#13#prev`(FIRST 2)
                                             return r4
```
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 10, 2025
@hvitved hvitved marked this pull request as ready for review June 10, 2025 16:46
@Copilot Copilot AI review requested due to automatic review settings June 10, 2025 16:46
@hvitved hvitved requested a review from a team as a code owner June 10, 2025 16:46
Copy link
Contributor

@Copilot Copilot AI left a comment

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 pragma[nomagic] annotations to two methods in the Rust CodeQL QLL files to improve join behavior when running the SummaryStats.ql query.

  • Add pragma[nomagic] to PathTypeReprMention.aliasResolveTypeAt
  • Add pragma[nomagic] to GenericArgListImpl.getTypeArg

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
rust/ql/lib/codeql/rust/internal/TypeMention.qll Insert pragma[nomagic] before aliasResolveTypeAt
rust/ql/lib/codeql/rust/elements/internal/GenericArgListImpl.qll Insert pragma[nomagic] before getTypeArg
Comments suppressed due to low confidence (2)

rust/ql/lib/codeql/rust/internal/TypeMention.qll:133

  • The Javadoc comment above aliasResolveTypeAt is now separated from the method by the pragma. This may prevent the comment from being associated with the method in generated docs—consider moving the comment block above the pragma or placing the pragma before the comment.
pragma[nomagic]

rust/ql/lib/codeql/rust/elements/internal/GenericArgListImpl.qll:29

  • The documentation comment for getTypeArg is now separated by the pragma, which may break its association with the method. Consider relocating the pragma or the comment so that the doc block immediately precedes the method signature.
pragma[nomagic]

@hvitved hvitved merged commit 3fed7f5 into github:main Jun 11, 2025
16 checks passed
@hvitved hvitved deleted the rust/fix-bad-join branch June 11, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants