Skip to content

Commit 606a8fe

Browse files
authored
Merge pull request github#15406 from hvitved/csharp/no-stats-experiment
C#: Remove all DB stats
2 parents c22cbf5 + 5f5bcf6 commit 606a8fe

File tree

11 files changed

+109
-41769
lines changed

11 files changed

+109
-41769
lines changed

csharp/ql/lib/semmle/code/csharp/AnnotatedType.qll

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ private module Annotations {
159159
getNoFlagsNullability(result) = getChildNullability(annotations.getNullability(), i)
160160
}
161161

162+
pragma[nomagic]
163+
private Nullability getChildNullability0(Nullability n, int i) {
164+
nullability_parent(getNullability(result), i, getNullability(n))
165+
}
166+
162167
/**
163168
* Gets the `i`th child of nullability `n`.
164169
* Returns `n` if the nullability is not explicitly
@@ -167,9 +172,10 @@ private module Annotations {
167172
*/
168173
bindingset[i]
169174
Nullability getChildNullability(Nullability n, int i) {
170-
if nullability_parent(_, i, getNullability(n))
171-
then nullability_parent(getNullability(result), i, getNullability(n))
172-
else result = n
175+
result = getChildNullability0(n, i)
176+
or
177+
not exists(getChildNullability0(n, i)) and
178+
result = n
173179
}
174180

175181
/**
@@ -276,6 +282,11 @@ private Annotations::Nullability getElementNullability(@has_type_annotation elem
276282
else result instanceof Annotations::NoNullability
277283
}
278284

285+
pragma[nomagic]
286+
private predicate isNoFlagsNoNullability(Annotations::TypeAnnotations annotations) {
287+
Annotations::getNoFlagsNullability(annotations) instanceof Annotations::NoNullability
288+
}
289+
279290
private newtype TAnnotatedType =
280291
TAnnotatedTypeNullability(Type type, Annotations::TypeAnnotations annotations) {
281292
Annotations::elementTypeAnnotations(_, type, annotations)
@@ -288,7 +299,7 @@ private newtype TAnnotatedType =
288299
Annotations::getNoFlagsNullability(annotations) = getTypeParameterNullability(_, type)
289300
or
290301
// All types have at least one annotated type
291-
Annotations::getNoFlagsNullability(annotations) instanceof Annotations::NoNullability
302+
isNoFlagsNoNullability(annotations) and exists(type)
292303
or
293304
exists(AnnotatedArrayType at |
294305
type = at.getType().(ArrayType).getElementType() and

csharp/ql/lib/semmle/code/csharp/Generics.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,16 @@ private string getTypeArgumentsToString(ConstructedGeneric cg) {
9595
strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.toStringWithTypes(), ", " order by i)
9696
}
9797

98+
pragma[nomagic]
99+
private string getTypeArgumentName(ConstructedGeneric cg, int i) {
100+
result = cg.getTypeArgument(i).getName()
101+
}
102+
98103
/** Gets the concatenation of the `getName()` of type arguments. */
99104
language[monotonicAggregates]
100105
private string getTypeArgumentsNames(ConstructedGeneric cg) {
101-
result = strictconcat(Type t, int i | t = cg.getTypeArgument(i) | t.getName(), "," order by i)
106+
result =
107+
strictconcat(int i | exists(cg.getTypeArgument(i)) | getTypeArgumentName(cg, i), "," order by i)
102108
}
103109

