C++: Speed up "Declaration hides parameter"

Bad magic ended up in `LocalVariable.getFunction` and effectively
created a Cartesian product. Before this change, the timing looked like
this:

    Variable::LocalVariable::getFunction_dispred#bb ... 50.1s
    #select#cpe#123#fff ............................... 20.6s

After this change, those predicates become much faster:

    Variable::LocalVariable::getFunction_dispred#ff ... 121ms
    DeclarationHidesParameter::localVariableNames#fff . 77ms
    #select#cpe#123#fff ............................... 28ms

Introducing the predicate `localVariableNames` ensures that we can do
the main join on two columns simultaneously, so that's a change we
should keep even if we remove the `pragma[nomagic]` later.
This commit is contained in:
Jonas Jensen
2019-01-11 11:06:18 +01:00
parent 8a435ae321
commit 2268f1fee6

View File

@@ -28,9 +28,15 @@ ParameterDeclarationEntry functionParameterNames(Function f, string name) {
)
}
from Function f, LocalVariable lv, ParameterDeclarationEntry pde
pragma[nomagic]
LocalVariable localVariableNames(Function f, string name) {
name = result.getName() and
f = result.getFunction()
}
from Function f, LocalVariable lv, ParameterDeclarationEntry pde, string name
where
f = lv.getFunction() and
pde = functionParameterNames(f, lv.getName()) and
lv = localVariableNames(f, name) and
pde = functionParameterNames(f, name) and
not lv.isInMacroExpansion()
select lv, "Local variable '" + lv.getName() + "' hides a $@.", pde, "parameter of the same name"