This is an archive of the discontinued LLVM Phabricator instance.

Expose DataflowAnalysisContext.querySolver().
ClosedPublic

Authored by bazuzi on Jun 26 2023, 12:20 PM.

Details

Summary

This allows for use of the same solver used by the DAC for additional solving post-analysis and thus shared use of MaxIterations in WatchedLiteralsSolver.

Diff Detail

Event Timeline

bazuzi created this revision.Jun 26 2023, 12:20 PM
Herald added a project: Restricted Project. · View Herald Transcript
bazuzi requested review of this revision.Jun 26 2023, 12:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2023, 12:20 PM
ymandel accepted this revision.Jun 26 2023, 12:30 PM
ymandel added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
179–182

nit: Given that these are options of Solver::Result, I think you can just delete these lines.

This revision is now accepted and ready to land.Jun 26 2023, 12:30 PM
bazuzi updated this revision to Diff 536269.Jun 30 2023, 8:32 AM

Updated function comment to remove unnecessary repetition and include newly-discovered caveat re: flow conditions.

bazuzi marked an inline comment as done.Jun 30 2023, 8:33 AM
sammccall accepted this revision.Jun 30 2023, 9:25 AM

Thanks!

As discussed offline, I had some concerns about whether there were any cases where it was safe to use formulas separate from the FC that might constrain them.
But we found some: these are formulas produced by the downstream analysis that have known structure.

clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
184

FWIW, I'd probably prefer exposing the solver object itself, having all capabilities exposed directly through DataflowAnalysisContext gives it this ugly "god object" quality and the places that we want to use it really just need arena + solver.

184

this should be ArrayRef<BoolValue*> now... sorry for the churn

bazuzi updated this revision to Diff 536293.Jun 30 2023, 9:38 AM

Rebase on main to pull in change from DenseSet to SetVector.

sammccall added inline comments.Jun 30 2023, 9:42 AM
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
184

I do think ArrayRef is the right signature here - SetVector is a slightly messy impl detail.

This would mean an unfortunate copy for now but that will go away, see D153485 (which is waiting on the Formula patch to land)

bazuzi added inline comments.Jun 30 2023, 9:51 AM
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
184

HEAD says SetVector, so updated to that. Is there another change coming that makes it ArrayRef?

184

If all capabilities was more than 1 capability and this function didn't already exist, I'd me more inclined to agree. But requiring users to duplicate the body of this function seems worse to me than forwarding an API from a member.

I'm noticing as well that the body of this function adds true and !false constraints to the provided set, which I hadn't been doing when using a solver and for which I can find no documentation indicating that it's necessary. Either we should document why that's done and would need to expect users to know to do it if we expose the solver only directly, or we should remove that from this function.

gribozavr2 accepted this revision.Jun 30 2023, 9:52 AM
gribozavr2 added inline comments.
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
184

@sammccall
While I'd normally agree, querySolver() incorporates the true and false literals into the formula, so it is actually a lot more useful than the raw solver object. Until we have a different representation of boolean literals, I think this patch is the better in terms of API design.

LG as is, sorry for the noise!

clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
184

The public APIs for "set of constraints" are ArrayRef (on Solver::solve).
SetVector was how we maintained determinism while deduplicating inside DACtx, this function is SetVector specifically because it was private.

Nevertheless, let's go with this change as-is, the alternatives are complicated for now.
I'll try to simplify the API a bit once the prereqs are in place.

184

Either we should document why that's done and would need to expect users to know to do it if we expose the solver only directly, or we should remove that from this function.

I'll just eliminate the requirement to do so at all, soon.

It looks like D153485 changes the context for the last few comments significantly. What's the appetite for adding yet another child commit to the chain D153485 is in that exposes the solver directly? Instead of committing this and having D153485 make a breaking change to expose the solver directly if that's better in the new context.

It looks like D153485 changes the context for the last few comments significantly. What's the appetite for adding yet another child commit to the chain D153485 is in that exposes the solver directly? Instead of committing this and having D153485 make a breaking change to expose the solver directly if that's better in the new context.

Yeah, that's fewer steps but more stuff stacked on top.
I don't feel strongly - happy to make that change later if you'd like to have this available now.

Since the timeline for being able to use this is dependent not only on commits but integrates as well, lets go ahead with this then.

Can someone commit it for me when we're ready?

This revision was landed with ongoing or failed builds.Jun 30 2023, 3:15 PM
This revision was automatically updated to reflect the committed changes.