104110
/**
@@ -197,9 +203,9 @@ class TypeParameter extends DotNet::TypeParameter, Type, @type_parameter {
197203
// A<int>.B<T2> is a partially constructed UnboundGenericClass and
198204
// A<int>.B<int> is a ConstructedGenericClass.
199205
exists(ConstructedGeneric c, UnboundGeneric u, int tpi |
200-
this = u.getTypeParameter(tpi) and
206+
this = u.getTypeParameter(pragma[only_bind_into](tpi)) and
201207
(u = c.getUnboundGeneric() or u = c.getUnboundDeclaration()) and
202-
result = c.getTypeArgument(tpi)
208+
result = c.getTypeArgument(pragma[only_bind_into](tpi))
203209
)
204210
}
205211

csharp/ql/lib/semmle/code/csharp/Implements.qll

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,28 +108,29 @@ private predicate hasMemberCompatibleWithInterfaceMember(ValueOrRefType t, Virtu
108108
*/
109109
pragma[nomagic]
110110
private Virtualizable getACompatibleInterfaceMember(Virtualizable m) {
111-
result = getACompatibleInterfaceMemberAux(m) and
112-
(
111+
exists(ValueOrRefType declType | result = getACompatibleInterfaceMemberAux(m, declType) |
113112
// If there is both an implicit and an explicit compatible member
114113
// in the same type, then the explicit implementation must be used
115-
not result = getACompatibleExplicitInterfaceMember(_, m.getDeclaringType())
114+
not result = getACompatibleExplicitInterfaceMember(_, declType)
116115
or
117-
result = getACompatibleExplicitInterfaceMember(m, m.getDeclaringType())
116+
result = getACompatibleExplicitInterfaceMember(m, declType)
118117
)
119118
}
120119

121120
pragma[nomagic]
122121
private Virtualizable getACompatibleExplicitInterfaceMember(Virtualizable m, ValueOrRefType declType) {
123-
result = getACompatibleInterfaceMemberAux(m) and
124-
declType = m.getDeclaringType() and
122+
result = getACompatibleInterfaceMemberAux(m, declType) and
125123
m.implementsExplicitInterface()
126124
}
127125

128126
pragma[nomagic]
129-
private Virtualizable getACompatibleInterfaceMemberAux(Virtualizable m) {
130-
result = getACompatibleInterfaceAccessor(m) or
131-
result = getACompatibleInterfaceIndexer(m) or
132-
result = getACompatibleRelevantInterfaceMember(m)
127+
private Virtualizable getACompatibleInterfaceMemberAux(Virtualizable m, ValueOrRefType declType) {
128+
(
129+
result = getACompatibleInterfaceAccessor(m) or
130+
result = getACompatibleInterfaceIndexer(m) or
131+
result = getACompatibleRelevantInterfaceMember(m)
132+
) and
133+
declType = m.getDeclaringType()
133134
}
134135

135136
/**
@@ -182,13 +183,16 @@ ValueOrRefType getAPossibleImplementor(Interface i) {
182183
not result instanceof Interface
183184
}
184185

186+
pragma[nomagic]
187+
private Type getParameterType(Parameterizable p, int i) { result = p.getParameter(i).getType() }
188+
185189
private Indexer getACompatibleInterfaceIndexer0(Indexer i, int j) {
186190
result = getACompatibleInterfaceIndexerCandidate(i) and
187191
convIdentity(i.getType(), result.getType()) and
188192
j = -1
189193
or
190194
result = getACompatibleInterfaceIndexer0(i, j - 1) and
191-
convIdentity(i.getParameter(j).getType(), result.getParameter(j).getType())
195+
convIdentity(getParameterType(i, j), getParameterType(result, j))
192196
}
193197

194198
/**

csharp/ql/lib/semmle/code/csharp/commons/QualifiedName.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,20 @@ module QualifiedName<QualifiedNameInputSig Input> {
4949
)
5050
}
5151

52+
pragma[nomagic]
53+
private string getTypeArgumentsQualifiedName(ConstructedGeneric cg, int i) {
54+
result = getFullName(cg.getTypeArgument(i))
55+
}
56+
5257
/** Gets the concatenation of the `getFullName` of type arguments. */
5358
language[monotonicAggregates]
5459
private string getTypeArgumentsQualifiedNames(ConstructedGeneric cg) {
5560
result =
56-
strictconcat(Type t, int i | t = cg.getTypeArgument(i) | getFullName(t), "," order by i)
61+
strictconcat(int i |
62+
exists(cg.getTypeArgument(i))
63+
|
64+
getTypeArgumentsQualifiedName(cg, i), "," order by i
65+
)
5766
}
5867

5968
/** Holds if declaration `d` has the qualified name `qualifier`.`name`. */

csharp/ql/lib/semmle/code/csharp/commons/StructuralComparison.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ predicate toGvn = toGvnCached/1;
195195
/**
196196
* Holds if the control flow elements `x` and `y` are structurally equal.
197197
*/
198-
pragma[inline]
199-
predicate sameGvn(ControlFlowElement x, ControlFlowElement y) {
200-
pragma[only_bind_into](toGvn(pragma[only_bind_out](x))) =
201-
pragma[only_bind_into](toGvn(pragma[only_bind_out](y)))
202-
}
198+
bindingset[x, y]
199+
pragma[inline_late]
200+
predicate sameGvn(ControlFlowElement x, ControlFlowElement y) { toGvn(x) = toGvn(y) }

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,12 +1013,18 @@ module Internal {
10131013
* Holds if pre-basic-block `bb` only is reached when guard `g` has abstract value `v`,
10141014
* not taking implications into account.
10151015
*/
1016+
pragma[nomagic]
10161017
private predicate preControlsDirect(Guard g, PreBasicBlocks::PreBasicBlock bb, AbstractValue v) {
10171018
exists(PreBasicBlocks::ConditionBlock cb, ConditionalSuccessor s | cb.controls(bb, s) |
10181019
v.branch(cb.getLastElement(), s, g)
10191020
)
10201021
}
10211022

1023+
pragma[nomagic]
1024+
private predicate preControlsDefDirect(Guard g, PreSsa::Definition def, AbstractValue v) {
1025+
preControlsDirect(g, def.getBasicBlock(), v)
1026+
}
1027+
10221028
/** Holds if pre-basic-block `bb` only is reached when guard `g` has abstract value `v`. */
10231029
predicate preControls(Guard g, PreBasicBlocks::PreBasicBlock bb, AbstractValue v) {
10241030
preControlsDirect(g, bb, v)
@@ -1111,36 +1117,47 @@ module Internal {
11111117
)
11121118
}
11131119

1114-
pragma[noinline]
1120+
pragma[nomagic]
11151121
private predicate conditionalAssign0(
11161122
Guard guard, AbstractValue vGuard, PreSsa::PhiNode phi, Expr e, PreSsa::Definition upd,
1117-
PreBasicBlocks::PreBasicBlock bbGuard
1123+
PreBasicBlocks::PreBasicBlock bbGuard, PreBasicBlocks::PreBasicBlock bbPhi
11181124
) {
11191125
e = upd.getDefinition().getSource() and
11201126
upd = phi.getAnInput() and
1121-
preControlsDirect(guard, upd.getBasicBlock(), vGuard) and
1127+
preControlsDefDirect(guard, upd, vGuard) and
11221128
bbGuard.getAnElement() = guard and
1123-
bbGuard.strictlyDominates(phi.getBasicBlock()) and
1124-
not preControlsDirect(guard, phi.getBasicBlock(), vGuard)
1129+
bbPhi = phi.getBasicBlock()
11251130
}
11261131

11271132
pragma[noinline]
11281133
private predicate conditionalAssign1(
1134+
Guard guard, AbstractValue vGuard, PreSsa::PhiNode phi, Expr e, PreSsa::Definition upd,
1135+
PreBasicBlocks::PreBasicBlock bbGuard
1136+
) {
1137+
exists(PreBasicBlocks::PreBasicBlock bbPhi |
1138+
conditionalAssign0(guard, vGuard, phi, e, upd, bbGuard, bbPhi) and
1139+
bbGuard.strictlyDominates(bbPhi) and
1140+
not preControlsDefDirect(guard, phi, vGuard)
1141+
)
1142+
}
1143+
1144+
pragma[noinline]
1145+
private predicate conditionalAssign2(
11291146
Guard guard, AbstractValue vGuard, PreSsa::PhiNode phi, Expr e, PreSsa::Definition upd,
11301147
PreBasicBlocks::PreBasicBlock bbGuard, PreSsa::Definition other
11311148
) {
1132-
conditionalAssign0(guard, vGuard, phi, e, upd, bbGuard) and
1149+
conditionalAssign1(guard, vGuard, phi, e, upd, bbGuard) and
11331150
other != upd and
11341151
other = phi.getAnInput()
11351152
}
11361153

11371154
pragma[noinline]
1138-
private predicate conditionalAssign2(
1155+
private predicate conditionalAssign3(
11391156
Guard guard, AbstractValue vGuard, PreSsa::Definition def, Expr e, PreSsa::Definition upd,
11401157
PreBasicBlocks::PreBasicBlock bbGuard, PreSsa::Definition other
11411158
) {
1142-
conditionalAssign1(guard, vGuard, def, e, upd, bbGuard, other) and
1143-
preControlsDirect(guard, other.getBasicBlock(), vGuard.getDualValue())
1159+
conditionalAssign2(guard, vGuard, def, e, upd, bbGuard, other) and
1160+
preControlsDefDirect(guard, other, vGuard.getDualValue())
11441161
}
11451162

11461163
/** Gets the successor block that is reached when guard `g` has abstract value `v`. */
@@ -1153,11 +1170,11 @@ module Internal {
11531170
}
11541171

11551172
pragma[noinline]
1156-
private predicate conditionalAssign3(
1173+
private predicate conditionalAssign4(
11571174
Guard guard, AbstractValue vGuard, PreSsa::Definition def, Expr e, PreSsa::Definition upd,
11581175
PreBasicBlocks::PreBasicBlock bbGuard, PreSsa::Definition other
11591176
) {
1160-
conditionalAssign1(guard, vGuard, def, e, upd, bbGuard, other) and
1177+
conditionalAssign2(guard, vGuard, def, e, upd, bbGuard, other) and
11611178
other.getBasicBlock().dominates(bbGuard) and
11621179
not other.isLiveAtEndOfBlock(getConditionalSuccessor(guard, vGuard))
11631180
}
@@ -1184,25 +1201,25 @@ module Internal {
11841201
)
11851202
or
11861203
exists(PreSsa::Definition upd, PreBasicBlocks::PreBasicBlock bbGuard |
1187-
conditionalAssign0(guard, vGuard, def, e, upd, bbGuard)
1204+
conditionalAssign1(guard, vGuard, def, e, upd, bbGuard)
11881205
|
11891206
forall(PreSsa::Definition other |
1190-
conditionalAssign1(guard, vGuard, def, e, upd, bbGuard, other)
1207+
conditionalAssign2(guard, vGuard, def, e, upd, bbGuard, other)
11911208
|
11921209
// For example:
11931210
// if (guard)
11941211
// upd = a;
11951212
// else
11961213
// other = b;
11971214
// def = phi(upd, other)
1198-
conditionalAssign2(guard, vGuard, def, e, upd, bbGuard, other)
1215+
conditionalAssign3(guard, vGuard, def, e, upd, bbGuard, other)
11991216
or
12001217
// For example:
12011218
// other = a;
12021219
// if (guard)
12031220
// upd = b;
12041221
// def = phi(other, upd)
1205-
conditionalAssign3(guard, vGuard, def, e, upd, bbGuard, other)
1222+
conditionalAssign4(guard, vGuard, def, e, upd, bbGuard, other)
12061223
)
12071224
)
12081225
}

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ private newtype TCompletion =
4949
nestedFinallyCompletion(outer, nestLevel)
5050
}
5151

52-
pragma[noinline]
52+
pragma[nomagic]
53+
private int getAFinallyNestLevel() { result = any(Statements::TryStmtTree t).nestLevel() }
54+
55+
pragma[nomagic]
5356
private predicate nestedFinallyCompletion(Completion outer, int nestLevel) {
5457
(
5558
outer = TReturnCompletion()
@@ -64,7 +67,7 @@ private predicate nestedFinallyCompletion(Completion outer, int nestLevel) {
6467
or
6568
outer = TExitCompletion()
6669
) and
67-
nestLevel = any(Statements::TryStmtTree t).nestLevel()
70+
nestLevel = getAFinallyNestLevel()
6871
}
6972

7073
pragma[noinline]

csharp/ql/lib/semmle/code/csharp/controlflow/internal/PreBasicBlocks.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ class PreBasicBlock extends ControlFlowElement {
7575

7676
predicate immediatelyDominates(PreBasicBlock bb) { bbIDominates(this, bb) }
7777

78+
pragma[inline]
7879
predicate strictlyDominates(PreBasicBlock bb) { this.immediatelyDominates+(bb) }
7980

81+
pragma[inline]
8082
predicate dominates(PreBasicBlock bb) {
8183
bb = this
8284
or
@@ -97,6 +99,7 @@ class ConditionBlock extends PreBasicBlock {
9799
)
98100
}
99101

102+
pragma[nomagic]
100103
private predicate immediatelyControls(PreBasicBlock succ, ConditionalCompletion cc) {
101104
exists(ControlFlowElement last, Completion c |
102105
last = this.getLastElement() and

csharp/ql/lib/semmle/code/csharp/dispatch/OverridableCallable.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,19 @@ class OverridableCallable extends Callable, Overridable {
121121
result = c.getDeclaringType()
122122
}
123123

124+
pragma[nomagic]
124125
private predicate isDeclaringSubType(ValueOrRefType t) {
125126
t = this.getDeclaringType()
126127
or
127128
exists(ValueOrRefType mid | this.isDeclaringSubType(mid) | t = mid.getASubType())
128129
}
129130

131+
pragma[nomagic]
132+
private predicate isDeclaringSubType(ValueOrRefType t, ValueOrRefType sub) {
133+
this.isDeclaringSubType(t) and
134+
t = sub.getABaseType()
135+
}
136+
130137
pragma[noinline]
131138
private Callable getAnOverrider0(ValueOrRefType t) {
132139
// A (transitive) overrider
@@ -155,10 +162,7 @@ class OverridableCallable extends Callable, Overridable {
155162
Callable getAnOverrider(ValueOrRefType t) {
156163
result = this.getAnOverrider0(t)
157164
or
158-
exists(ValueOrRefType mid | result = this.getAnOverrider(mid) |
159-
t = mid.getABaseType() and
160-
this.isDeclaringSubType(t)
161-
)
165+
exists(ValueOrRefType mid | result = this.getAnOverrider(mid) | this.isDeclaringSubType(t, mid))
162166
}
163167
}
164168

0 commit comments

Comments
 (0)