Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rust/ql/lib/codeql/rust/dataflow/internal/ModelsAsData.qll
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private module Debug {
sc.propagatesFlow(input, _, _, _) and
input.head() = SummaryComponent::argument(pos) and
p = pos.getParameterIn(sc.getParamList()) and
tm.resolveType() instanceof RefType and
tm.getType() instanceof RefType and
not input.tail().head() = SummaryComponent::content(TSingletonContentSet(TReferenceContent()))
|
tm = p.getTypeRepr()
Expand All @@ -239,7 +239,7 @@ private module Debug {
exists(TypeMention tm |
relevantManualModel(sc, can) and
sc.propagatesFlow(_, output, _, _) and
tm.resolveType() instanceof RefType and
tm.getType() instanceof RefType and
output.head() = SummaryComponent::return(_) and
not output.tail().head() =
SummaryComponent::content(TSingletonContentSet(TReferenceContent())) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ predicate isBlanketLike(ImplItemNode i, TypePath blanketSelfPath, TypeParam blan
exists(TypeMention tm, Type root, TypeParameter tp |
tm = i.(Impl).getSelfTy() and
complexSelfRoot(root, tp) and
tm.resolveType() = root and
tm.resolveTypeAt(blanketSelfPath) = TTypeParamTypeParameter(blanketTypeParam) and
tm.getType() = root and
tm.getTypeAt(blanketSelfPath) = TTypeParamTypeParameter(blanketTypeParam) and
blanketSelfPath = TypePath::singleton(tp) and
hasFirstNonTrivialTraitBound(blanketTypeParam, _)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class DerefImplItemNode extends ImplItemNode {
*/
pragma[nomagic]
predicate targetHasTypeParameterAt(TypePath path) {
this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).resolveTypeAt(path)
instanceof TypeParameter
this.getAssocItem("Target").(TypeAlias).getTypeRepr().(TypeMention).getTypeAt(path) instanceof
TypeParameter
}

/** Gets the first type parameter of the type being implemented, if any. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private import FunctionType

pragma[nomagic]
private Type resolveNonTypeParameterTypeAt(TypeMention tm, TypePath path) {
result = tm.resolveTypeAt(path) and
result = tm.getTypeAt(path) and
not result instanceof TypeParameter
}

Expand All @@ -32,7 +32,7 @@ private predicate implSiblingCandidate(
) {
trait = impl.(ImplItemNode).resolveTraitTy() and
selfTy = impl.getSelfTy() and
rootType = selfTy.resolveType()
rootType = selfTy.getType()
}

pragma[nomagic]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ Type getAssocFunctionTypeAt(Function f, ImplOrTraitItemNode i, FunctionPosition
// No specialization needed when the function is directly in the trait or
// impl block or the declared type is not a type parameter
(parent = i or not result instanceof TypeParameter) and
result = pos.getTypeMention(f).resolveTypeAt(path)
result = pos.getTypeMention(f).getTypeAt(path)
or
exists(TypePath prefix, TypePath suffix, TypeParameter tp, TypeMention constraint |
BaseTypes::rootTypesSatisfaction(_, TTrait(parent), i, _, constraint) and
path = prefix.append(suffix) and
tp = pos.getTypeMention(f).resolveTypeAt(prefix) and
tp = pos.getTypeMention(f).getTypeAt(prefix) and
if tp = TSelfTypeParameter(_)
then result = resolveImplOrTraitType(i, suffix)
else result = getTraitConstraintTypeAt(i, constraint, tp, suffix)
Expand Down
69 changes: 32 additions & 37 deletions rust/ql/lib/codeql/rust/internal/typeinference/TypeInference.qll
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,11 @@ class TypePath = M1::TypePath;

module TypePath = M1::TypePath;

private module Input2 implements InputSig2 {
private import TypeMention as TM

class TypeMention = TM::TypeMention;

private module Input2 implements InputSig2<TypeMention> {
TypeMention getABaseTypeMention(Type t) { none() }

Type getATypeParameterConstraint(TypeParameter tp, TypePath path) {
exists(TypeMention tm | result = tm.resolveTypeAt(path) |
exists(TypeMention tm | result = tm.getTypeAt(path) |
tm = tp.(TypeParamTypeParameter).getTypeParam().getATypeBound().getTypeRepr() or
tm = tp.(SelfTypeParameter).getTrait() or
tm =
Expand Down Expand Up @@ -212,7 +208,7 @@ private module Input2 implements InputSig2 {
}
}

private module M2 = Make2<Input2>;
private module M2 = Make2<TypeMention, Input2>;

import M2

Expand All @@ -231,7 +227,7 @@ module Consistency {
// mention for the self type has multiple types for a path.
not exists(ImplItemNode impl, TypePath selfTypePath |
n = impl.getAnAssocItem().(Function).getSelfParam() and
strictcount(impl.(Impl).getSelfTy().(TypeMention).resolveTypeAt(selfTypePath)) > 1
strictcount(impl.(Impl).getSelfTy().(TypeMention).getTypeAt(selfTypePath)) > 1
)
}
}
Expand Down Expand Up @@ -297,7 +293,7 @@ private class FunctionDeclaration extends Function {
result = getAssocFunctionTypeAt(this, i.asSome(), pos, path)
or
i.isNone() and
result = this.getParam(pos.asPosition()).getTypeRepr().(TypeMention).resolveTypeAt(path)
result = this.getParam(pos.asPosition()).getTypeRepr().(TypeMention).getTypeAt(path)
)
}

Expand All @@ -308,7 +304,7 @@ private class FunctionDeclaration extends Function {
getAssocFunctionTypeAt(this, i.asSome(), any(FunctionPosition pos | pos.isReturn()), path)
or
i.isNone() and
result = getReturnTypeMention(this).resolveTypeAt(path)
result = getReturnTypeMention(this).getTypeAt(path)
)
}

Expand Down Expand Up @@ -352,12 +348,12 @@ private TypeMention getCallExprTypeMentionArgument(CallExpr ce, TypeArgumentPosi

pragma[nomagic]
private Type getCallExprTypeArgument(CallExpr ce, TypeArgumentPosition apos, TypePath path) {
result = getCallExprTypeMentionArgument(ce, apos).resolveTypeAt(path)
result = getCallExprTypeMentionArgument(ce, apos).getTypeAt(path)
or
// Handle constructions that use `Self(...)` syntax
exists(Path p, TypePath path0 |
p = CallExprImpl::getFunctionPath(ce) and
result = p.(TypeMention).resolveTypeAt(path0) and
result = p.(TypeMention).getTypeAt(path0) and
path0.isCons(TTypeParamTypeParameter(apos.asTypeParam()), path)
)
}
Expand All @@ -380,16 +376,16 @@ private TypeMention getTypeAnnotation(AstNode n) {
/** Gets the type of `n`, which has an explicit type annotation. */
pragma[nomagic]
private Type inferAnnotatedType(AstNode n, TypePath path) {
result = getTypeAnnotation(n).resolveTypeAt(path)
result = getTypeAnnotation(n).getTypeAt(path)
or
result = n.(ShorthandSelfParameterMention).resolveTypeAt(path)
result = n.(ShorthandSelfParameterMention).getTypeAt(path)
}

pragma[nomagic]
private Type inferFunctionBodyType(AstNode n, TypePath path) {
exists(Function f |
n = f.getFunctionBody() and
result = getReturnTypeMention(f).resolveTypeAt(path) and
result = getReturnTypeMention(f).getTypeAt(path) and
not exists(ImplTraitReturnType i | i.getFunction() = f |
result = i or result = i.getATypeParameter()
)
Expand Down Expand Up @@ -433,7 +429,7 @@ module CertainTypeInference {
private TypePath getPathToImplSelfTypeParam(TypeParam tp) {
exists(ImplItemNode impl |
tp = impl.getTypeParam(_) and
TTypeParamTypeParameter(tp) = impl.(Impl).getSelfTy().(TypeMention).resolveTypeAt(result)
TTypeParamTypeParameter(tp) = impl.(Impl).getSelfTy().(TypeMention).getTypeAt(result)
)
}

Expand All @@ -449,7 +445,7 @@ module CertainTypeInference {
// and the path `Foo<i64>::bar` we must resolve `A` to `i64`.
exists(TypePath pathToTp |
pathToTp = getPathToImplSelfTypeParam(tp) and
result = p.getQualifier().(TypeMention).resolveTypeAt(pathToTp.appendInverse(suffix))
result = p.getQualifier().(TypeMention).getTypeAt(pathToTp.appendInverse(suffix))
)
or
// For type parameters of the function we must resolve their
Expand All @@ -465,11 +461,11 @@ module CertainTypeInference {
}

private Type inferCertainStructExprType(StructExpr se, TypePath path) {
result = se.getPath().(TypeMention).resolveTypeAt(path)
result = se.getPath().(TypeMention).getTypeAt(path)
}

private Type inferCertainStructPatType(StructPat sp, TypePath path) {
result = sp.getPath().(TypeMention).resolveTypeAt(path)
result = sp.getPath().(TypeMention).getTypeAt(path)
}

predicate certainTypeEquality(AstNode n1, TypePath prefix1, AstNode n2, TypePath prefix2) {
Expand Down Expand Up @@ -905,7 +901,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
// type of a field
exists(TypeMention tp |
tp = this.getField(dpos.asFieldPos()).getTypeRepr() and
result = tp.resolveTypeAt(path)
result = tp.getTypeAt(path)
)
or
// type parameter of the struct itself
Expand Down Expand Up @@ -958,7 +954,7 @@ private module StructExprMatchingInput implements MatchingInputSig {
// Handle constructions that use `Self {...}` syntax
exists(TypeMention tm, TypePath path0 |
tm = this.getStructPath() and
result = tm.resolveTypeAt(path0) and
result = tm.getTypeAt(path0) and
path0.isCons(TTypeParamTypeParameter(apos.asTypeParam()), path)
)
}
Expand Down Expand Up @@ -1068,7 +1064,7 @@ pragma[nomagic]
private Type getCallExprTypeQualifier(CallExpr ce, TypePath path) {
exists(TypeMention tm |
tm = getCallExprPathQualifier(ce) and
result = tm.resolveTypeAt(path) and
result = tm.getTypeAt(path) and
not resolvePath(tm) instanceof Trait
)
}
Expand Down Expand Up @@ -2330,19 +2326,19 @@ private module MethodResolution {
* instance of the type being implemented.
*/
private module TypeQualifierIsInstantiationOfImplSelfInput implements
IsInstantiationOfInputSig<MethodCallCallExpr, TypeMentionTypeTree>
IsInstantiationOfInputSig<MethodCallCallExpr, TypeMention>
{
pragma[nomagic]
private predicate potentialInstantiationOf0(
MethodCallCallExpr ce, ImplItemNode impl, TypeMentionTypeTree constraint
MethodCallCallExpr ce, ImplItemNode impl, TypeMention constraint
) {
ce.hasTypeQualifiedCandidate(impl) and
constraint = impl.getSelfPath()
}

pragma[nomagic]
predicate potentialInstantiationOf(
MethodCallCallExpr ce, TypeAbstraction abs, TypeMentionTypeTree constraint
MethodCallCallExpr ce, TypeAbstraction abs, TypeMention constraint
) {
potentialInstantiationOf0(ce, abs, constraint) and
if abs.(Impl).hasTrait()
Expand All @@ -2353,14 +2349,13 @@ private module MethodResolution {
else any()
}

predicate relevantConstraint(TypeMentionTypeTree constraint) {
predicate relevantConstraint(TypeMention constraint) {
potentialInstantiationOf0(_, _, constraint)
}
}

private module TypeQualifierIsInstantiationOfImplSelf =
IsInstantiationOf<MethodCallCallExpr, TypeMentionTypeTree,
TypeQualifierIsInstantiationOfImplSelfInput>;
IsInstantiationOf<MethodCallCallExpr, TypeMention, TypeQualifierIsInstantiationOfImplSelfInput>;

/**
* A configuration for anti-matching the type of a receiver against the type of
Expand Down Expand Up @@ -2481,7 +2476,7 @@ private module MethodCallMatchingInput implements MatchingWithEnvironmentInputSi
.getGenericArgList()
.getTypeArg(apos.asMethodTypeArgumentPosition())
.(TypeMention)
.resolveTypeAt(path)
.getTypeAt(path)
or
result = getCallExprTypeArgument(this, apos, path)
}
Expand Down Expand Up @@ -3012,7 +3007,7 @@ abstract private class TupleLikeConstructor extends Addressable {
}

Type getParameterType(FunctionPosition pos, TypePath path) {
result = this.getTupleField(pos.asPosition()).getTypeRepr().(TypeMention).resolveTypeAt(path)
result = this.getTupleField(pos.asPosition()).getTypeRepr().(TypeMention).getTypeAt(path)
}
}

Expand Down Expand Up @@ -3367,7 +3362,7 @@ private module FieldExprMatchingInput implements MatchingInputSig {
)
or
dpos.isField() and
result = this.getTypeRepr().(TypeMention).resolveTypeAt(path)
result = this.getTypeRepr().(TypeMention).getTypeAt(path)
}

override string toString() { result = this.getAstNode().toString() }
Expand Down Expand Up @@ -3719,7 +3714,7 @@ private module StructPatMatchingInput implements MatchingInputSig {
// The struct/enum type is supplied explicitly as a type qualifier, e.g.
// `let Foo<Bar>::Variant { ... } = ...`.
apos.isStructPos() and
result = this.getPath().(TypeMention).resolveTypeAt(path)
result = this.getPath().(TypeMention).getTypeAt(path)
}

Declaration getTarget() { result = resolvePath(this.getPath()) }
Expand Down Expand Up @@ -3769,7 +3764,7 @@ private module TupleStructPatMatchingInput implements MatchingInputSig {
// The struct/enum type is supplied explicitly as a type qualifier, e.g.
// `let Option::<Foo>::Some(x) = ...`.
apos.isSelf() and
result = this.getPath().(TypeMention).resolveTypeAt(path)
result = this.getPath().(TypeMention).getTypeAt(path)
}

Declaration getTarget() { result = resolvePath(this.getPath()) }
Expand Down Expand Up @@ -3958,13 +3953,13 @@ private Type inferClosureExprType(AstNode n, TypePath path) {
or
// Propagate return type annotation to body
n = ce.getClosureBody() and
result = ce.getRetType().getTypeRepr().(TypeMention).resolveTypeAt(path)
result = ce.getRetType().getTypeRepr().(TypeMention).getTypeAt(path)
)
}

pragma[nomagic]
private Type inferCastExprType(CastExpr ce, TypePath path) {
result = ce.getTypeRepr().(TypeMention).resolveTypeAt(path)
result = ce.getTypeRepr().(TypeMention).getTypeAt(path)
}

cached
Expand Down Expand Up @@ -4162,7 +4157,7 @@ private module Debug {

predicate debugInferShorthandSelfType(ShorthandSelfParameterMention self, TypePath path, Type t) {
self = getRelevantLocatable() and
t = self.resolveTypeAt(path)
t = self.getTypeAt(path)
}

predicate debugInferMethodCallType(AstNode n, TypePath path, Type t) {
Expand All @@ -4177,7 +4172,7 @@ private module Debug {

predicate debugTypeMention(TypeMention tm, TypePath path, Type type) {
tm = getRelevantLocatable() and
tm.resolveTypeAt(path) = type
tm.getTypeAt(path) = type
}

Type debugInferAnnotatedType(AstNode n, TypePath path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ query predicate illFormedTypeMention(TypeMention tm) {
not tm =
any(PathTypeMention ptm |
exists(ptm.resolvePathTypeAt(TypePath::nil())) and
not exists(ptm.resolveType())
not exists(ptm.getType())
or
ptm.(NonAliasPathTypeMention).getResolved() instanceof TypeAlias
) and
Expand Down
Loading
Loading