Skip to content

Change Implicit Resolution Rules #5887

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 6 commits into from
Feb 18, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 9, 2019

This applies the following changes to implicit resolution:

  1. nested implicits always take precedence over outer ones
  2. no more shadowing checks
  3. package prefixes are not considered.

See #5881 for a discussion of these changes.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@odersky
Copy link
Contributor Author

odersky commented Feb 10, 2019

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/5887/ to see the changes.

Benchmarks is based on merging with master (8cce121)

@odersky
Copy link
Contributor Author

odersky commented Feb 10, 2019

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/5887/ to see the changes.

Benchmarks is based on merging with master (8cce121)

@odersky
Copy link
Contributor Author

odersky commented Feb 10, 2019

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/5887/ to see the changes.

Benchmarks is based on merging with master (8cce121)

This was referenced Feb 11, 2019
@odersky odersky changed the title Trial: Make implicit resolution block scoped Change Implicit Resolution Rules Feb 14, 2019
@odersky
Copy link
Contributor Author

odersky commented Feb 14, 2019

As discussed in #5881, there are more changes to consider. However, I believe the three changes in this PR are quite uncontroversial. So they can go in independently of the rest. I'll base further PR's on this one.

So far, nesting was just one of several criteria for selecting
a best implicit. What would happen if nesting was most significant?
I.e. inner implicits would always win over outer ones? This has the
potential to simplify the rules, gain effiviency, and solve the
local consistency problem since we can disambiguate implicits using
a local definition (see implicit-disambiguation.scala as a test case).
Since we always prefer inner implicits over outer ones, no need
to also consider levels when disambiguating.
Since implicit selection is now inner to outer, shadowing checks
are less important than before.

Shadowing is necessary if we treat implicit search as a synthesis for untyped
terms. I.e. come up with an untyped term and then check whether that term is
typeable and refers to the original implicit. If there's a nested definition
with the same name, that fails.

This viewpoint is very easy to spec but a bit unnatural. In all other instances
of meta programming we deal with typed terms. If we synthesize a typed
term directly, then name resolution is already done and shadowing is immaterial.
Besides, shadowing tests,  if they fail, are almost always much more suprising
than enlightening.
Don't consider implicits in package prefixes to be in the implicit
scope of a type unless under -language:Scala2.
odersky added a commit to dotty-staging/dotty that referenced this pull request Feb 14, 2019
Update doc on implicit resolution changes to take the previous changes
in scala#5887 into account.
odersky added a commit to dotty-staging/dotty that referenced this pull request Feb 14, 2019
Update doc on implicit resolution changes to take the previous changes
in scala#5887 into account.
Copy link
Contributor

@milessabin milessabin left a comment

Choose a reason for hiding this comment

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

This all looks good to me :-)

odersky added a commit to dotty-staging/dotty that referenced this pull request Feb 18, 2019
Update doc on implicit resolution changes to take the previous changes
in scala#5887 into account.
@odersky odersky merged commit 4126f63 into scala:master Feb 18, 2019
@ghost ghost removed the stat:needs review label Feb 18, 2019
odersky added a commit to dotty-staging/dotty that referenced this pull request Feb 18, 2019
Update doc on implicit resolution changes to take the previous changes
in scala#5887 into account.
@allanrenucci allanrenucci deleted the implicit-nested branch February 18, 2019 21:50
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.

3 participants