Merge pull request #20954 from hvitved/rust/stats-more-calls

Rust: Include more calls in DB quality metrics
This commit is contained in:
Tom Hvitved
2025-12-09 14:14:07 +01:00
committed by GitHub
25 changed files with 220 additions and 45 deletions

View File

@@ -15,8 +15,8 @@ class SourceLocatable extends Locatable {
SourceLocatable() { this.fromSource() } SourceLocatable() { this.fromSource() }
} }
query predicate multipleCallTargets(SourceLocatable a) { query predicate multipleResolvedTargets(SourceLocatable a) {
PathResolutionConsistency::multipleCallTargets(a, _) PathResolutionConsistency::multipleResolvedTargets(a, _)
} }
query predicate multiplePathResolutions(SourceLocatable a) { query predicate multiplePathResolutions(SourceLocatable a) {

View File

@@ -24,17 +24,10 @@ query predicate multiplePathResolutions(Path p, ItemNode i) {
strictcount(ItemNode i0 | i0 = resolvePath(p) and not i0 instanceof Crate) > 1 strictcount(ItemNode i0 | i0 = resolvePath(p) and not i0 instanceof Crate) > 1
} }
// TODO: Take other calls into account /** Holds if `ie` has multiple resolved targets including `target`. */
abstract private class CallExprBase extends InvocationExpr { } query predicate multipleResolvedTargets(InvocationExpr ie, Addressable target) {
target = ie.getResolvedTarget() and
private class CallExprCallExprBase extends CallExpr, CallExprBase { } strictcount(ie.getResolvedTarget()) > 1
private class MethodCallExprCallExprBase extends MethodCallExpr, CallExprBase { }
/** Holds if `call` has multiple static call targets including `target`. */
query predicate multipleCallTargets(CallExprBase call, Callable target) {
target = call.getResolvedTarget() and
strictcount(call.getResolvedTarget()) > 1
} }
/** Holds if `fe` resolves to multiple record fields including `field`. */ /** Holds if `fe` resolves to multiple record fields including `field`. */
@@ -62,8 +55,8 @@ int getPathResolutionInconsistencyCounts(string type) {
type = "Multiple path resolutions" and type = "Multiple path resolutions" and
result = count(Path p | multiplePathResolutions(p, _) | p) result = count(Path p | multiplePathResolutions(p, _) | p)
or or
type = "Multiple static call targets" and type = "Multiple resolved targets" and
result = count(CallExprBase call | multipleCallTargets(call, _) | call) result = count(InvocationExpr ie | multipleResolvedTargets(ie, _) | ie)
or or
type = "Multiple record fields" and type = "Multiple record fields" and
result = count(FieldExpr fe | multipleStructFields(fe, _) | fe) result = count(FieldExpr fe | multipleStructFields(fe, _) | fe)

View File

@@ -1,13 +1,14 @@
/** /**
* Provides database quality statistics that are reported by * Provides database quality statistics that are reported by
* `rust/telemetry/extractor-information` * `rust/telemetry/extractor-information`
* and perhaps warned about by `rust/diagnostics/database-quality`. * and perhaps warned about by `rust/diagnostic/database-quality`.
*/ */
import rust import rust
import codeql.util.ReportStats import codeql.util.ReportStats
import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl import codeql.rust.elements.internal.CallExprImpl::Impl as CallExprImpl
import codeql.rust.internal.TypeInference as TypeInference import codeql.rust.internal.TypeInference as TypeInference
import codeql.rust.internal.Type
/** /**
* A file that is included in the quality statistics. * A file that is included in the quality statistics.
@@ -20,25 +21,26 @@ private class RelevantFile extends File {
} }
module CallTargetStats implements StatsSig { module CallTargetStats implements StatsSig {
// TODO: Take other calls into account /**
abstract private class CallExprBase extends InvocationExpr { } * A call-like expression that is relevant for call target statistics.
*
private class CallExprCallExprBase extends CallExpr, CallExprBase { } * Note that this also includes tuple struct instantiations and tuple
* variant instantiations.
private class MethodCallExprCallExprBase extends MethodCallExpr, CallExprBase { } */
private class RelevantInvocationExpr extends InvocationExpr {
int getNumberOfOk() { RelevantInvocationExpr() {
result = this.getFile() instanceof RelevantFile and
count(CallExprBase c | c.getFile() instanceof RelevantFile and exists(c.getResolvedTarget())) not this instanceof CallExprImpl::DynamicCallExpr and
not this = any(Operation o | not o.isOverloaded(_, _, _)) and
not this = any(DerefExpr de | TypeInference::inferType(de.getExpr()) instanceof PtrType)
}
} }
additional predicate isNotOkCall(CallExprBase c) { int getNumberOfOk() { result = count(RelevantInvocationExpr e | exists(e.getResolvedTarget())) }
c.getFile() instanceof RelevantFile and
not exists(c.getResolvedTarget()) and
not c instanceof CallExprImpl::DynamicCallExpr
}
int getNumberOfNotOk() { result = count(CallExprBase c | isNotOkCall(c)) } additional predicate isNotOkCall(RelevantInvocationExpr e) { not exists(e.getResolvedTarget()) }
int getNumberOfNotOk() { result = count(RelevantInvocationExpr e | isNotOkCall(e)) }
string getOkText() { result = "calls with call target" } string getOkText() { result = "calls with call target" }

View File

@@ -1,2 +1,2 @@
multipleCallTargets multipleResolvedTargets
| proc_macro.rs:44:27:44:30 | ...::to_tokens(...) | | proc_macro.rs:44:27:44:30 | ...::to_tokens(...) |

View File

@@ -0,0 +1,4 @@
multipleResolvedTargets
| test.rs:419:34:419:35 | * ... |
| test.rs:420:26:420:27 | * ... |
| test.rs:597:9:597:10 | * ... |

View File

@@ -0,0 +1,3 @@
multipleResolvedTargets
| main.rs:236:11:236:15 | * ... |
| main.rs:272:13:272:29 | * ... |

View File

@@ -0,0 +1,2 @@
multipleResolvedTargets
| main.rs:562:10:562:15 | * ... |

View File

@@ -0,0 +1,2 @@
multipleResolvedTargets
| main.rs:115:14:115:35 | * ... |

View File

@@ -0,0 +1,26 @@
multipleResolvedTargets
| main.rs:19:17:19:18 | * ... |
| main.rs:53:14:53:15 | * ... |
| main.rs:59:33:59:34 | * ... |
| main.rs:72:14:72:15 | * ... |
| main.rs:73:9:73:10 | * ... |
| main.rs:74:14:74:15 | * ... |
| main.rs:75:9:75:10 | * ... |
| main.rs:76:14:76:15 | * ... |
| main.rs:83:9:83:10 | * ... |
| main.rs:90:9:90:17 | * ... |
| main.rs:97:9:97:10 | * ... |
| main.rs:105:9:105:10 | * ... |
| main.rs:106:14:106:15 | * ... |
| main.rs:113:14:113:15 | * ... |
| main.rs:114:9:114:10 | * ... |
| main.rs:115:14:115:15 | * ... |
| main.rs:122:9:122:10 | * ... |
| main.rs:125:9:125:10 | * ... |
| main.rs:135:17:135:18 | * ... |
| main.rs:136:17:136:18 | * ... |
| main.rs:201:9:201:10 | * ... |
| main.rs:209:14:209:15 | * ... |
| main.rs:211:14:211:15 | * ... |
| main.rs:224:13:224:17 | * ... |
| main.rs:229:9:229:10 | * ... |

View File

@@ -1,4 +1,4 @@
multipleCallTargets multipleResolvedTargets
| test.rs:59:62:59:77 | ...::from(...) | | test.rs:59:62:59:77 | ...::from(...) |
| test.rs:66:58:66:73 | ...::from(...) | | test.rs:66:58:66:73 | ...::from(...) |
| test.rs:389:30:389:67 | pinned.poll_read(...) | | test.rs:389:30:389:67 | pinned.poll_read(...) |

View File

@@ -1,2 +1,2 @@
multipleCallTargets multipleResolvedTargets
| main.rs:52:14:52:29 | ...::from(...) | | main.rs:52:14:52:29 | ...::from(...) |

View File

@@ -0,0 +1,5 @@
multipleResolvedTargets
| main.rs:35:5:35:14 | * ... |
| main.rs:35:5:35:14 | * ... |
| main.rs:35:5:35:14 | * ... |
| main.rs:35:5:35:14 | * ... |

View File

@@ -0,0 +1,2 @@
multipleResolvedTargets
| test.rs:52:2:52:5 | * ... |

View File

@@ -0,0 +1,45 @@
multipleResolvedTargets
| main.rs:28:5:28:14 | * ... |
| main.rs:28:5:28:14 | * ... |
| main.rs:28:5:28:14 | * ... |
| main.rs:28:5:28:14 | * ... |
| main.rs:29:5:29:14 | * ... |
| main.rs:29:5:29:14 | * ... |
| main.rs:29:5:29:14 | * ... |
| main.rs:29:5:29:14 | * ... |
| main.rs:30:5:30:14 | * ... |
| main.rs:30:5:30:14 | * ... |
| main.rs:30:5:30:14 | * ... |
| main.rs:30:5:30:14 | * ... |
| main.rs:31:5:31:14 | * ... |
| main.rs:31:5:31:14 | * ... |
| main.rs:31:5:31:14 | * ... |
| main.rs:31:5:31:14 | * ... |
| main.rs:33:5:33:14 | * ... |
| main.rs:33:5:33:14 | * ... |
| main.rs:33:5:33:14 | * ... |
| main.rs:33:5:33:14 | * ... |
| main.rs:34:5:34:14 | * ... |
| main.rs:34:5:34:14 | * ... |
| main.rs:34:5:34:14 | * ... |
| main.rs:34:5:34:14 | * ... |
| main.rs:35:5:35:14 | * ... |
| main.rs:35:5:35:14 | * ... |
| main.rs:35:5:35:14 | * ... |
| main.rs:35:5:35:14 | * ... |
| main.rs:36:5:36:14 | * ... |
| main.rs:36:5:36:14 | * ... |
| main.rs:36:5:36:14 | * ... |
| main.rs:36:5:36:14 | * ... |
| main.rs:37:5:37:14 | * ... |
| main.rs:37:5:37:14 | * ... |
| main.rs:37:5:37:14 | * ... |
| main.rs:37:5:37:14 | * ... |
| main.rs:75:5:75:14 | * ... |
| main.rs:75:5:75:14 | * ... |
| main.rs:75:5:75:14 | * ... |
| main.rs:75:5:75:14 | * ... |
| main.rs:76:5:76:14 | * ... |
| main.rs:76:5:76:14 | * ... |
| main.rs:76:5:76:14 | * ... |
| main.rs:76:5:76:14 | * ... |

View File

@@ -1,4 +1,4 @@
multipleCallTargets multipleResolvedTargets
| main.rs:126:9:126:11 | f(...) | | main.rs:126:9:126:11 | f(...) |
| main.rs:366:9:368:16 | ...::f(...) | | main.rs:366:9:368:16 | ...::f(...) |
| main.rs:369:9:371:16 | ...::f(...) | | main.rs:369:9:371:16 | ...::f(...) |

View File

@@ -1,13 +1,34 @@
multipleCallTargets multipleResolvedTargets
| blanket_impl.rs:33:13:33:17 | * ... |
| dereference.rs:69:15:69:24 | e1.deref() | | dereference.rs:69:15:69:24 | e1.deref() |
| dereference.rs:73:15:73:17 | * ... |
| dereference.rs:77:16:77:18 | * ... |
| dereference.rs:182:17:182:26 | ... .foo() | | dereference.rs:182:17:182:26 | ... .foo() |
| dereference.rs:183:17:183:23 | S.foo() | | dereference.rs:183:17:183:23 | S.foo() |
| dereference.rs:184:17:184:30 | ... .foo() | | dereference.rs:184:17:184:30 | ... .foo() |
| dereference.rs:186:17:186:25 | S.bar(...) | | dereference.rs:186:17:186:25 | S.bar(...) |
| dereference.rs:187:17:187:29 | S.bar(...) | | dereference.rs:187:17:187:29 | S.bar(...) |
| dyn_type.rs:65:20:65:23 | * ... |
| dyn_type.rs:69:21:69:24 | * ... |
| dyn_type.rs:90:10:90:13 | * ... |
| invalid/main.rs:69:13:69:17 | * ... |
| invalid/main.rs:76:13:76:17 | * ... |
| main.rs:1077:14:1077:18 | * ... |
| main.rs:1159:26:1159:30 | * ... |
| main.rs:1504:14:1504:21 | * ... |
| main.rs:1504:16:1504:20 | * ... |
| main.rs:1509:14:1509:18 | * ... |
| main.rs:1540:27:1540:29 | * ... |
| main.rs:1654:17:1654:24 | * ... |
| main.rs:1654:18:1654:24 | * ... |
| main.rs:1792:17:1792:21 | * ... |
| main.rs:1807:28:1807:32 | * ... |
| main.rs:2440:13:2440:18 | * ... |
| main.rs:2634:13:2634:31 | ...::from(...) | | main.rs:2634:13:2634:31 | ...::from(...) |
| main.rs:2635:13:2635:31 | ...::from(...) | | main.rs:2635:13:2635:31 | ...::from(...) |
| main.rs:2636:13:2636:31 | ...::from(...) | | main.rs:2636:13:2636:31 | ...::from(...) |
| main.rs:2642:13:2642:31 | ...::from(...) | | main.rs:2642:13:2642:31 | ...::from(...) |
| main.rs:2643:13:2643:31 | ...::from(...) | | main.rs:2643:13:2643:31 | ...::from(...) |
| main.rs:2644:13:2644:31 | ...::from(...) | | main.rs:2644:13:2644:31 | ...::from(...) |
| pattern_matching.rs:273:13:273:27 | * ... |
| pattern_matching.rs:273:14:273:27 | * ... |

View File

@@ -1,3 +1,17 @@
multipleCallTargets multipleResolvedTargets
| main.rs:16:15:16:16 | * ... |
| main.rs:91:19:91:40 | ...::from(...) | | main.rs:91:19:91:40 | ...::from(...) |
| main.rs:113:19:113:40 | ...::from(...) | | main.rs:113:19:113:40 | ...::from(...) |
| main.rs:507:5:507:10 | * ... |
| main.rs:512:5:512:6 | * ... |
| main.rs:513:9:513:10 | * ... |
| main.rs:514:9:514:10 | * ... |
| main.rs:519:5:519:6 | * ... |
| main.rs:520:9:520:10 | * ... |
| main.rs:521:9:521:10 | * ... |
| main.rs:522:5:522:6 | * ... |
| main.rs:530:5:530:6 | * ... |
| main.rs:542:5:542:7 | * ... |
| main.rs:542:6:542:7 | * ... |
| main.rs:552:5:552:6 | * ... |
| main.rs:699:9:699:13 | * ... |

View File

@@ -1,2 +1,2 @@
multipleCallTargets multipleResolvedTargets
| my_struct.rs:25:19:25:37 | ...::from(...) | | my_struct.rs:25:19:25:37 | ...::from(...) |

View File

@@ -1,4 +1,4 @@
multipleCallTargets multipleResolvedTargets
| mysql.rs:15:24:15:39 | ...::from(...) | | mysql.rs:15:24:15:39 | ...::from(...) |
| mysql.rs:16:26:16:85 | ...::from(...) | | mysql.rs:16:26:16:85 | ...::from(...) |
| mysql.rs:18:13:18:66 | ...::from(...) | | mysql.rs:18:13:18:66 | ...::from(...) |

View File

@@ -1,2 +1,2 @@
multipleCallTargets multipleResolvedTargets
| main.rs:9:43:9:63 | ...::from(...) | | main.rs:9:43:9:63 | ...::from(...) |

View File

@@ -1,4 +1,20 @@
multipleCallTargets multipleResolvedTargets
| test_logging.rs:214:13:214:22 | * ... |
| test_logging.rs:214:13:214:22 | * ... |
| test_logging.rs:214:13:214:22 | * ... |
| test_logging.rs:214:13:214:22 | * ... |
| test_logging.rs:217:13:217:22 | * ... |
| test_logging.rs:217:13:217:22 | * ... |
| test_logging.rs:217:13:217:22 | * ... |
| test_logging.rs:217:13:217:22 | * ... |
| test_logging.rs:223:13:223:28 | * ... |
| test_logging.rs:223:13:223:28 | * ... |
| test_logging.rs:223:13:223:28 | * ... |
| test_logging.rs:223:13:223:28 | * ... |
| test_logging.rs:226:13:226:28 | * ... |
| test_logging.rs:226:13:226:28 | * ... |
| test_logging.rs:226:13:226:28 | * ... |
| test_logging.rs:226:13:226:28 | * ... |
| test_storage.rs:13:10:13:33 | ...::from(...) | | test_storage.rs:13:10:13:33 | ...::from(...) |
| test_storage.rs:17:10:17:35 | ...::from(...) | | test_storage.rs:17:10:17:35 | ...::from(...) |
| test_storage.rs:21:10:21:35 | ...::from(...) | | test_storage.rs:21:10:21:35 | ...::from(...) |

View File

@@ -1,2 +1,2 @@
multipleCallTargets multipleResolvedTargets
| test_cipher.rs:114:23:114:50 | ...::new(...) | | test_cipher.rs:114:23:114:50 | ...::new(...) |

View File

@@ -1,6 +1,12 @@
multipleCallTargets multipleResolvedTargets
| deallocation.rs:354:11:354:29 | ...::from(...) | | deallocation.rs:354:11:354:29 | ...::from(...) |
| deallocation.rs:355:11:355:29 | ...::from(...) | | deallocation.rs:355:11:355:29 | ...::from(...) |
| lifetime.rs:217:17:217:25 | * ... |
| lifetime.rs:610:13:610:31 | ...::from(...) | | lifetime.rs:610:13:610:31 | ...::from(...) |
| lifetime.rs:611:13:611:31 | ...::from(...) | | lifetime.rs:611:13:611:31 | ...::from(...) |
| lifetime.rs:628:13:628:31 | ...::from(...) | | lifetime.rs:628:13:628:31 | ...::from(...) |
| lifetime.rs:630:11:630:25 | * ... |
| lifetime.rs:692:12:692:14 | * ... |
| lifetime.rs:693:12:693:14 | * ... |
| lifetime.rs:694:12:694:14 | * ... |
| lifetime.rs:734:11:734:13 | * ... |

View File

@@ -1,6 +1,31 @@
multipleCallTargets multipleResolvedTargets
| main.rs:14:13:14:29 | ...::from(...) | | main.rs:14:13:14:29 | ...::from(...) |
| main.rs:15:13:15:29 | ...::from(...) | | main.rs:15:13:15:29 | ...::from(...) |
| main.rs:223:9:223:18 | * ... |
| main.rs:223:9:223:18 | * ... |
| main.rs:223:9:223:18 | * ... |
| main.rs:223:9:223:18 | * ... |
| main.rs:228:9:228:18 | * ... |
| main.rs:228:9:228:18 | * ... |
| main.rs:228:9:228:18 | * ... |
| main.rs:228:9:228:18 | * ... |
| main.rs:353:5:353:14 | * ... |
| main.rs:353:5:353:14 | * ... |
| main.rs:353:5:353:14 | * ... |
| main.rs:353:5:353:14 | * ... |
| main.rs:539:13:539:14 | * ... |
| main.rs:544:19:544:20 | * ... |
| more.rs:34:11:34:19 | * ... |
| more.rs:45:20:45:26 | * ... |
| more.rs:56:20:56:30 | * ... |
| more.rs:56:21:56:30 | * ... |
| more.rs:61:20:61:30 | * ... |
| more.rs:61:21:61:30 | * ... |
| more.rs:67:20:67:25 | * ... |
| more.rs:71:5:71:10 | * ... |
| more.rs:75:5:75:10 | * ... |
| more.rs:80:5:80:10 | * ... |
| more.rs:82:20:82:26 | * ... |
| unreachable.rs:165:20:165:42 | ...::from(...) | | unreachable.rs:165:20:165:42 | ...::from(...) |
| unreachable.rs:171:9:171:15 | ...::from(...) | | unreachable.rs:171:9:171:15 | ...::from(...) |
| unreachable.rs:177:17:177:25 | ...::from(...) | | unreachable.rs:177:17:177:25 | ...::from(...) |

View File

@@ -0,0 +1,9 @@
multipleResolvedTargets
| option.rs:34:18:34:22 | * ... |
| option.rs:61:15:61:19 | * ... |
| option.rs:69:15:69:19 | * ... |
| option.rs:306:9:306:13 | * ... |
| option.rs:335:13:335:17 | * ... |
| option.rs:483:27:483:29 | * ... |
| summaries.rs:87:5:87:6 | * ... |
| summaries.rs:92:5:92:6 | * ... |