Skip to content

Commit d2113f1

Browse files
committed
More performance stuff. (Possibly not all needed.)
1 parent 11ceaf3 commit d2113f1

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

python/ql/src/analysis/DefinitionTracking.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,18 @@ private predicate method_callsite_defn(MethodCallsiteRefinement def, Definition
229229
pragma [noinline]
230230
private predicate module_and_name_for_import_star(ModuleObject mod, string name, ImportStarRefinement def) {
231231
exists(ImportStarNode im_star |
232-
im_star = def.getDefiningNode() |
233-
name = def.getSourceVariable().getName() and
234-
im_star.getModule().refersTo(mod) and
232+
module_and_name_for_import_star_helper(mod, name, im_star, def) and
235233
mod.exports(name)
236234
)
237235
}
238236

239-
/** Holds if `def` is technically a defn of `var`, but the `from ... import *` does not in fact define `var` */
237+
pragma [noinline]
238+
private predicate module_and_name_for_import_star_helper(ModuleObject mod, string name, ImportStarNode im_star, ImportStarRefinement def) {
239+
im_star = def.getDefiningNode() and
240+
im_star.getModule().refersTo(mod) and
241+
name = def.getSourceVariable().getName()
242+
}
243+
/** Holds if `def` is technically a defn of `var`, but the `from ... import *` does not in fact define `var` */
240244
pragma [noinline]
241245
private predicate variable_not_redefined_by_import_star(EssaVariable var, ImportStarRefinement def) {
242246
var = def.getInput() and

python/ql/src/semmle/python/pointsto/PointsTo.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,18 @@ private module InterModulePointsTo {
667667
pragma [noinline]
668668
private EssaVariable ssa_variable_for_module_attribute(ImportMemberNode f, PointsToContext context) {
669669
exists(string name, ModuleObjectInternal mod, Module m |
670-
mod.getSourceModule() = m and m = f.getEnclosingModule() and m = result.getScope() and
670+
mod.getSourceModule() = m and m = result.getScope() and
671671
PointsToInternal::pointsTo(f.getModule(name), context, mod, _) and
672-
result.getSourceVariable().getName() = name and result.getAUse() = f
672+
result = ssa_helper(f, name, m)
673673
)
674674
}
675675

676+
pragma [noinline]
677+
private EssaVariable ssa_helper(ImportMemberNode f, string name, Module m) {
678+
result.getSourceVariable().getName() = name and result.getAUse() = f
679+
and m = f.getEnclosingModule()
680+
}
681+
676682
/* Helper for implicit_submodule_points_to */
677683
private ModuleObjectInternal getModule(ImplicitSubModuleDefinition def) {
678684
exists(PackageObjectInternal package |

python/ql/src/semmle/python/types/Extensions.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ class ReModulePointToExtension extends PointsToExtension {
142142
sre_constants.attribute("SRE_FLAG_" + name, value, orig) and
143143
origin = orig.asCfgNodeOrHere(this)
144144
)
145-
and context.appliesTo(this)
145+
and pointsTo_helper(context)
146+
}
147+
148+
pragma [noinline]
149+
predicate pointsTo_helper(Context context) {
150+
context.appliesTo(this)
146151
}
147152

148153
}

0 commit comments

Comments
 (0)