Skip to content

Commit a5ea635

Browse files
committed
Unified: Stats for type mentions
1 parent 605dc1c commit a5ea635

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ private import codeql.unified.internal.NameBinding
44
private import codeql.unified.internal.dataflow.DataFlowCall
55
private import codeql.unified.internal.dataflow.DataFlowCallable
66
private import codeql.unified.internal.dataflow.CallGraph
7+
private import codeql.unified.internal.typeinference.Type as Type
8+
private import codeql.unified.internal.typeinference.TypeMention
79

810
/** Stats about name nodes that static name binding could resolve. */
911
module StaticNameResolutionStats implements EntityStatsSig {
@@ -109,6 +111,18 @@ module CallGraphStats implements EntityStatsSig {
109111

110112
module CallGraphStatsReport = EntityReportStats<CallGraphStats>;
111113

114+
module TypeMentionStats implements EntityStatsSig {
115+
class Candidate extends ExprTypeMention {
116+
predicate isOk() { this.getType() = any(Type::Type t | not t instanceof Type::UnknownType) }
117+
}
118+
119+
string getOkText() { result = "resolvable type mentions" }
120+
121+
string getNotOkText() { result = "unresolvable type mentions" }
122+
}
123+
124+
module TypeMentionStatsReport = EntityReportStats<TypeMentionStats>;
125+
112126
/**
113127
* Gets summary statistics about taint.
114128
*/

‎unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ private import TypeInferencePlugin as Plugin
55
private import codeql.unified.internal.StaticNameBinding
66
private import codeql.unified.internal.ExprPositions
77

8+
final class TypeMention = TypeMentionImpl;
9+
810
/** An AST node that mentions a type. */
9-
abstract class TypeMention extends AstNode {
11+
abstract private class TypeMentionImpl extends AstNode {
1012
/**
1113
* Gets the type mentioned at `path`.
1214
*/
@@ -27,8 +29,10 @@ private Type resolveType(Identifier access) {
2729
)
2830
}
2931

30-
abstract private class ExprTypeMention extends TypeMention, Expr {
31-
ExprTypeMention() { isInTypeContext(this) }
32+
final class ExprTypeMention = ExprTypeMentionImpl;
33+
34+
abstract private class ExprTypeMentionImpl extends TypeMentionImpl, Expr {
35+
ExprTypeMentionImpl() { isInTypeContext(this) }
3236

3337
pragma[nomagic]
3438
abstract TypePath getTypeArgumentPath(int i);
@@ -37,7 +41,7 @@ abstract private class ExprTypeMention extends TypeMention, Expr {
3741
/**
3842
* A type mention that resolves via an alias (aliases are expanded).
3943
*/
40-
private class AliasExprTypeMention extends ExprTypeMention {
44+
private class AliasExprTypeMention extends ExprTypeMentionImpl {
4145
private TypeAliasDeclaration alias;
4246

4347
AliasExprTypeMention() { alias.getNameNode() = getStaticBindingTargetFromRef(this) }
@@ -62,7 +66,7 @@ private class AliasExprTypeMention extends ExprTypeMention {
6266
/**
6367
* A type mention that does not resolve via an alias.
6468
*/
65-
private class NonAliasExprTypeMention extends ExprTypeMention {
69+
private class NonAliasExprTypeMention extends ExprTypeMentionImpl {
6670
NonAliasExprTypeMention() { not this instanceof AliasExprTypeMention }
6771

6872
private Type getRootType0() {
@@ -141,7 +145,7 @@ private class NonAliasExprTypeMention extends ExprTypeMention {
141145
}
142146
}
143147

144-
private class GenericTypeExprTypeMention extends TypeMention, GenericTypeExpr {
148+
private class GenericTypeExprTypeMention extends TypeMentionImpl, GenericTypeExpr {
145149
private ExprTypeMention base;
146150

147151
GenericTypeExprTypeMention() { base = this.getBase() }
@@ -163,7 +167,7 @@ private class GenericTypeExprTypeMention extends TypeMention, GenericTypeExpr {
163167
}
164168

165169
/** A class declaration mentions itself. */
166-
private class ClassLikeDeclarationTypeMention extends TypeMention, Identifier {
170+
private class ClassLikeDeclarationTypeMention extends TypeMentionImpl, Identifier {
167171
private ClassLikeDeclaration c;
168172

169173
ClassLikeDeclarationTypeMention() { this = c.getNameNode() }

‎unified/ql/src/diagnostic/ExtractorInformation.ql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ where
4242
numberOfLinesOfCodeByExtension(key, value) or
4343
StaticNameResolutionStatsReport::keyValuePair(key, value) or
4444
FilesCoveredByModuleManifestStatsReport::keyValuePair(key, value) or
45-
CallGraphStatsReport::keyValuePair(key, value)
45+
CallGraphStatsReport::keyValuePair(key, value) or
46+
TypeMentionStatsReport::keyValuePair(key, value)
4647
) and
4748
/* Infinity */
4849
value != 1.0 / 0.0 and

0 commit comments

Comments
 (0)