From 73fd66cfed7083e334983df6fecdc18e50c87f34 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Tue, 12 Oct 2021 16:19:43 +0200 Subject: [PATCH] Python: Cache `TypeBackTracker::prepend` --- .../dataflow/new/internal/TypeTracker.qll | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll b/python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll index 6ced6a8206e..50452012213 100644 --- a/python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll +++ b/python/ql/lib/semmle/python/dataflow/new/internal/TypeTracker.qll @@ -52,6 +52,24 @@ private module Cached { ) } + /** Gets the summary resulting from prepending `step` to this type-tracking summary. */ + cached + TypeBackTracker prepend(TypeBackTracker tbt, StepSummary step) { + exists(Boolean hasReturn, string content | tbt = MkTypeBackTracker(hasReturn, content) | + step = LevelStep() and result = tbt + or + step = CallStep() and hasReturn = false and result = tbt + or + step = ReturnStep() and result = MkTypeBackTracker(true, content) + or + exists(string p | + step = LoadStep(p) and content = "" and result = MkTypeBackTracker(hasReturn, p) + ) + or + step = StoreStep(content) and result = MkTypeBackTracker(hasReturn, "") + ) + } + /** * Gets the summary that corresponds to having taken a forwards * heap and/or intra-procedural step from `nodeFrom` to `nodeTo`. @@ -365,19 +383,7 @@ class TypeBackTracker extends TTypeBackTracker { TypeBackTracker() { this = MkTypeBackTracker(hasReturn, content) } /** Gets the summary resulting from prepending `step` to this type-tracking summary. */ - TypeBackTracker prepend(StepSummary step) { - step = LevelStep() and result = this - or - step = CallStep() and hasReturn = false and result = this - or - step = ReturnStep() and result = MkTypeBackTracker(true, content) - or - exists(string p | - step = LoadStep(p) and content = "" and result = MkTypeBackTracker(hasReturn, p) - ) - or - step = StoreStep(content) and result = MkTypeBackTracker(hasReturn, "") - } + TypeBackTracker prepend(StepSummary step) { result = prepend(this, step) } /** Gets a textual representation of this summary. */ string toString() {