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 "var_universe invoked on bound variable" crash #649

Merged

Conversation

flodiebold
Copy link
Member

This should fix rust-lang/rust-analyzer#5495.

unify_ty_ty calls normalize_ty_shallow on both types and then assumes that they can't be bound variables. With integer type variables, this assumption was broken, because you could have a general type variable resolving to an integer type variable resolving to i32. To fix this, normalize_ty_shallow probes twice, to make sure to fully resolve the variable.

This should fix rust-lang/rust-analyzer#5495.

`unify_ty_ty` calls `normalize_ty_shallow` on both types and then assumes that
they can't be bound variables. With integer type variables, this assumption was
broken, because you could have a general type variable resolving to an integer
type variable resolving to i32. To fix this, `normalize_ty_shallow` probes
twice, to make sure to fully resolve the variable.
@jackh726
Copy link
Member

jackh726 commented Nov 8, 2020

So, I think this problem (or a related one) came up in the variance PR. (See this commit as a fix).

I guess, I'm a little bit unsure on if the "root" variable also corresponds to the resolved type. In that commit, we're worried about always getting back the same inference var. For this PR, I guess I'm somewhat worried about the arbitrary normalize twice.

This is definitely something I want @nikomatsakis to comment on, because I don't know enough about ena and the semantics of probing for variables.

@flodiebold
Copy link
Member Author

That's a different problem. The case in the commit you reference is that multiple inference variables of the same kind (i.e. general, or integer, or float) that don't have a value yet are unified. Here, it's about when e.g. an integer variable is unified with a general variable. That works differently: variables of different kind aren't simply unified as variables, but rather the general type variable's value is set to the integer variable (just like if we were unifying with a concrete type instead of an integer variable). That's why a general type variable can never resolve to another general type variable, but it can resolve to an integer or float variable.

Here's the same code in rustc (it just recurses instead of normalizing twice, but the effect should be the same).

@jackh726
Copy link
Member

jackh726 commented Nov 8, 2020

Thanks for the clarification!

@bors r+

@bors
Copy link
Contributor

bors commented Nov 8, 2020

📌 Commit f3b3156 has been approved by jackh726

@bors
Copy link
Contributor

bors commented Nov 8, 2020

⌛ Testing commit f3b3156 with merge d112f2e...

@bors
Copy link
Contributor

bors commented Nov 8, 2020

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing d112f2e to master...

@bors bors merged commit d112f2e into rust-lang:master Nov 8, 2020
@flodiebold flodiebold deleted the general-vars-containing-integer-vars branch November 9, 2020 16:53
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.

var_universe invoked on bound variable when analysis-stating --with-deps
3 participants