Skip to content

Generalize Uniqueness Analysis to arbitrary semirings #3280

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

anfelor
Copy link
Contributor

@anfelor anfelor commented Nov 15, 2024

This PR contains a proposed refactoring of uniqueness_analysis.ml. I have added it at @riaqn's request so that we don't lose track of this code. Ignore most of the diff: all the relevant changes are to uniqueness_analysis.ml in commits 255f533 and 4d69a80.

The refactoring reimagines the uniqueness analysis as a data flow analysis over arbitrary semirings. That makes it potentially much more useful in the future as any data that attaches to memory locations and is semiring-shaped can be collected in this analysis. Here is an overview over the changes:

  • I remove the usage information from Usage_tree, Usage_forest and Paths. Instead, these are now generic datastructures that can hold arbitrary elements. I push them to the top of the file since the concept of "memory location mapped to data" can be understood without thinking about usages at all.
  • I introduce a general functor for semirings and for "promotable" semirings that can live in trees. You can form the product of such semirings. Trees and forests over a promotable semiring are again semirings.
  • The code for usages is largely unchanged. There is an unrelated change adding an access_order to errors for better error messages, but other than that, the only change is that I make Usage a promotable semiring.
  • There are modules Tag, Learned_tags and Overwrites which are related to the overwriting extension and can be ignored. These are promotable semirings as well.
  • I use two different semirings for patterns and expressions. Patterns yield a PF.t which is a forest semiring that contains usages and learned tags, while expressions yield a UF.t which is a forest semiring that contains usages and overwrites.This makes it type-safe to combine learned tags with overwrites (split_pf, learn_tags).
  • The rest of the file only contains changes that follow directly from the design above.

goldfirere and others added 30 commits October 4, 2024 15:07
* Basic overwriting syntax

* Update line numbers in expect tests after cherry-pick

* Implement suggestions

* Update tests

* Implement suggestions

* Remove nested quotes

* Revert "Remove nested quotes"

This reverts commit 72eaa04.
* Propagate unique_barrier through typing/ (broken commit since lambda/ untouched)

* Map unique_barrier to Reads_vary

* Propagate unique_barrier into matching.ml

* Add pat_unique_barrier to chamelon

* Add pat_unique_barrier to chamelon (2)

* Fix formatting

* Refactor

* Use Uniqueness.lr, without a ref.

* Update comment in typing/uniqueness_analysis.ml

as suggested by @goldfirere

Co-authored-by: Richard Eisenberg <rae@richarde.dev>

* Address review comments

* Enable unique barrier for exception patterns

* Address comments

* Implement suggestion

* Add tests

* Add comment to pat_unique_barrier

---------

Co-authored-by: Richard Eisenberg <reisenberg@janestreet.com>
Co-authored-by: Richard Eisenberg <rae@richarde.dev>
* Tests for overwriting

* Remove old tests for unique overwrites and fix typos

* Add overwriting tests back

* Add tests for lifting out constants

* Update tests

* Use extension universe alpha

* Test all cases for gc soundness bug

* Review feedback: add more CRs and clarify overwriting_map.ml

* Review feedback: Add allocation counter to rbtree

* Review feedback: also test mixed blocks and unboxed float blocks in the lift constants test

* Review feedback: as discussed in meeting

* Review feedback
Co-authored-by: Richard Eisenberg <rae@richarde.dev>
Co-authored-by: Richard Eisenberg <rae@richarde.dev>
Co-authored-by: Richard Eisenberg <rae@richarde.dev>
@anfelor anfelor requested a review from riaqn November 15, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants