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: Ensure that the constraints are checked and propagated fully #4798

Merged
merged 6 commits into from
May 30, 2022

Conversation

Marwes
Copy link
Contributor

@Marwes Marwes commented May 27, 2022

fix: Always query the root variable for the constraint it is bound by

Only the root variable knows which kinds it is constrained by as we remove them and combine
them when two variables are unified

fix: Don't cause errors in default argument checking due to label requirements

fix: Always add constraints to the root variable

Else we aren't able to reliably lookup all constraints for a variable as they
may be spread out over multiple (otherwise unified) variables.

Extracted from #4776

Markus Westerlind added 4 commits May 27, 2022 15:08
Only the root variable knows which kinds it is constrained by as we remove them and combine
them when two variables are unified
Else we aren't able to reliably lookup all constraints for a variable as they
may be spread out over multiple (otherwise unified) variables.
@Marwes Marwes requested a review from a team as a code owner May 27, 2022 13:19
@Marwes Marwes requested review from nathanielc and removed request for a team May 27, 2022 13:19
Copy link
Contributor

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

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

Can you add a test case for this case?

Else we aren't able to reliably lookup all constraints for a variable as they
may be spread out over multiple (otherwise unified) variables.

I have some questions below to help me understand.

@@ -182,6 +182,28 @@ pub fn equal(
})
}

pub fn subsume(
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the intent of the name subsume? Is this related to subtyping somehow? My understanding of your changes was that we are propagating the constraints to the root type. Is root type the supertype in this context? I had assumed that the root type was just the root type variable where all its sub type variables are all equal to it and we have a convention to associate the constraints with the root type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the intent of the name subsume? Is this related to subtyping somehow?

Yes, this change is for fix: Don't cause errors in default argument checking due to label requirements. I needed to change the check to use subsumption, else the default value (a string literal) would not get treated as a label and cause an error as the function required a label to be passed. It should probably have been a separate PR as it is a different change from fully checking the constraints fully.

Is root type the supertype in this context?

No. If multiple variables are unified the root is the variable that names the entire set.
Say you unify like this

A <> B
B <> C

D <> E

The set A, B, C may have the root A while D, E has the root E. Querying the root for B or C returns A in both cases which lets us know that they are unified while querying it for D will yield E so we know it is in a disjoint set from B, C (and A). Which variable in a set that ends up as the root is arbitrary and just a by product of how https://en.wikipedia.org/wiki/Disjoint-set_data_structure is implemented.

Specifically in this change I made sure that add a constraint on, for example, B (which has A as the root) we actually record the constraint on A. Before, when we added the constraint on B explicitly inference did not know that A and C were also constrained by this (hence lost).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation, helps clarify.

Markus Westerlind added 2 commits May 27, 2022 19:26
…is bound by

Only the root variable knows which kinds it is constrained by as we remove them and combine
them when two variables are unified
@Marwes
Copy link
Contributor Author

Marwes commented May 27, 2022

Can you add a test case for this case?

Fixed. Messed up the cherry-pick/rebase and dropped the test and a change.

@Marwes Marwes merged commit 49e2997 into master May 30, 2022
@Marwes Marwes deleted the cherrypick branch May 30, 2022 10:23
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