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

[Merged by Bors] - perf(library/type_context): cache type-class searches w/o mvars #332

Closed
wants to merge 1 commit into from

Conversation

gebner
Copy link
Member

@gebner gebner commented Jun 15, 2020

This PR adds caching of intermediate results during type-class synthesis, under the condition that the subgoals have no temporary metavariables. For example, a subgoal has_add α is cached, but has_coe_t α ?m is not.

It is theoretically possible that some type-class searches fail now, because we no longer try all possible instances (and if this actually matters for another instance to apply). But it's a bug anyhow if you have two instances that are not definitionally equal.

@gebner
Copy link
Member Author

gebner commented Jun 15, 2020

As expected, all errors were theoretical. mathlib builds fine.

bors merge

bors bot pushed a commit that referenced this pull request Jun 15, 2020
This PR adds caching of intermediate results during type-class synthesis, under the condition that the subgoals have no temporary metavariables.  For example, a subgoal `has_add α` is cached, but `has_coe_t α ?m` is not.

It is theoretically possible that some type-class searches fail now, because we no longer try all possible instances (and if this actually matters for another instance to apply).  But it's a bug anyhow if you have two instances that are not definitionally equal.
@bors
Copy link

bors bot commented Jun 15, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title perf(library/type_context): cache type-class searches w/o mvars [Merged by Bors] - perf(library/type_context): cache type-class searches w/o mvars Jun 15, 2020
@bors bors bot closed this Jun 15, 2020
@bors bors bot deleted the tc_cache branch June 15, 2020 16:10
@fpvandoorn
Copy link
Member

fpvandoorn commented Jun 15, 2020

This is really nice! I feel that the exponential search time on type-class inference was one of the big bottlenecks for development in mathlib.

I wouldn't be surprised if this sped up a lot of other things as well, like simp (and maybe even library_search?).

@gebner
Copy link
Member Author

gebner commented Jun 15, 2020

It will definitely speed up simp (in some cases). My initial motivation came from this test case from the simp_nf linter:

import all
-- before: 16s
-- after: 0.3s
example {α : Type*} {β : Type*} (f : α → β) (a : α) :
  (f : pfun α β) a = roption.some (f a) :=
by simp

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.

None yet

2 participants