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 incomplete check of record row constraints #1558

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

yannham
Copy link
Member

@yannham yannham commented Aug 30, 2023

Fixes #1393

In an attempt to free the allocation of the constraints of a record row unification variable that is being assigned to some other record rows, the code checking that row constraints are satisfied (constr_unify_rrows) was removing the constraints from the global state. Since rows are defined as linked lists, if the constraint wasn't violated on the first row, this function would recursively call itself. But then the subsequent recursive calls would try to get the constraints from the state again, to only find an empty set constraints, as it has been removed just before. The function thus wouldn't detect constraint violations happening in the tail of the record rows.

This explains why #1393 was getting triggered randomly (at first, then the issue became deterministic, maybe after the many refactorings related to introducing type variable levels), as it depends on the order of the row declarations.

This patch defines a subfunction which passes the initial constraints along recursive calls, such that they aren't lost during recursion, instead of trying to get them from the state again at each recursive call.

Additionally, constr_unify_rrows wasn't properly called in the body of remove_row, so row constraints weren't propagated properly there. Fixing constr_unify_rrows as described before and calling it at the right place fixed #1393.

@github-actions github-actions bot temporarily deployed to pull request August 30, 2023 16:39 Inactive
In an attempt to free the allocation of the constraints of a record row
unification variable that is being assigned to some record rows, the
code checking that row constraints are satisfied was removing the
constraints from the global state. Since rows are defined as linked
list, if the constraint wasn't violated on the first row, this function
would recursively call itself. But then the subsequent recursive calls
would try to get the constraints from the state again, to only find an
empty set constraints, as it has been removed just before. The function
thus wouldn't detect constraint violations happening in the tail of the
record rows.

This patch defines a subfunction which passes the initial constraints
along recursive calls, such that they aren't lost during recursion,
instead of trying to get them from the state again at each recursive
call.
@yannham yannham changed the title WIP Fix incomplete check of record row constraints Sep 1, 2023
@yannham yannham marked this pull request as ready for review September 1, 2023 10:33
@github-actions github-actions bot temporarily deployed to pull request September 1, 2023 10:34 Inactive
@yannham yannham added this pull request to the merge queue Sep 1, 2023
Merged via the queue into master with commit 3891689 Sep 1, 2023
4 checks passed
@yannham yannham deleted the fix/row-conflict-check branch September 1, 2023 15:00
suimong pushed a commit to suimong/nickel that referenced this pull request Sep 17, 2023
In an attempt to free the allocation of the constraints of a record row
unification variable that is being assigned to some record rows, the
code checking that row constraints are satisfied was removing the
constraints from the global state. Since rows are defined as linked
list, if the constraint wasn't violated on the first row, this function
would recursively call itself. But then the subsequent recursive calls
would try to get the constraints from the state again, to only find an
empty set constraints, as it has been removed just before. The function
thus wouldn't detect constraint violations happening in the tail of the
record rows.

This patch defines a subfunction which passes the initial constraints
along recursive calls, such that they aren't lost during recursion,
instead of trying to get them from the state again at each recursive
call.
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.

Type error depends on name of irrelevant record field
2 participants