ruby/python: remove predicates from interface

This commit is contained in:
Rasmus Lerchedahl Petersen
2023-06-07 14:07:08 +02:00
parent 7ab3cde3aa
commit 6ddf1f7eaf
4 changed files with 54 additions and 63 deletions

View File

@@ -1,10 +1,10 @@
/** /**
* Provides the implementation of a summary type tracker, that is type tracking through flow summaries. * Provides the implementation of type tracking steps through flow summaries.
* To use this, you must implement the `Input` signature. You can then use the predicates in the `Output` * To use this, you must implement the `Input` signature. You can then use the predicates in the `Output`
* signature to implement the predicates of the same names inside `TypeTrackerSpecific.qll`. * signature to implement the predicates of the same names inside `TypeTrackerSpecific.qll`.
*/ */
/** The classes and predicates needed to generate a summary type tracker. */ /** The classes and predicates needed to generate type-tracking steps from summaries. */
signature module Input { signature module Input {
// Dataflow nodes // Dataflow nodes
class Node; class Node;
@@ -80,13 +80,6 @@ signature module Input {
/** Gets a dataflow node respresenting the return of `callable` indicated by `return`. */ /** Gets a dataflow node respresenting the return of `callable` indicated by `return`. */
Node returnOf(Node callable, SummaryComponent return); Node returnOf(Node callable, SummaryComponent return);
// Specific summary handling
/** Holds if component should be treated as a level step by type tracking. */
predicate componentLevelStep(SummaryComponent component);
/** Holds if the given component can't be evaluated by `evaluateSummaryComponentStackLocal`. */
predicate isNonLocal(SummaryComponent component);
// Relating callables to nodes // Relating callables to nodes
/** Gets a dataflow node respresenting a call to `callable`. */ /** Gets a dataflow node respresenting a call to `callable`. */
Node callTo(SummarizedCallable callable); Node callTo(SummarizedCallable callable);
@@ -146,8 +139,8 @@ module SummaryFlow<Input I> implements Output<I> {
I::SummaryComponentStack output I::SummaryComponentStack output
) { ) {
callable.propagatesFlow(I::push(I::content(contents), input), output, true) and callable.propagatesFlow(I::push(I::content(contents), input), output, true) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) not isNonLocal(output.head())
} }
pragma[nomagic] pragma[nomagic]
@@ -155,8 +148,8 @@ module SummaryFlow<Input I> implements Output<I> {
I::SummarizedCallable callable, I::TypeTrackerContent contents, I::SummaryComponentStack input, I::SummarizedCallable callable, I::TypeTrackerContent contents, I::SummaryComponentStack input,
I::SummaryComponentStack output I::SummaryComponentStack output
) { ) {
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) and not isNonLocal(output.head()) and
( (
callable.propagatesFlow(input, I::push(I::content(contents), output), true) callable.propagatesFlow(input, I::push(I::content(contents), output), true)
or or
@@ -178,8 +171,8 @@ module SummaryFlow<Input I> implements Output<I> {
callable callable
.propagatesFlow(I::push(I::content(loadContents), input), .propagatesFlow(I::push(I::content(loadContents), input),
I::push(I::content(storeContents), output), true) and I::push(I::content(storeContents), output), true) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) not isNonLocal(output.head())
} }
pragma[nomagic] pragma[nomagic]
@@ -190,8 +183,8 @@ module SummaryFlow<Input I> implements Output<I> {
exists(I::TypeTrackerContent content | exists(I::TypeTrackerContent content |
callable.propagatesFlow(I::push(I::withoutContent(content), input), output, true) and callable.propagatesFlow(I::push(I::withoutContent(content), input), output, true) and
filter = I::getFilterFromWithoutContentStep(content) and filter = I::getFilterFromWithoutContentStep(content) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) and not isNonLocal(output.head()) and
input != output input != output
) )
} }
@@ -204,12 +197,26 @@ module SummaryFlow<Input I> implements Output<I> {
exists(I::TypeTrackerContent content | exists(I::TypeTrackerContent content |
callable.propagatesFlow(I::push(I::withContent(content), input), output, true) and callable.propagatesFlow(I::push(I::withContent(content), input), output, true) and
filter = I::getFilterFromWithContentStep(content) and filter = I::getFilterFromWithContentStep(content) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) and not isNonLocal(output.head()) and
input != output input != output
) )
} }
private predicate componentLevelStep(I::SummaryComponent component) {
exists(I::TypeTrackerContent content |
component = I::withoutContent(content) and
not exists(I::getFilterFromWithoutContentStep(content))
)
}
pragma[nomagic]
private predicate isNonLocal(I::SummaryComponent component) {
component = I::content(_)
or
component = I::withContent(_)
}
/** /**
* Gets a data flow I::Node corresponding an argument or return value of `call`, * Gets a data flow I::Node corresponding an argument or return value of `call`,
* as specified by `component`. * as specified by `component`.
@@ -255,7 +262,7 @@ module SummaryFlow<Input I> implements Output<I> {
I::SummarizedCallable callable, I::SummaryComponent head, I::SummaryComponentStack tail I::SummarizedCallable callable, I::SummaryComponent head, I::SummaryComponentStack tail
) { ) {
dependsOnSummaryComponentStackCons(callable, head, tail) and dependsOnSummaryComponentStackCons(callable, head, tail) and
not I::isNonLocal(head) not isNonLocal(head)
} }
pragma[nomagic] pragma[nomagic]
@@ -290,7 +297,7 @@ module SummaryFlow<Input I> implements Output<I> {
or or
result = I::returnOf(prev, head) result = I::returnOf(prev, head)
or or
I::componentLevelStep(head) and componentLevelStep(head) and
result = prev result = prev
) )
} }

View File

@@ -255,14 +255,6 @@ module SummaryTypeTrackerInput implements SummaryTypeTracker::Input {
callable.getALocalSource().asExpr().(CallableExpr).getInnerScope().getAReturnValueFlowNode() callable.getALocalSource().asExpr().(CallableExpr).getInnerScope().getAReturnValueFlowNode()
} }
// Specific summary handling
predicate componentLevelStep(SummaryComponent component) { none() }
pragma[nomagic]
predicate isNonLocal(SummaryComponent component) {
component = FlowSummary::SummaryComponent::content(_)
}
// Relating callables to nodes // Relating callables to nodes
Node callTo(SummarizedCallable callable) { result = callable.getACallSimple() } Node callTo(SummarizedCallable callable) { result = callable.getACallSimple() }
} }

View File

@@ -80,13 +80,6 @@ signature module Input {
/** Gets a dataflow node respresenting the return of `callable` indicated by `return`. */ /** Gets a dataflow node respresenting the return of `callable` indicated by `return`. */
Node returnOf(Node callable, SummaryComponent return); Node returnOf(Node callable, SummaryComponent return);
// Specific summary handling
/** Holds if component should be treated as a level step by type tracking. */
predicate componentLevelStep(SummaryComponent component);
/** Holds if the given component can't be evaluated by `evaluateSummaryComponentStackLocal`. */
predicate isNonLocal(SummaryComponent component);
// Relating callables to nodes // Relating callables to nodes
/** Gets a dataflow node respresenting a call to `callable`. */ /** Gets a dataflow node respresenting a call to `callable`. */
Node callTo(SummarizedCallable callable); Node callTo(SummarizedCallable callable);
@@ -146,8 +139,8 @@ module SummaryFlow<Input I> implements Output<I> {
I::SummaryComponentStack output I::SummaryComponentStack output
) { ) {
callable.propagatesFlow(I::push(I::content(contents), input), output, true) and callable.propagatesFlow(I::push(I::content(contents), input), output, true) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) not isNonLocal(output.head())
} }
pragma[nomagic] pragma[nomagic]
@@ -155,8 +148,8 @@ module SummaryFlow<Input I> implements Output<I> {
I::SummarizedCallable callable, I::TypeTrackerContent contents, I::SummaryComponentStack input, I::SummarizedCallable callable, I::TypeTrackerContent contents, I::SummaryComponentStack input,
I::SummaryComponentStack output I::SummaryComponentStack output
) { ) {
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) and not isNonLocal(output.head()) and
( (
callable.propagatesFlow(input, I::push(I::content(contents), output), true) callable.propagatesFlow(input, I::push(I::content(contents), output), true)
or or
@@ -178,8 +171,8 @@ module SummaryFlow<Input I> implements Output<I> {
callable callable
.propagatesFlow(I::push(I::content(loadContents), input), .propagatesFlow(I::push(I::content(loadContents), input),
I::push(I::content(storeContents), output), true) and I::push(I::content(storeContents), output), true) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) not isNonLocal(output.head())
} }
pragma[nomagic] pragma[nomagic]
@@ -190,8 +183,8 @@ module SummaryFlow<Input I> implements Output<I> {
exists(I::TypeTrackerContent content | exists(I::TypeTrackerContent content |
callable.propagatesFlow(I::push(I::withoutContent(content), input), output, true) and callable.propagatesFlow(I::push(I::withoutContent(content), input), output, true) and
filter = I::getFilterFromWithoutContentStep(content) and filter = I::getFilterFromWithoutContentStep(content) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) and not isNonLocal(output.head()) and
input != output input != output
) )
} }
@@ -204,12 +197,26 @@ module SummaryFlow<Input I> implements Output<I> {
exists(I::TypeTrackerContent content | exists(I::TypeTrackerContent content |
callable.propagatesFlow(I::push(I::withContent(content), input), output, true) and callable.propagatesFlow(I::push(I::withContent(content), input), output, true) and
filter = I::getFilterFromWithContentStep(content) and filter = I::getFilterFromWithContentStep(content) and
not I::isNonLocal(input.head()) and not isNonLocal(input.head()) and
not I::isNonLocal(output.head()) and not isNonLocal(output.head()) and
input != output input != output
) )
} }
private predicate componentLevelStep(I::SummaryComponent component) {
exists(I::TypeTrackerContent content |
component = I::withoutContent(content) and
not exists(I::getFilterFromWithoutContentStep(content))
)
}
pragma[nomagic]
private predicate isNonLocal(I::SummaryComponent component) {
component = I::content(_)
or
component = I::withContent(_)
}
/** /**
* Gets a data flow I::Node corresponding an argument or return value of `call`, * Gets a data flow I::Node corresponding an argument or return value of `call`,
* as specified by `component`. * as specified by `component`.
@@ -255,7 +262,7 @@ module SummaryFlow<Input I> implements Output<I> {
I::SummarizedCallable callable, I::SummaryComponent head, I::SummaryComponentStack tail I::SummarizedCallable callable, I::SummaryComponent head, I::SummaryComponentStack tail
) { ) {
dependsOnSummaryComponentStackCons(callable, head, tail) and dependsOnSummaryComponentStackCons(callable, head, tail) and
not I::isNonLocal(head) not isNonLocal(head)
} }
pragma[nomagic] pragma[nomagic]
@@ -290,7 +297,7 @@ module SummaryFlow<Input I> implements Output<I> {
or or
result = I::returnOf(prev, head) result = I::returnOf(prev, head)
or or
I::componentLevelStep(head) and componentLevelStep(head) and
result = prev result = prev
) )
} }

View File

@@ -467,21 +467,6 @@ module SummaryTypeTrackerInput implements SummaryTypeTracker::Input {
) )
} }
// Specific summary handling
predicate componentLevelStep(SummaryComponent component) {
exists(TypeTrackerContent content |
component = SummaryComponent::withoutContent(content) and
not exists(getFilterFromWithoutContentStep(content))
)
}
pragma[nomagic]
predicate isNonLocal(SummaryComponent component) {
component = SC::content(_)
or
component = SC::withContent(_)
}
// Relating callables to nodes // Relating callables to nodes
Node callTo(SummarizedCallable callable) { result.asExpr().getExpr() = callable.getACallSimple() } Node callTo(SummarizedCallable callable) { result.asExpr().getExpr() = callable.getACallSimple() }
} }