From 7279cc42f86146e1c34978989182ecc05b3c2667 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:49:47 +0000 Subject: [PATCH 1/6] Rust: Add resolved macros to rust/summary/summary-stats. --- rust/ql/src/queries/summary/SummaryStats.ql | 4 ++++ rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 2 ++ 2 files changed, 6 insertions(+) diff --git a/rust/ql/src/queries/summary/SummaryStats.ql b/rust/ql/src/queries/summary/SummaryStats.ql index 3f24eb50d196..53856bf7b033 100644 --- a/rust/ql/src/queries/summary/SummaryStats.ql +++ b/rust/ql/src/queries/summary/SummaryStats.ql @@ -37,4 +37,8 @@ where key = "Inconsistencies - CFG" and value = getTotalCfgInconsistencies() or key = "Inconsistencies - data flow" and value = getTotalDataFlowInconsistencies() + or + key = "Macro calls - total" and value = count(MacroCall mc) + or + key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded()) select key, value diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index 37ec4eb1425f..6508ec059a6b 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -10,3 +10,5 @@ | Inconsistencies - data flow | 7 | | Lines of code extracted | 59 | | Lines of user code extracted | 59 | +| Macro calls - resolved | 8 | +| Macro calls - total | 8 | From 7b265b2df3172d4723bc50777bd4e784bb0032f3 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:53:32 +0000 Subject: [PATCH 2/6] Rust: Add a deliberately unresolvable macro call to the test. --- .../diagnostics/ExtractionWarnings.expected | 1 + .../query-tests/diagnostics/LinesOfCode.expected | 2 +- .../diagnostics/LinesOfUserCode.expected | 2 +- .../diagnostics/LinesOfUserCodeInFiles.expected | 2 +- .../query-tests/diagnostics/SummaryStats.expected | 14 +++++++------- rust/ql/test/query-tests/diagnostics/my_macro.rs | 5 +++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected index 1ebd7e232214..9db7d1d2383c 100644 --- a/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected +++ b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected @@ -5,3 +5,4 @@ | does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | | does_not_compile.rs:2:32:2:31 | expected field name or number | Extraction warning in does_not_compile.rs with message expected field name or number | 1 | | error.rs:2:5:2:17 | An error! | Extraction warning in error.rs with message An error! | 1 | +| my_macro.rs:17:9:17:27 | macro expansion failed: could not resolve macro 'myUndefinedMacro' | Extraction warning in my_macro.rs with message macro expansion failed: could not resolve macro 'myUndefinedMacro' | 1 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected index 6facd293859d..5fa7b20e01bb 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfCode.expected @@ -1 +1 @@ -| 59 | +| 60 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected index 6facd293859d..5fa7b20e01bb 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCode.expected @@ -1 +1 @@ -| 59 | +| 60 | diff --git a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected index fe63f68abd8b..d11c7dc615be 100644 --- a/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected +++ b/rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected @@ -1,7 +1,7 @@ | my_struct.rs:0:0:0:0 | my_struct.rs | 20 | | comments.rs:0:0:0:0 | comments.rs | 13 | | main.rs:0:0:0:0 | main.rs | 8 | -| my_macro.rs:0:0:0:0 | my_macro.rs | 7 | +| my_macro.rs:0:0:0:0 | my_macro.rs | 8 | | lib.rs:0:0:0:0 | lib.rs | 5 | | does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | error.rs:0:0:0:0 | error.rs | 3 | diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index 6508ec059a6b..317be07ec7ae 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,14 +1,14 @@ -| Elements extracted | 376 | +| Elements extracted | 383 | | Elements unextracted | 0 | | Extraction errors | 0 | -| Extraction warnings | 7 | +| Extraction warnings | 8 | | Files extracted - total | 7 | -| Files extracted - with errors | 2 | -| Files extracted - without errors | 5 | +| Files extracted - with errors | 3 | +| Files extracted - without errors | 4 | | Inconsistencies - AST | 0 | | Inconsistencies - CFG | 0 | | Inconsistencies - data flow | 7 | -| Lines of code extracted | 59 | -| Lines of user code extracted | 59 | +| Lines of code extracted | 60 | +| Lines of user code extracted | 60 | | Macro calls - resolved | 8 | -| Macro calls - total | 8 | +| Macro calls - total | 9 | diff --git a/rust/ql/test/query-tests/diagnostics/my_macro.rs b/rust/ql/test/query-tests/diagnostics/my_macro.rs index d8a0cc2812bd..3b24857aa6c8 100644 --- a/rust/ql/test/query-tests/diagnostics/my_macro.rs +++ b/rust/ql/test/query-tests/diagnostics/my_macro.rs @@ -1,6 +1,6 @@ /** - * total lines in this file: 18 - * of which code: 10 + * total lines in this file: 19 + * of which code: 11 * of which only comments: 6 * of which blank: 2 */ @@ -14,5 +14,6 @@ macro_rules! myMacro { pub fn my_func() { if true { myMacro!(); + myUndefinedMacro!(); } } From 0d1bd8a9cdd359885d86054a9ea6248f4a4dfaa7 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:19:28 +0000 Subject: [PATCH 3/6] Rust: Add 'order by' to the summary stats query (doesn't seem to affect the test, but affects VSCode runs). --- rust/ql/src/queries/summary/SummaryStats.ql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/ql/src/queries/summary/SummaryStats.ql b/rust/ql/src/queries/summary/SummaryStats.ql index 53856bf7b033..2ff6fc7be70f 100644 --- a/rust/ql/src/queries/summary/SummaryStats.ql +++ b/rust/ql/src/queries/summary/SummaryStats.ql @@ -41,4 +41,4 @@ where key = "Macro calls - total" and value = count(MacroCall mc) or key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded()) -select key, value +select key, value order by key From 04926df6ea9fa4f33b66b30501f75c52ed3e6833 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:11:21 +0000 Subject: [PATCH 4/6] Rust: Add rust/diagnostics/unresolved-macro-calls diagnostic query. --- .../src/queries/diagnostics/UnresolvedMacroCalls.ql | 11 +++++++++++ .../diagnostics/UnresolvedMacroCalls.expected | 1 + .../diagnostics/UnresolvedMacroCalls.qlref | 1 + 3 files changed, 13 insertions(+) create mode 100644 rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql create mode 100644 rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected create mode 100644 rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref diff --git a/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql b/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql new file mode 100644 index 000000000000..49ff698dcb07 --- /dev/null +++ b/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql @@ -0,0 +1,11 @@ +/** + * @name Unresolved Macro Calls + * @description List all macro calls that were not resolved to a target. + * @id rust/diagnostics/unresolved-macro-calls + */ + +import rust + +from MacroCall mc +where not mc.hasExpanded() +select mc, "Macro call was not resolved to a target." diff --git a/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected new file mode 100644 index 000000000000..28fb46e8283a --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.expected @@ -0,0 +1 @@ +| my_macro.rs:17:9:17:27 | MacroCall | Macro call was not resolved to a target. | diff --git a/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref new file mode 100644 index 000000000000..77f337e27032 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/UnresolvedMacroCalls.qlref @@ -0,0 +1 @@ +queries/diagnostics/UnresolvedMacroCalls.ql From f827ad815709a0887662f820bdd071cddcd9bd81 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:33:06 +0000 Subject: [PATCH 5/6] Rust: Add missing @kind diagnostic query metadata. --- rust/ql/src/queries/diagnostics/UnextractedElements.ql | 1 + rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql | 1 + 2 files changed, 2 insertions(+) diff --git a/rust/ql/src/queries/diagnostics/UnextractedElements.ql b/rust/ql/src/queries/diagnostics/UnextractedElements.ql index dccf7d2ab09f..1a819e3f7847 100644 --- a/rust/ql/src/queries/diagnostics/UnextractedElements.ql +++ b/rust/ql/src/queries/diagnostics/UnextractedElements.ql @@ -1,6 +1,7 @@ /** * @name Unextracted Elements * @description List all elements that weren't extracted due to unimplemented features or parse errors. + * @kind diagnostic * @id rust/diagnostics/unextracted-elements */ diff --git a/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql b/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql index 49ff698dcb07..a20c5035b6ab 100644 --- a/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql +++ b/rust/ql/src/queries/diagnostics/UnresolvedMacroCalls.ql @@ -1,6 +1,7 @@ /** * @name Unresolved Macro Calls * @description List all macro calls that were not resolved to a target. + * @kind diagnostic * @id rust/diagnostics/unresolved-macro-calls */ From ede72b26809f1bf8d735124bcee1cd5ba52f01d9 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:59:05 +0000 Subject: [PATCH 6/6] Rust: Add unresolved macro calls count as well. --- rust/ql/src/queries/summary/SummaryStats.ql | 2 ++ rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 1 + 2 files changed, 3 insertions(+) diff --git a/rust/ql/src/queries/summary/SummaryStats.ql b/rust/ql/src/queries/summary/SummaryStats.ql index 2ff6fc7be70f..72a876ba08ca 100644 --- a/rust/ql/src/queries/summary/SummaryStats.ql +++ b/rust/ql/src/queries/summary/SummaryStats.ql @@ -41,4 +41,6 @@ where key = "Macro calls - total" and value = count(MacroCall mc) or key = "Macro calls - resolved" and value = count(MacroCall mc | mc.hasExpanded()) + or + key = "Macro calls - unresolved" and value = count(MacroCall mc | not mc.hasExpanded()) select key, value order by key diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index 317be07ec7ae..ecc33cd7be2a 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -12,3 +12,4 @@ | Lines of user code extracted | 60 | | Macro calls - resolved | 8 | | Macro calls - total | 9 | +| Macro calls - unresolved | 1 |