Skip to content

Zero alloc: don't loose witnesses #2353

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 12 commits into from

Conversation

gretay-js
Copy link
Contributor

There is a mismatch in handling witnesses: V.lessequal ignores them and V.join does not. As a result, witnesses discovered in the last iteration of a fixed point computation might be lost, if there are already other witnesses for the same component.
The analysis uses V.lessequal new_value value to detect fixed points and will not join the new_value to the preiously computed value if the only difference is in witnesses.

This is not a soundness problem in the sense that the check will not miss allocations, but it might not return all allocations as witnesses. We do not guarantee that all witnesses will be reported, but it is a nice property to have. We rely on the witnesses produced by the analysis to visualize allocations and not only to check annotations. Having consistent output also makes testing easier.

This PR fixes it "properly" by taking witnesses into account in V.lessequal and refactoring some other witness related checks to make it clear that we are allowed to ignore witnesses of "expected" values that come from annotations, and not the computed values. The downside of this approach is that the fixpoint can take longer: the height of the abstract domain now depends on the size of the input file in the worst case, instead of being constant height of 3. I think that the bad case cannot happen in practice because of the order or propagation of witnesses along all the control flow paths within a loop before checking for a fixed point.

An alternative is to call join even when lessequal is true. It works too but feels like a hack.

For example, the output of existing test fail19.ml changes depending on the order in which functions are emitted in the file: -function-layout topological includes probe witness and with the source layout it doesn't. This happens because the fixpoint for "forward defined" functions discovered a new witness but the value was already Top, so the new witness is not recorded. I haven't found a way to reproduce this on main yet.

On top of #2290.

gretay-js added 12 commits March 7, 2024 10:05
This allows us to get rid of a lot of machinery for tracking and
resolving unresolved depedencies. Conservative on functions that have
mutually recursive calls or forward calls.
1) Keep unresolved functions around until the end of the compilation unit
2) Naively compute fixed point at the end of the unit
t.approx should only be used for self rec that has no other unresolved
dependencies.
Pass [keep_witnesses ] as an argument to [Analysis.create] instead of
using default initial value and mutating it later.
Copy link
Contributor

@xclerc xclerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an idea of the size of the
witness sets in practice? With the
comparision over the domain now
possibly involving an inclusion test,
the cost could increase significantly.

@gretay-js
Copy link
Contributor Author

Do we have an idea of the size of the witness sets in practice? With the comparision over the domain now possibly involving an inclusion test, the cost could increase significantly.

I am collecting some statistics on this RP and it's baseline #2290.

@gretay-js
Copy link
Contributor Author

I messed up the repo/branch in this PR, sorry. I am closing this in favor of #2354 to reduce the confusion. We can continue the discussion there.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants