Skip to content

typedSelect refactorings #11037

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 5 commits into from
Jan 15, 2021
Merged

typedSelect refactorings #11037

merged 5 commits into from
Jan 15, 2021

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 8, 2021

The aim of the refactoring is to be clearer and to be able to drop ExtMethodApply.

Two main strategies:

  1. Move some code out of adapt and assignType into typedSelect.
  2. Concentrate extension method expansion and conversions for selections in a
    method tryExtensionOrConversion. The method is called from typedSelectandtryInsertImplicitOnQualifier`.

The aim of the refactoring is to move all select-dependent adaptations and re-tries into
typedSelect. Right now some are in adapt and some are in assignType. This is awkward
since it means that

  • we do too much in TypeAssigner. Since it aims to be minimal TypeAssigner should have no business doing adaptations
    and retries.
  • we do some adaptations too early in adapt. This means we need the kludge of wrapping
    trees in ExtMethodApply which causes byname implicit depending on recursive given crash #8182, among others.

Fixes #8182

@odersky odersky marked this pull request as draft January 8, 2021 13:02
@odersky odersky force-pushed the fix-#8182 branch 5 times, most recently from 30ee52c to 876e6e6 Compare January 11, 2021 13:11
@odersky odersky marked this pull request as ready for review January 11, 2021 13:22
@odersky odersky requested a review from liufengyun January 13, 2021 11:06
Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

Nice simplification 👍

Need to rebase to resolve conflicts.

-- [E008] Not Found Error: tests/neg/i8032.scala:3:12 ------------------------------------------------------------------
3 |val y = ???.map // error
| ^^^^^^^
| value map is not a member of Nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this removed by accident? Or it's due to the TODO in the typer about the improvement on error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it was removed since the error message now contained an additional clause

Note that implicit extension methods cannot be applied because they are ambiguous;
  |both method charArrayOps in object Predef and method doubleArrayOps in object Predef provide an extension method `map` on (??? : => Nothing)
2 

but that clause was not deterministic (different conversion candidates showed up). I have now changed the reporting
so that the eplanation is dropped for arguments of type Nothing and brought the check file back.

if isExtension then return found
else
checkImplicitConversionUseOK(found)
val qual1 = withoutMode(Mode.ImplicitsEnabled)(adapt(found, selProto, locked))
Copy link
Contributor

Choose a reason for hiding this comment

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

In Implicits.scala, the method tryConversionForSelection seems to already ensure compatibility w.r.t the selProto. Is the adaptation here still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. It looks like the adapt can be dropped here.

tryEither {
val tree1 = tryExtensionOrConversion(tree, pt, pt, qual, locked, NoViewsAllowed, privateOK = false)
if tree1.isEmpty then None
else Some(adapt(tree1, pt, locked))
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the result tree1 already adapted w.r.t. to pt in the call tryExtensionOrConversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it isn't. tryExtensionOrConversion only does a typedSelect, not a full typed. typedSelect does not adapt.

The aim of the refactoring is to be clearer and to be able to drop ExtMethodApply.

Two main strategies:

  1. Move some code out of adapt and assignType into typedSelect.
  2. Concentrate extension method expansion and conversions for selections in a
    method `tryExtensionOrConversion. The method is called from `typedSelect`
    and `tryInsertImplicitOnQualifier`.

The aim of the refactoring is to move all select-dependent adaptations and re-tries into
typedSelect. Right now some are in adapt and some are in assignType. This is awkward
since it means that

  - we do too much in TypeAssigner. Sine it aims to be minimal TypeAssigner should have no business doing adaptations
and retries.
  - we do some adaptations too early in adpt. This means we need the kludge of wrapping
trees in ExtMethodApply which causes scala#8182, among others.

Fixes scala#8182
@odersky
Copy link
Contributor Author

odersky commented Jan 15, 2021

test performance please

@dottybot
Copy link
Member

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

@odersky odersky merged commit 49ae535 into scala:master Jan 15, 2021
@odersky odersky deleted the fix-#8182 branch January 15, 2021 13:50
@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with master (f5e84f4)

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.

byname implicit depending on recursive given crash
4 participants