8000 SI-4700 Types with symbolic names print in infix by default · Pull Request #5589 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

SI-4700 Types with symbolic names print in infix by default #5589

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 3 commits into from Feb 16, 2017
Merged

SI-4700 Types with symbolic names print in infix by default #5589

merged 3 commits into from Feb 16, 2017

Conversation

ghost
Copy link
@ghost ghost commented Dec 8, 2016

before:

scala> implicitly[Int =:= Int]
res0: =:=[Int,Int] = <function1>

after:

scala> implicitly[Int =:= Int]
res0: Int =:= Int = <function1>

Building off of @VladUreche's work in #5401, here's a PR that addresses some of the comments there.

  • makes two-parameter types with symbolic names print infixly by default, and
  • adds a @showAsInfix annotation to enable/disable override that for types.

Review by @lrytz, @retronym, and others?

--allison

```
scala> import scala.annotation.infix
import scala.annotation.infix

scala> @infix class &&[T, U]
defined class $amp$amp

scala> def foo: Int && Boolean = ???
foo: Int && Boolean
```
@scala-jenkins scala-jenkins added this to the 2.12.2 milestone Dec 8, 2016
@ghost ghost changed the title (SI-5401) The thrilling continuation to the infix type printing saga. SI-4700 The thrilling continuation to the infix type printing saga. Dec 8, 2016
@lrytz
Copy link
Member
lrytz commented Dec 9, 2016

Thanks @allisonhb for picking this up, it looks great in the current form! CC @adriaanm

However, it adds a public class to the standard library, which is not forwards binary compatible. @SethTisue do you know why this is not flagged by MiMa? Could we ignore this case?

@retronym
Copy link
Member
retronym commented Dec 9, 2016

I we fixed a MiMa bug recently in our build. If this PR were rebased on 2.12.x, the compat violation ought to be reported.

I'm not totally against the idea of allowing annotations in a minor release. Need to give it some thought.

Last time we considered this was with @compileTimeOnly, which we decided had to wait until 2.11.0 to move from reflect.internal to annotation.

@ghost
Copy link
Author
ghost commented Dec 9, 2016

So for what little it's worth, I can't think of any places where someone would rather keep the prefix notation for symbolic type names, and only a few (refined comes to mind) where infix notation is preferred for non-symbolic names.

On the other hand, I know that at least in my workplace, types such as shapeless.::[Int, shapeless.::[(Long, Long), shapeless.::[String, shapeless.HNil]]] are a major cause for complaint. If you like I can rebase this onto 2.12.x, drop the annotation, and reinstate it in a 2.13.x PR.

--allison

edit: woops accidentally pushed "close + commit" button...


8000
@ghost ghost closed this Dec 9, 2016
@ghost ghost reopened this Dec 9, 2016
@milessabin
Copy link
Contributor

@allisonhb I'd be very keen to merge this in Typelevel Scala for the upcoming 2.12.1 release ... please let me know if you'd be happy with that.

@ghost
Copy link
Author
ghost commented Dec 10, 2016

@milessabin that sounds great! I'll make a PR against TLS as soon as I get home.

@milessabin
Copy link
Contributor

@allisonhb no need ... I can merge this PR to TLS as it stands. Thanks for working on this!

/* It only makes sense to show 2-ary type constructors infix.
* By default we do only if it's a symbolic name. */
override def isShowAsInfixType: Boolean =
args.size == 2 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

It's best to avoid calling size on a list. We have a more performant convenience method for this: hasLength(args, 2)

@lrytz
Copy link
Member
lrytz commented Dec 20, 2016

I did some testing what will happen if a class annotated @showAsInfix is used (on the classpath) by an older compiler, where the annotation doesn't exist.

scala> cls.annotations
res15: List[$r.intp.global.AnnotationInfo] = List(showAsInfix(showAsInfix.<init>$default$1))

scala> cls.annotations.head.atp.typeSymbol
res16: $r.intp.global.Symbol = class showAsInfix

scala> cls.annotations.head.atp.typeSymbol.getClass
res17: Class[_ <: $r.intp.global.Symbol] = class scala.reflect.internal.Symbols$StubClassSymbol

so this seems to be safe.

@lrytz
Copy link
Member
lrytz commented Dec 20, 2016

LGTM, veto by @retronym?

@SethTisue
Copy link
Member

Not sure about the details of the code, but I definitely support this design change.

@milessabin
Copy link
Contributor

FYI: this has been merged in Typelevel Scala 2.12.1.

@adriaanm
Copy link
Contributor

Based on Lukas's testing, I think this is ready to go.

@adriaanm adriaanm merged commit e2be7c4 into scala:2.12.x Feb 16, 2017
SethTisue added a commit to SethTisue/scala that referenced this pull request Feb 17, 2017
little missing piece of scala#5589;
not sure why it didn't fail PR validation
SethTisue added a commit to SethTisue/scala that referenced this pull request Feb 17, 2017
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Feb 22, 2017
@SethTisue SethTisue changed the title SI-4700 The thrilling continuation to the infix type printing saga. SI-4700 Types with symbolic names print in infix by default Apr 14, 2017
@fommil
Copy link
Contributor
fommil commented Apr 19, 2017

we get failures in the ensime-server tests that I think are because of this... looks like our inferred scaladoc URLs are changing, e.g. having to add to our CI

        equal(Some("docs/scala-library-" + c.scalaVersion + "-javadoc.jar/scala/Some.html#flatten[B](implicitev:<:<[A,Option[B]]):Option[B]")) or
        equal(Some("docs/scala-library-" + c.scalaVersion + "-javadoc.jar/scala/Some.html#flatten[B](implicitev:A<:<Option[B]):Option[B]"))

@fommil
Copy link
Contributor
fommil commented Apr 19, 2017

looks like the tags of the actual scaladocs did change with this. Was that expected?

@adriaanm
Copy link
Contributor
adriaanm commented Apr 19, 2017 via email

@fommil
Copy link
Contributor
fommil commented Apr 19, 2017

@adriaanm I'm not sure if it is a bug, it's a regression if anything, but flip flopping on regressions is not great either

@SethTisue
Copy link
Member

@allisonhb since this PR is linked directly from the 2.12.2 release notes, I've edited your PR description to include a "before/after" pair

smarter added a commit to dotty-staging/dotty that referenced this pull request Jun 8, 2017
This a partial port of scala/scala#5589 to
dotty: when pretty-printing an applied type, if its type constructor has
a symbolic name, then always print it in infix form. The PR in scalac
also adds an `@showAsInfix` annotation to control this behavior, but we
cannot do the same in dotty since we still rely on the standard library
from Scala 2.11 and the annotation only exists in 2.12 and up.
@eparejatobes
Copy link

Would be really nice if types would display accordingly in the scaladoc output.

@fommil
Copy link
Contributor
fommil commented Aug 15, 2017

I'd settle for scalac providing utility methods that converted between all the different kinds of names that a thing can have. This is the bulk of our work interfacing with the interactive compiler in ensime.

@SethTisue
Copy link
Member

Would be really nice if types would display accordingly in the scaladoc output

that would make a great scala/bug ticket (if there isn't one already?), and a nice manageably sized issue, I expect, for a volunteer contributor to tackle

was thinking of this just now because I'm watching a talk where the speaker is demoing HList from Shapeless, and those types sure do look nice in infix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants
0