Skip to content

Commit 936a960

Browse files
committed
wip
1 parent 5cf1fc4 commit 936a960

2 files changed

Lines changed: 129 additions & 94 deletions

File tree

rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private module Input3 implements InputSig3 {
367367
}
368368

369369
private class ConstDeclaration extends VariableDeclaration instanceof Const {
370-
override predicate isCoercionSite() { none() }
370+
override predicate isCoercionSite() { any() }
371371

372372
override TypeMention getType() { result = super.getTypeRepr() }
373373

@@ -377,7 +377,7 @@ private module Input3 implements InputSig3 {
377377
}
378378

379379
private class StaticDeclaration extends VariableDeclaration instanceof Static {
380-
override predicate isCoercionSite() { none() }
380+
override predicate isCoercionSite() { any() }
381381

382382
override TypeMention getType() { result = super.getTypeRepr() }
383383

@@ -454,10 +454,10 @@ private module Input3 implements InputSig3 {
454454
final class Parameter = ParameterImpl;
455455

456456
/** A parameter, including enum/struct constructor fields. */
457-
abstract private class ParameterImpl extends AstNode {
458-
abstract AstNode getPattern();
457+
abstract private class ParameterImpl extends VariableDeclaration {
458+
override predicate isCoercionSite() { any() } // doesn't really matter, since there are no initializers
459459

460-
abstract TypeMention getType();
460+
override AstNode getInitializer() { none() }
461461
}
462462

463463
private class SelfParamParameter extends ParameterImpl, SelfParam {
@@ -941,25 +941,25 @@ private module Input3 implements InputSig3 {
941941
exists(c)
942942
}
943943

944-
predicate inferStepCertain(AstNode n1, TypePath path1, AstNode n2, TypePath path2) {
944+
predicate inferStepCertain(AstNode n1, TypePath prefix1, AstNode n2, TypePath prefix2) {
945945
n1 =
946946
any(IdentPat ip |
947947
n2 = ip.getName() and
948-
path1.isEmpty() and
948+
prefix1.isEmpty() and
949949
if ip.isRef()
950950
then
951951
exists(boolean isMutable | if ip.isMut() then isMutable = true else isMutable = false |
952-
path2 = TypePath::singleton(getRefTypeParameter(isMutable))
952+
prefix2 = TypePath::singleton(getRefTypeParameter(isMutable))
953953
)
954-
else path2.isEmpty()
954+
else prefix2.isEmpty()
955955
)
956956
or
957957
exists(CallExprImpl::DynamicCallExpr dce, TupleType tt, int i |
958958
n1 = dce.getSyntacticPositionalArgument(i) and
959959
n2 = dce.getArgList() and
960960
tt.getArity() = dce.getNumberOfSyntacticArguments() and
961-
path1.isEmpty() and
962-
path2 = TypePath::singleton(tt.getPositionalTypeParameter(i))
961+
prefix1.isEmpty() and
962+
prefix2 = TypePath::singleton(tt.getPositionalTypeParameter(i))
963963
)
964964
}
965965

@@ -1001,44 +1001,44 @@ private module Input3 implements InputSig3 {
10011001
result = inferClosureArgsType(n, path)
10021002
}
10031003

1004-
predicate inferStep(AstNode n1, TypePath path1, AstNode n2, TypePath path2) {
1004+
predicate inferStep(AstNode n1, TypePath prefix1, AstNode n2, TypePath prefix2) {
10051005
// When `n2` is `*n1` propagate type information from a raw pointer type
10061006
// parameter at `n1` (all other deref expressions are handled as calls)
10071007
n1 = n2.(DerefExpr).getExpr() and
1008-
path1 = TypePath::singleton(getPtrTypeParameter()) and
1009-
path2.isEmpty()
1008+
prefix1 = TypePath::singleton(getPtrTypeParameter()) and
1009+
prefix2.isEmpty()
10101010
or
1011-
path1.isEmpty() and
1011+
prefix1.isEmpty() and
10121012
(
10131013
n1 = n2.(ArrayListExpr).getAnExpr() and
1014-
path2 = TypePath::singleton(getArrayTypeParameter())
1014+
prefix2 = TypePath::singleton(getArrayTypeParameter())
10151015
or
10161016
exists(Struct s |
10171017
n1 = [n2.(RangeExpr).getStart(), n2.(RangeExpr).getEnd()] and
1018-
path2 =
1018+
prefix2 =
10191019
TypePath::singleton(TTypeParamTypeParameter(s.getGenericParamList().getATypeParam())) and
10201020
s = getRangeType(n2)
10211021
)
10221022
or
10231023
n2 =
10241024
any(RefExpr re |
10251025
n1 = re.getExpr() and
1026-
path2 = TypePath::singleton(inferRefExprType(re).getPositionalTypeParameter(0))
1026+
prefix2 = TypePath::singleton(inferRefExprType(re).getPositionalTypeParameter(0))
10271027
)
10281028
or
10291029
exists(BlockExpr be |
10301030
n2 = be and
10311031
n1 = be.getStmtList().getTailExpr() and
10321032
if be.isAsync()
1033-
then path2 = TypePath::singleton(getDynFutureOutputTypeParameter())
1034-
else path2.isEmpty()
1033+
then prefix2 = TypePath::singleton(getDynFutureOutputTypeParameter())
1034+
else prefix2.isEmpty()
10351035
)
10361036
or
10371037
// an array repeat expression (`[1; 3]`) has the type of the repeat operand
10381038
n2.(ArrayRepeatExpr).getRepeatOperand() = n1 and
1039-
path2 = TypePath::singleton(getArrayTypeParameter())
1039+
prefix2 = TypePath::singleton(getArrayTypeParameter())
10401040
or
1041-
path2.isEmpty() and
1041+
prefix2.isEmpty() and
10421042
(
10431043
exists(ReturnExpr re, Rust::Callable c |
10441044
n1 = re.getExpr() and
@@ -1067,9 +1067,9 @@ private module Input3 implements InputSig3 {
10671067
n1 =
10681068
any(RefPat rp |
10691069
n2 = rp.getPat() and
1070-
path2.isEmpty() and
1070+
prefix2.isEmpty() and
10711071
exists(boolean isMutable | if rp.isMut() then isMutable = true else isMutable = false |
1072-
path1 = TypePath::singleton(getRefTypeParameter(isMutable))
1072+
prefix1 = TypePath::singleton(getRefTypeParameter(isMutable))
10731073
)
10741074
)
10751075
or
@@ -1078,13 +1078,13 @@ private module Input3 implements InputSig3 {
10781078
|
10791079
arity = n2.(TupleExpr).getNumberOfFields() and
10801080
n1 = n2.(TupleExpr).getField(i) and
1081-
path1.isEmpty() and
1082-
path2 = path
1081+
prefix1.isEmpty() and
1082+
prefix2 = path
10831083
or
10841084
arity = n1.(TuplePat).getTupleArity() and
10851085
n2 = n1.(TuplePat).getField(i) and
1086-
path2.isEmpty() and
1087-
path1 = path
1086+
prefix2.isEmpty() and
1087+
prefix1 = path
10881088
)
10891089
}
10901090

0 commit comments

Comments
 (0)