Skip to content
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

Lattice support #2438

Merged
merged 20 commits into from
Nov 15, 2023
Merged

Lattice support #2438

merged 20 commits into from
Nov 15, 2023

Conversation

julienhenry
Copy link
Member

@julienhenry julienhenry commented Nov 9, 2023

This PR implements support for lattice elements in Soufflé, in a similar way as the Flix language (see https://flix.dev/ and in particular this paper )

Given a type named myType declared with .type myType = ..., one can now attach a lattice description for this type in the form :

.lattice myType<> {
    Lub -> @mylub(_,_)
    Glb -> @myglb(_,_)
    Bottom -> $myBottom()
    Top -> $myTop()
}

Now, one can declare a relation with lattice arguments :

.decl Relation R(x:number, y:number, z:myType<>)

Semantically, a tuple R(x,y,z) where z is a lattice element implies all tuples R(x,y,z') where z' <= z is the lattice.

Additionally, such relation R will ensure at each time that there is a single fact of the form R(x, y, ...), and ... will be the least upper bound (using the Lub specification of the lattice) of all the otherwise produced tuples of the form R(x, y, ...).

Clauses using atoms containing lattice attributes will behave accordingly to the semantics of lattice:
Example:

.type Sign =
    Bottom{}
  | Negative{}
  | Positive{}
  | Top{}
  | Zero{}

.lattice Sign<> {
    Bottom -> $Bottom(),
    Lub -> @sign_lub(_,_),
    Glb -> @sign_glb(_,_)
}

Top($Top()).
Pos($Positive()).

A(x) :- Pos(x), Top(x).

will produce the fact A($Positive()) because the fact Top($Top()) implies Top($Positive()) ($Positive() < $Top() in the lattice). Technically, x will be evaluated as the the GLB of the x in Pos(x) and the x in Top(x).

Note that it is still possible to use the type myType as is without the lattice description :

.decl Relation R(x:number, y:number, z:myType)

and the relation R will behave as a regular relation, without automatic lub/glb.

See test interface/lub for a few examples using lattice

For the time being, there is a restriction on the Lub and Glb definitions : they can only be user-defined functors with the right signature. This can be extended in future PRs.

@julienhenry julienhenry requested a review from quentin November 9, 2023 14:09
Copy link
Member

@quentin quentin left a comment

Choose a reason for hiding this comment

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

First quick read.

src/RelationTag.h Show resolved Hide resolved
src/ast/Lattice.cpp Outdated Show resolved Hide resolved
src/ast/transform/InsertLatticeOperations.cpp Show resolved Hide resolved
src/interpreter/EqrelIndex.cpp Outdated Show resolved Hide resolved
src/interpreter/Util.h Show resolved Hide resolved
src/parser/parser.yy Show resolved Hide resolved
src/parser/parser.yy Show resolved Hide resolved
src/parser/scanner.ll Outdated Show resolved Hide resolved
src/synthesiser/Relation.cpp Show resolved Hide resolved
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #2438 (7571422) into master (2914f7b) will increase coverage by 0.24%.
Report is 19 commits behind head on master.
The diff coverage is 77.32%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2438      +/-   ##
==========================================
+ Coverage   77.75%   78.00%   +0.24%     
==========================================
  Files         474      483       +9     
  Lines       31164    31999     +835     
==========================================
+ Hits        24232    24961     +729     
- Misses       6932     7038     +106     
Files Coverage Δ
src/FunctorOps.cpp 60.81% <ø> (ø)
src/RelationTag.h 53.03% <ø> (+0.79%) ⬆️
src/ast/Attribute.h 100.00% <100.00%> (ø)
src/ast/Component.h 100.00% <ø> (ø)
src/ast/IterationCounter.cpp 100.00% <100.00%> (ø)
src/ast/Lattice.h 100.00% <100.00%> (ø)
src/ast/Program.h 100.00% <ø> (ø)
src/ast/QualifiedName.h 94.11% <ø> (ø)
src/ast/Relation.h 100.00% <100.00%> (ø)
src/ast/Term.h 75.00% <100.00%> (-15.00%) ⬇️
... and 76 more

... and 9 files with indirect coverage changes

@souffle-lang souffle-lang locked and limited conversation to collaborators Nov 10, 2023
@souffle-lang souffle-lang unlocked this conversation Nov 10, 2023
@julienhenry julienhenry changed the title Lattice support [Draft] Lattice support Nov 10, 2023
@julienhenry julienhenry changed the title [Draft] Lattice support Lattice support Nov 13, 2023
@quentin
Copy link
Member

quentin commented Nov 15, 2023

Great feature and impressive work.
Would be very nice to have it documented on Souffle's website.

@quentin quentin merged commit c17bbab into souffle-lang:master Nov 15, 2023
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants