Skip to content

Conversation

@N1ark
Copy link
Contributor

@N1ark N1ark commented Dec 19, 2025

Fixes #170

Use the patricia-tree where possible. Unfortunately, there are a few places where we use hashconsed values over Hashtbl/Hashset, which Patricia_tree doesn't have an equivalent for.

For where we used maps/sets I still did the switch; most notably:

  • Var.Map/Var.Set
  • the analyses in Bv_solver and C_solver
  • the tag map in Tree_borrow

Benchmarks:

  • Collections-C x 10: 1.746s ± 0.045s --> 1.711s ± 0.036s, -2%
  • Miri+Kani: 97.68s --> 96.74s, -1%
  • Micro-benchmark Rust: 1.25G cycles --> 810.40M cycles, -54%
    This one is over 50132 executions of Rtree_block.Make.MemVal.merge, which itself calls Tree_borrow.merge, which merges two integer maps. The new implementation uses idempotent_union, which is faster as it reuses subtrees

@N1ark N1ark requested a review from giltho as a code owner December 19, 2025 12:05
@N1ark N1ark added the performance Issues relating to performance improvements label Dec 20, 2025
Copy link
Contributor

@giltho giltho left a comment

Choose a reason for hiding this comment

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

Looks good, though I'd also expose a way of doing States.PMap with patricia trees as well

let v2, st = get_or_make v2 st in
merge v1 v2 st;
(* Here we choose to pass down the equality (rather than simplifying to true),
so that the underlying solver can do trivial SAT checks using these equalities.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should "trivial_truthiness" go through analyses? It would avoid that problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's done in #208 hehe! though i dont think i removed this there so when you review it pls add a comment to remind me

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any modifications of trivial_truthiness in #208?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh i misread that ! was thinking of the trivial_model_check or whatever it's called (better names needed maybe)

it's already handled in the trivial_truthiness, since here https://github.com/soteria-tools/soteria/blob/disjoint-analysis/soteria/lib/bv_values/bv_solver.ml#L21 it calls the fallback, which is analyses.simplify!

reallyyyy what we want is that BvSolver's PC is an analysis itself i think, which is at the bottom of the stack and for which:

  • add_constraint... adds the constraint
  • simplify checks the PC for a value and its negation
    i think that would be quite elegant :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

regardless of that change though this comment should go and i can now return true for equalities !!! so yayyy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will update tmw

@N1ark
Copy link
Contributor Author

N1ark commented Dec 26, 2025

yup will do tmw

@giltho
Copy link
Contributor

giltho commented Dec 27, 2025

I believe this is ready to be merged as soon as you add Patricia trees for states then?
Or before and you do a separate PR up to you

@N1ark
Copy link
Contributor Author

N1ark commented Dec 27, 2025

can you actually just check the PR f83778d

like it works but i am not super super convinced of how I did it so I'd like your opinion

@giltho
Copy link
Contributor

giltho commented Dec 27, 2025

About to go to sleep and skiing tomorrow so I can't postpone sleep, but will do tomorrow!

I had a very very quick look and saw you have S_PatriciaTree instead of S_patricia_tee somewhere :p

@N1ark N1ark added this pull request to the merge queue Dec 29, 2025
Merged via the queue into main with commit 09cb89d Dec 29, 2025
2 checks passed
@N1ark N1ark deleted the patricia-optims branch December 29, 2025 18:13
pcarrott pushed a commit that referenced this pull request Dec 30, 2025
* Use `Bimap` in `Fun_ctx`

* Use Patricia trees where possible

* Ignore failures in soteria-c `--benchmark`

* Update shell.nix

* Patricia trees of values

* Tentative: add `Patricia_tree` to `pmap`

* `Typo_in_module_name` :P

* drive-by: Nicer frontend error message

* Unexpose some `PMap` stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Issues relating to performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use patricia trees wherever we have hashconsed values

3 participants