Skip to content

Commit

Permalink
Use a set to track callable candidates.
Browse files Browse the repository at this point in the history
We don't the instance key that produces the callable right now.
  • Loading branch information
khatchad committed Jul 21, 2024
1 parent 9574624 commit 5fe2b79
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
import com.ibm.wala.util.collections.HashMapFactory;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.intset.OrdinalSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

public class PythonInstanceMethodTrampolineTargetSelector<T>
Expand Down Expand Up @@ -223,7 +224,8 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr
PointerKey receiver = pkf.getPointerKeyForLocal(caller, call.getUse(0));
OrdinalSet<InstanceKey> objs = builder.getPointerAnalysis().getPointsToSet(receiver);

Map<InstanceKey, IClass> instanceToCallable = new HashMap<>();
// The set of potential callables to be returned.
Set<IClass> callableSet = new HashSet<>();

for (InstanceKey o : objs) {
AllocationSiteInNode instanceKey = getAllocationSiteInNode(o);
Expand Down Expand Up @@ -256,28 +258,21 @@ private IClass getCallable(CGNode caller, IClassHierarchy cha, PythonInvokeInstr
LOGGER.info("Applying callable workaround for https://github.com/wala/ML/issues/118.");
}

if (callable != null) {
if (instanceToCallable.containsKey(instanceKey))
throw new IllegalStateException("Exisitng mapping found for: " + instanceKey);

IClass previousValue = instanceToCallable.put(instanceKey, callable);
assert previousValue == null : "Not expecting a previous mapping.";
}
callableSet.add(callable);
}
}

// if there's only one possible option.
if (instanceToCallable.values().size() == 1) {
IClass callable = instanceToCallable.values().iterator().next();
if (callableSet.size() == 1) {
IClass callable = callableSet.iterator().next();
assert callable != null : "Callable should be non-null.";
return callable;
}

// if we have multiple candidates.
if (instanceToCallable.values().size() > 1)
if (callableSet.size() > 1)
// we cannot accurately select one.
LOGGER.warning(
"Multiple (" + instanceToCallable.values().size() + ") callable targets found.");
LOGGER.warning("Multiple (" + callableSet.size() + ") callable targets found.");

return null;
}
Expand Down

0 comments on commit 5fe2b79

Please sign in to comment.