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

fix ungrounded error when destructuring with don't-cares #2483

Merged
merged 2 commits into from
Apr 5, 2024

Conversation

quentin
Copy link
Member

@quentin quentin commented Apr 3, 2024

Name unnamed variables that appear in record and branch inits before the resolution of aliases.

fix #2482

After the ResolveAliasesTransformer, all occurences of t are replaced with [ta,_], and the groundedness constraint system cannot give a bounded value to [ta,_] in the head (var([ta,_])->0 in the Solution).

Clause: pred([ta,_],ta) :-
   fact([ta,_]).
Problem:
{
        var([ta,_]) ⇒ var(ta),
        var([ta,_]) ⇒ var(_),
        var(ta) ∧ var(_) ⇒ var([ta,_]),
        var([ta,_]) is true,
        var([ta,_]) ⇒ var(ta),
        var([ta,_]) ⇒ var(_),
        var(ta) ∧ var(_) ⇒ var([ta,_])
}
Solution:
{var(_)->1,var(_)->0,var([ta,_])->1,var([ta,_])->0,var(ta)->1}

When you provide an explicit variable for the second part of the record, the constraint system can be solved because the second member of the record has is bound by the variable (var(_fix)->1 and var([ta,_fix])->1):

Clause: pred([ta,_fix],ta) :-
   fact([ta,_fix]).
Problem:
{
        var([ta,_fix]) ⇒ var(ta),
        var([ta,_fix]) ⇒ var(_fix),
        var(ta) ∧ var(_fix) ⇒ var([ta,_fix]),
        var([ta,_fix]) is true,
        var([ta,_fix]) ⇒ var(ta),
        var([ta,_fix]) ⇒ var(_fix),
        var(ta) ∧ var(_fix) ⇒ var([ta,_fix])
}
Solution:
{var([ta,_fix])->1,var([ta,_fix])->1,var(ta)->1,var(_fix)->1}

To fix this, we need to transform _ into unique variables before the ResolveAliasesTransformer.

Name unnamed variables that appear in record and branch
inits before the resolution of aliases.

fix 2482

After the `ResolveAliasesTransformer`, all  occurences of `t` are replaced with `[ta,_]`, and the groundedness constraint system cannot give a bounded value to `[ta,_]` in the head (`var([ta,_])->0` in the `Solution`).

```
Clause: pred([ta,_],ta) :-
   fact([ta,_]).
Problem:
{
        var([ta,_]) ⇒ var(ta),
        var([ta,_]) ⇒ var(_),
        var(ta) ∧ var(_) ⇒ var([ta,_]),
        var([ta,_]) is true,
        var([ta,_]) ⇒ var(ta),
        var([ta,_]) ⇒ var(_),
        var(ta) ∧ var(_) ⇒ var([ta,_])
}
Solution:
{var(_)->1,var(_)->0,var([ta,_])->1,var([ta,_])->0,var(ta)->1}
```

When you provide an explicit variable for the second part of the record, the constraint system can be solved because the second member of the record has is bound by the variable (`var(_fix)->1` and `var([ta,_fix])->1`):

```
Clause: pred([ta,_fix],ta) :-
   fact([ta,_fix]).
Problem:
{
        var([ta,_fix]) ⇒ var(ta),
        var([ta,_fix]) ⇒ var(_fix),
        var(ta) ∧ var(_fix) ⇒ var([ta,_fix]),
        var([ta,_fix]) is true,
        var([ta,_fix]) ⇒ var(ta),
        var([ta,_fix]) ⇒ var(_fix),
        var(ta) ∧ var(_fix) ⇒ var([ta,_fix])
}
Solution:
{var([ta,_fix])->1,var([ta,_fix])->1,var(ta)->1,var(_fix)->1}
```

To fix this, we need to transform `_` into unique variables before the `ResolveAliasesTransformer`.
@quentin quentin requested a review from b-scholz April 3, 2024 13:09
@quentin
Copy link
Member Author

quentin commented Apr 3, 2024

This change allows some form of match/case:

case_adt(t, case) :-
  fact_adt(t),
  ( t = $Some(_,_), case = "some"
  ; t = $None(), case = "none"
  ).

@quentin quentin requested a review from julienhenry April 3, 2024 13:12
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.83%. Comparing base (57f104d) to head (bd052b5).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2483      +/-   ##
==========================================
+ Coverage   77.80%   77.83%   +0.03%     
==========================================
  Files         492      492              
  Lines       33189    33205      +16     
==========================================
+ Hits        25822    25846      +24     
+ Misses       7367     7359       -8     
Files Coverage Δ
src/ast/transform/ResolveAliases.cpp 98.65% <100.00%> (+0.10%) ⬆️

... and 4 files with indirect coverage changes

Copy link
Member

@julienhenry julienhenry left a comment

Choose a reason for hiding this comment

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

Thank you, this is useful.

@quentin quentin merged commit c7ce229 into souffle-lang:master Apr 5, 2024
35 checks passed
quentin added a commit to quentin/souffle that referenced this pull request Jun 3, 2024
…g#2483)

fix ungrounded error when destructuring with don't-cares

Name unnamed variables that appear in record and branch
inits before the resolution of aliases.

fix souffle-lang#2482

After the `ResolveAliasesTransformer`, all  occurences of `t` are replaced with `[ta,_]`, and the groundedness constraint system cannot give a bounded value to `[ta,_]` in the head (`var([ta,_])->0` in the `Solution`).

```
Clause: pred([ta,_],ta) :-
   fact([ta,_]).
Problem:
{
        var([ta,_]) ⇒ var(ta),
        var([ta,_]) ⇒ var(_),
        var(ta) ∧ var(_) ⇒ var([ta,_]),
        var([ta,_]) is true,
        var([ta,_]) ⇒ var(ta),
        var([ta,_]) ⇒ var(_),
        var(ta) ∧ var(_) ⇒ var([ta,_])
}
Solution:
{var(_)->1,var(_)->0,var([ta,_])->1,var([ta,_])->0,var(ta)->1}
```

When you provide an explicit variable for the second part of the record, the constraint system can be solved because the second member of the record has is bound by the variable (`var(_fix)->1` and `var([ta,_fix])->1`):

```
Clause: pred([ta,_fix],ta) :-
   fact([ta,_fix]).
Problem:
{
        var([ta,_fix]) ⇒ var(ta),
        var([ta,_fix]) ⇒ var(_fix),
        var(ta) ∧ var(_fix) ⇒ var([ta,_fix]),
        var([ta,_fix]) is true,
        var([ta,_fix]) ⇒ var(ta),
        var([ta,_fix]) ⇒ var(_fix),
        var(ta) ∧ var(_fix) ⇒ var([ta,_fix])
}
Solution:
{var([ta,_fix])->1,var([ta,_fix])->1,var(ta)->1,var(_fix)->1}
```

To fix this, we need to transform `_` into unique variables before the `ResolveAliasesTransformer`.
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.

Ungrounded record error when destructuring with don't-cares?
2 participants