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

we only need to prove things one way #754

Merged
merged 6 commits into from
Apr 12, 2022
Merged

Conversation

nikomatsakis
Copy link
Contributor

Partially addresses #727 (some work is left for future work).

@flodiebold
Copy link
Member

I tried out this patch with rust-analyzer on the rust-analyzer codebase:

> $ ./ra-chalk-master -q analysis-stats . 
Database loaded:     1.23s, 246minstr (metadata 747.44ms, 24minstr; build 266.50ms, 9338kinstr)
  crates: 39, mods: 857, decls: 19554, fns: 14566
Item Collection:     17.80s, 78ginstr
  exprs: 400526, ??ty: 342 (0%), ?ty: 514 (0%), !ty: 155
Inference:           102.34s, 375ginstr
Total:               120.14s, 453ginstr

> $ ./ra-chalk-niko -q analysis-stats . 
Database loaded:     1.14s, 245minstr (metadata 720.16ms, 24minstr; build 222.83ms, 9060kinstr)
  crates: 39, mods: 857, decls: 19554, fns: 14566
Item Collection:     17.82s, 78ginstr
  exprs: 400526, ??ty: 342 (0%), ?ty: 514 (0%), !ty: 17
Inference:           96.19s, 361ginstr
Total:               114.01s, 439ginstr

> $ ./ra-chalk-niko-early-exit -q analysis-stats .
Database loaded:     1.15s, 245minstr (metadata 711.23ms, 24minstr; build 206.14ms, 9085kinstr)
  crates: 39, mods: 857, decls: 19554, fns: 14566
Item Collection:     16.40s, 78ginstr
  exprs: 400526, ??ty: 342 (0%), ?ty: 514 (0%), !ty: 17
Inference:           75.01s, 318ginstr
Total:               91.41s, 396ginstr

So this patch fixes almost all remaining type mismatches (that's the !ty) we have on our codebase, and with the early exit I mentioned it actually improves inference time by 25%!

I inspected the results, seems good
@nikomatsakis
Copy link
Contributor Author

@flodiebold ready to merge, I think

tests/test/misc.rs Show resolved Hide resolved
Comment on lines 843 to 847
} yields[SolverChoice::slg_default()] {
expect![["Ambiguous; definite substitution for<?U0,?U0> { [?0 := ^0.0, ?1 := '^0.1] }"]]
} yields[SolverChoice::recursive_default()] {
expect![["Ambiguous; suggested substitution for<?U0,?U0> { [?0 := ^0.0, ?1 := '^0.1] }"]]
expect![[r#"Ambiguous; no inference guidance"#]]
}
Copy link
Member

Choose a reason for hiding this comment

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

And here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are, I believe, equivalent. That substitution is an "identity substitution", so it's not very useful guidance. I looked into why this was coming about -- it's because I removed the (erroneous) "early exit" that was causing us to bail out early. What we now do is bail out because we see ?T: '?a for some unknown ?T and we can't make progress (in fact, we could see that it's in the environment, but the code doesn't do that today).

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

A few points, but I'm okay if we want to merge this.

Comment on lines 841 to 845
} yields[SolverChoice::slg_default()] {
expect![["Ambiguous; definite substitution for<?U0,?U0> { [?0 := ^0.0, ?1 := '^0.1] }"]]
} yields[SolverChoice::recursive_default()] {
expect![["Ambiguous; suggested substitution for<?U0,?U0> { [?0 := ^0.0, ?1 := '^0.1] }"]]
expect![[r#"Ambiguous; no inference guidance"#]]
}
Copy link
Member

Choose a reason for hiding this comment

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

The fact these are still different bothers me. Also, SLG is still given the identity solution as "ambiguous", which is somewhat at odds with what the aggregate hack is saying, right?

@@ -0,0 +1,133 @@
use super::*;
Copy link
Member

Choose a reason for hiding this comment

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

I feel like I'd like to see these tests more properly categorized. But I don't know how strongly I feel about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense-- but I'm not sure where to categorize them!

@@ -83,9 +91,11 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
break Guidance::Unknown;
}

// FIXME: This may cause us to miss some "trivially true" answers maybe? Haven't investigated very deeply.
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this is the cause of the test I pointed out.

@@ -46,8 +46,16 @@ impl<I: Interner> AggregateOps<I> for SlgContextOps<'_, I> {
}
};

// If the answer is trivially true and thus subsumes all others, then that's a unique-enough answer for us :)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe at least a comment that this is hacky would be nice.

@nikomatsakis
Copy link
Contributor Author

I reverted the last commit

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

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

r=me with issue opened to reconcile ambiguous vs unique, and how they different between the two solvers

@nikomatsakis
Copy link
Contributor Author

@bors r+

@bors
Copy link
Contributor

bors commented Apr 12, 2022

📌 Commit 70b2fdb has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Apr 12, 2022

⌛ Testing commit 70b2fdb with merge 3e3f76a...

@nikomatsakis
Copy link
Contributor Author

Filed #760

@lnicola
Copy link
Member

lnicola commented Apr 12, 2022

Would it be possible to trigger an early publish? We want to get our hands on this in RA, and upgrading sooner will let us find any issues before the next release.

@jackh726
Copy link
Member

I can kick off a release later today.

@bors
Copy link
Contributor

bors commented Apr 12, 2022

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing 3e3f76a to master...

@bors bors merged commit 3e3f76a into rust-lang:master Apr 12, 2022
@jackh726
Copy link
Member

0.82.0 released

@lnicola
Copy link
Member

lnicola commented Apr 12, 2022

with the early exit I mentioned it actually improves inference time by 25%!

Strangely, I'm not seeing that large of a difference:

baseline
Database loaded:     1.79s, 244minstr (metadata 420.87ms, 24minstr; build 1.29s, 8944kinstr)
  crates: 39, mods: 878, decls: 20758, fns: 15517
Item Collection:     9.90s, 79ginstr
58  exprs: 425364, ??ty: 325 (0%), ?ty: 145 (0%), !ty: 142                                                                                                         
Inference:           53.36s, 405ginstr
Total:               63.25s, 484ginstr

chalk-0.82
Database loaded:     1.22s, 244minstr (metadata 413.94ms, 24minstr; build 727.46ms, 8602kinstr)
  crates: 39, mods: 878, decls: 20758, fns: 15517
Item Collection:     9.87s, 79ginstr
  exprs: 425364, ??ty: 325 (0%), ?ty: 145 (0%), !ty: 1                                                                                                             
Inference:           48.90s, 373ginstr
Total:               58.77s, 452ginstr

@lnicola
Copy link
Member

lnicola commented Apr 12, 2022

Sure, but flodiebold reported a 25% speed-up vs. the 8% I got. Still good, but a bit unexpected.

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.

5 participants