Skip to content

Fix #3348: use a new typeState in inferView #3354

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
merged 2 commits into from
Oct 23, 2017

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Oct 20, 2017

Fix #3348

inferImplicit has a useful invariant that the constraint doesn't
change in the case of implicit resolution failure. However, this
invariant may not hold if completions are triggered during implicit resolution.
By create a new typeState for inferView, we ensure that the useful
invariant holds in such cases.

`inferImplicit` has an useful invariant that the constraint doesn't
change in the case of implicit resolution failure. However, this
invariant may not hold if completions are triggered during implicit resolution.
By create a new typeState for inferView, we ensure that the useful
invariant holds in such cases.
@liufengyun liufengyun requested a review from odersky October 20, 2017 12:17
@liufengyun
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3354/ to see the changes.

Benchmarks is based on merging with master (174444d)

@allanrenucci
Copy link
Contributor

You forgot to add the test case

@odersky
Copy link
Contributor

odersky commented Oct 20, 2017

I am not sure anymore whether we should undo completions when an implicit search fails. We have at least three choices here:

  1. Simply remove the assertion, which means we accept that a failed implicit search can add to the constraint via completions.
  2. Create a new TyperState and commit only on success, as done in this PR. But note that this will also forget all error messages that would be emitted for completed symbols
  3. Reset the constraint only, the same way it is done in isSubType.

I think we need to dig deeper to decide which of the three is the right strategy.

@liufengyun
Copy link
Contributor Author

liufengyun commented Oct 20, 2017

My feeling is that the assertion is a useful invariant to guard against other mistakes, thus I would make choice 1 as last resort.

For 2nd solution, actually the errors that emitted during completion are reported, as the following example shows:

class Test {
  import Test.test
  "Hello".toto     // error
}

object Test {
  def test = {
    abc                  // <== error reported
    implicitly[collection.generic.CanBuildFrom[List[Int], Int, List[Int]]]
  }
}

Or there are may be other cases that I'm ignorant of.

The 3rd option sounds good, I'll have a look.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants