Skip to content

Fixes to transparent to enable generic tuples #4916

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 9 commits into from
Aug 22, 2018

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 9, 2018

Several fixes to transparent methods needed to make the TupleAbstract.scala test work. This one is a PoC for an implementation of generic tuples with the following properties:

  • no limit of 22
  • generic operations are possible
  • fully backwards compatible with Scala-2 tuples
  • specializes for small tuple sizes, yielding optimized code

@odersky
Copy link
Contributor Author

odersky commented Aug 17, 2018

test performance please

@dottybot
Copy link
Member

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

@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with master (788908f)

val tp1 = mapOver {
tp match {
case tp: TypeRef if boundTypes.contains(tp.symbol) =>
val TypeAlias(alias) = tp.info
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we get anything other than a TypeAlias 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.

It should always be a TypeAlias because of the way we generate type bindings. So boundTypes.contains(tp.symbol) should imply tp.info is a TypeAlias.

}
}
val boundVars = getBoundVars(Nil, tpt)
for (bv <- boundVars) ctx.gadt.setBounds(bv, bv.info.bounds)
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels a bit ad hoc, isn't there a way to reuse normal type checking of patterns instead of redoing all that work 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.

I tried, but did not find a good way to re-use what's there. it's spread out over several different things.

@@ -165,7 +165,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
val leftArg = if (isRightAssoc && isInfixType(l)) "(" ~ argText(l) ~ ")" else argText(l)
val rightArg = if (!isRightAssoc && isInfixType(r)) "(" ~ argText(r) ~ ")" else argText(r)

leftArg ~ " " ~ simpleNameString(op.classSymbol) ~ " " ~ rightArg
leftArg ~ " " ~ simpleNameString(op.typeSymbol) ~ " " ~ rightArg
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW can be dropped, this is already fixed in #4072 (5e01496 and preserved by later refactorings).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On rebasing I reverted the conflicting code from #4072. So "("...")" will only be printed if precedence demands it. Not writting redundant parens is important in particular for long sequences of type operators, as for example when working with HLists.

Copy link
Contributor

Choose a reason for hiding this comment

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

@odersky Did you lose your changes? This PR (as merged) contains no such revert, and #4072 replaced extra parentheses with proper use of atPrec. Either you lost your changes or the code you reverted was the old one.

If you can find a bug in master, happy to fix it and add tests. 😄

# Conflicts:
#	tests/run/TupleImpl.scala
A PoC how generic tuples can be implemented

 - no limit of 22
 - generic operations are possible
 - fully backwards compatible with Scala-2 tuples
 - specializes for small tuple sizes, yielding optimized code
... to reflect the fact that empty blocks in inline code are now optimized away.
... since they are inlined themselves.

Also, fleshed out tuple PoC.
@odersky odersky force-pushed the fix-transparent-3 branch from a6b3166 to 103237e Compare August 22, 2018 15:51
@odersky odersky merged commit 33afaa2 into scala:master Aug 22, 2018
@allanrenucci allanrenucci deleted the fix-transparent-3 branch August 22, 2018 16:26
@OlivierBlanvillain
Copy link
Contributor

The newly added test doesn't pass -Ytest-pickler on my machine, I'm surprise this wasn't caught by the CI.

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