Merge pull request #14086 from hvitved/csharp/perf-fixes

C#: Various performance fixes
This commit is contained in:
Tom Hvitved
2023-08-30 12:13:52 +02:00
committed by GitHub
5 changed files with 53 additions and 29 deletions

View File

@@ -538,7 +538,8 @@ module Unification {
*
* Note: This predicate is inlined.
*/
bindingset[t]
bindingset[this]
pragma[inline_late]
predicate unifiable(Type t) { none() }
/**
@@ -546,7 +547,8 @@ module Unification {
*
* Note: This predicate is inlined.
*/
bindingset[t]
bindingset[this]
pragma[inline_late]
predicate subsumes(Type t) { none() }
}
@@ -554,7 +556,8 @@ module Unification {
private class SingleConstraintTypeParameter extends ConstrainedTypeParameter {
SingleConstraintTypeParameter() { constraintCount = 1 }
bindingset[t]
bindingset[this]
pragma[inline_late]
override predicate unifiable(Type t) {
exists(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
ttc = TRefTypeConstraint() and
@@ -567,7 +570,8 @@ module Unification {
)
}
bindingset[t]
bindingset[this]
pragma[inline_late]
override predicate subsumes(Type t) {
exists(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
ttc = TRefTypeConstraint() and
@@ -585,9 +589,13 @@ module Unification {
private class MultiConstraintTypeParameter extends ConstrainedTypeParameter {
MultiConstraintTypeParameter() { constraintCount > 1 }
bindingset[t]
pragma[nomagic]
TTypeParameterConstraint getATypeConstraint() { result = getATypeConstraint(this) }
bindingset[this]
pragma[inline_late]
override predicate unifiable(Type t) {
forex(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
forex(TTypeParameterConstraint ttc | ttc = this.getATypeConstraint() |
ttc = TRefTypeConstraint() and
t.isRefType()
or
@@ -598,9 +606,10 @@ module Unification {
)
}
bindingset[t]
bindingset[this]
pragma[inline_late]
override predicate subsumes(Type t) {
forex(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
forex(TTypeParameterConstraint ttc | ttc = this.getATypeConstraint() |
ttc = TRefTypeConstraint() and
t.isRefType()
or

View File

@@ -299,6 +299,12 @@ class NUnitAssertNonNullMethod extends NullnessAssertMethod, NUnitAssertMethod {
override int getAnAssertionIndex(boolean b) { result = this.getAnAssertionIndex() and b = false }
}
pragma[nomagic]
private predicate parameterAssertion(Assertion a, int index, Parameter p) {
strictcount(AssignableDefinition def | def.getTarget() = p) = 1 and
a.getExpr(index) = p.getAnAccess()
}
/** A method that forwards to another assertion method. */
class ForwarderAssertMethod extends AssertMethod {
private Assertion a;
@@ -307,10 +313,9 @@ class ForwarderAssertMethod extends AssertMethod {
ForwarderAssertMethod() {
p = this.getAParameter() and
strictcount(AssignableDefinition def | def.getTarget() = p) = 1 and
forex(ControlFlowElement body | body = this.getBody() |
bodyAsserts(this, body, a) and
a.getExpr(forwarderIndex) = p.getAnAccess()
parameterAssertion(a, forwarderIndex, p)
)
}

View File

@@ -1159,6 +1159,7 @@ private predicate adjacentDefReachesUncertainRead(
)
}
pragma[nomagic]
private predicate adjacentDefReachesUncertainReadExt(
DefinitionExt def, SsaInput::BasicBlock bb1, int i1, SsaInput::BasicBlock bb2, int i2
) {

View File

@@ -862,9 +862,7 @@ private module Internal {
or
Unification::subsumes(t, qualifierType)
or
t.(Unification::ConstrainedTypeParameter).unifiable(qualifierType)
or
qualifierType = t.(Unification::UnconstrainedTypeParameter).getAnUltimatelySuppliedType()
qualifierType = t.(TypeParameter).getAnUltimatelySuppliedType()
)
}

View File

@@ -399,13 +399,20 @@ module Make<LocationSig Location, InputSig<Location> Input> {
}
}
private predicate isFullyConstructedSplits(Splits splits) { exists(TAstNode(_, _, splits)) }
/**
* A set of control flow node splits. The set is represented by a list of splits,
* ordered by ascending rank.
*/
class Splits extends TSplits {
/** Gets a textual representation of this set of splits. */
string toString() { result = splitsToString(this) }
string toString() {
result = splitsToString(this)
or
not isFullyConstructedSplits(this) and
result = "<partial split set>"
}
/** Gets a split belonging to this set of splits. */
SplitImpl getASplit() {
@@ -857,23 +864,27 @@ module Make<LocationSig Location, InputSig<Location> Input> {
succEntrySplitsCons(_, _, head, tail, _)
}
private string getSplitStringAt(Splits split, int index) {
exists(SplitImpl head, Splits tail | split = TSplitsCons(head, tail) |
index = 0 and result = head.toString() and result != ""
or
index > 0 and result = getSplitStringAt(tail, index - 1)
)
}
private string getSplitsStringPart(Splits splits, int index) {
isFullyConstructedSplits(splits) and
result = getSplitStringAt(splits, index)
}
cached
string splitsToString(Splits splits) {
splits = TSplitsNil() and
result = ""
or
exists(SplitImpl head, Splits tail, string headString, string tailString |
splits = TSplitsCons(head, tail)
|
headString = head.toString() and
tailString = tail.toString() and
if tailString = ""
then result = headString
else
if headString = ""
then result = tailString
else result = headString + ", " + tailString
)
result =
concat(string child, int index |
child = getSplitsStringPart(splits, index)
|
child, ", " order by index
)
}
/**