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

Bug With Anonymous Records? #2158

Open
cwarden opened this issue Dec 15, 2021 Discussed in #2156 · 5 comments
Open

Bug With Anonymous Records? #2158

cwarden opened this issue Dec 15, 2021 Discussed in #2156 · 5 comments
Labels
bug - identified Bugs with an identified cause

Comments

@cwarden
Copy link
Contributor

cwarden commented Dec 15, 2021

Discussed in #2156

Originally posted by cwarden December 13, 2021
I'm working with records for the first time and running into an unexpected issue. Running the following program with souffle -v, souffle seems to get stuck in a loop of ResolveAnonymousRecordAliases and FoldAnonymousRecords.

.type Cell = [
   row: number,
   column: number
]

.decl cell_size(cell: Cell, size: number)
.decl number_bigger(cell: Cell, num: number)

cell_size([0, 1], 5).
cell_size([1, 1], 3).

number_bigger([r1, p1], n) :-
   cell_size([r1, p1], A),
   n = count : { cell_size([r2, p2], B),
   [r1, p1] != [r2, p2],
   A < B}.

.output number_bigger(IO=stdout, headers=true)

Is it a bug or am I doing something wrong?

The issue occurs as of 244cb07.

@b-scholz b-scholz added the bug - identified Bugs with an identified cause label Dec 16, 2021
@b-scholz
Copy link
Member

The endless loop in the AST-transformation pipeline is caused by FoldAnonymousRecords since it can only deal with anonymous records outside of aggregates. In the reported example, we have the anonymous record in the sub-clause of count.

@b-scholz b-scholz mentioned this issue Dec 16, 2021
@b-scholz
Copy link
Member

I have provided the fix so that aggregates are rewritten as well. The example would be rewritten to:

type Cell = [
   row: number,
   column: number
]

.decl cell_size(cell: Cell, size: number)
.decl number_bigger(cell: Cell, num: number)

cell_size([0, 1], 5).
cell_size([1, 1], 3).

number_bigger([r1, p1], n) :-
   cell_size([r1, p1], A),
   n = count : { cell_size([r2, p2], B),
   r1!=r2, p1!=  p2,
   A < B}.

.output number_bigger(IO=stdout, headers=true)

However, there is still the problem that the aggregation fails.

@b-scholz
Copy link
Member

b-scholz commented Dec 16, 2021

The problem is that we don't have a simple aggregate (although it looks like a simple aggregate).
The transformed Datalog code is,

.type Cell = [row:number, column:number]
.decl cell_size(cell:Cell, size:number) 
.decl number_bigger(cell:Cell, num:number) 
cell_size([0,1],5).

cell_size([1,1],3).

number_bigger([r1,p1],@generator_0) :- 
   cell_size([r1,p1],A),
   @generator_0 = count : { cell_size([r2,p2],B),r1 != r2,p1 != p2,A < B }.
.output number_bigger(IO="stdout",attributeNames="cell	num",headers="true",name="number_bigger",operation="output",output-dir=".",params="{"records": {"Cell": {"arity": 2, "params": ["row", "column"]}}, "relation": {"arity": 2, "params": ["cell", "num"]}}",types="{"ADTs": {}, "records": {"r:Cell": {"arity": 2, "types": ["i:number", "i:number"]}}, "relation": {"arity": 2, "types": ["r:Cell", "i:number"]}}")

This will not work because we have an unpack inside the aggregate relation.
We would need to fix aggregates first.

@b-scholz
Copy link
Member

You could introduce a helper relation that reflects the computations inside the count sub-clause. That might be the easiest way to solve your problem.

@cwarden
Copy link
Contributor Author

cwarden commented Dec 16, 2021

I solved it with a relation that maps the Cell records to autoinc() values that I used in number_bigger, but a relation of (bigger: Cell, smaller: Cell) tuples works as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - identified Bugs with an identified cause
Projects
None yet
Development

No branches or pull requests

2 participants