Skip to content

Conversation

@ashawley
Copy link
Member

@ashawley ashawley commented Dec 4, 2018

UPDATE: this was reverted by #7917

In scala/scala-dev#459, there was a suggestion to provide a string variant to replace the symbol quote syntax:

book should have (
  sym"title" ("Programming in Scala"),
  sym"author" (List("Odersky", "Spoon", "Venners")),
  sym"pubYear" (2008)
)

This is a work-in-progress for discussion on providing an alternative so quote syntax can be deprecated. As implemented with StringContext, it supports interpolation as well.

I've disabled the test suite so that only the new test runs.

@scala-jenkins scala-jenkins added this to the 2.13.0-RC1 milestone Dec 4, 2018
@ashawley ashawley force-pushed the new-sym-syntax branch 2 times, most recently from 4a49645 to a3dca0b Compare December 5, 2018 02:50
@ashawley
Copy link
Member Author

ashawley commented Dec 5, 2018

Symbol literals supported pattern matching:

    'foo match {
      case 'bar => ...
    }

This shorthand syntax, using StringContext, won't compile:

    sym"foo" match {
      case sym"bar" => ...
    }
[error] method sym is not a case class, nor does it have an unapply/unapplySeq member
[error]       case sym"bar" => ...
[error]            ^
[error] one error found

It is possible to match using the Symbol.apply constructor.

    sym"foo" match {
      case Symbol("bar") => ...
    }

Is it possible to make sym a syntax that supports pattern matching? I don't think it would be a big loss to lose string interpolation when constructing symbols.

@smarter
Copy link
Member

smarter commented Dec 5, 2018

You can have an unapply on a string interpolator, see for example #7387

@ashawley
Copy link
Member Author

ashawley commented Dec 5, 2018

@smarter Exciting! Thanks for pointing that out.

@ashawley ashawley force-pushed the new-sym-syntax branch 3 times, most recently from 4d219a9 to f5f2e5c Compare December 5, 2018 18:07
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Dec 5, 2018
@ashawley
Copy link
Member Author

Using this syntax throughout the compiler was successfully experimented with in #7499.

@ashawley
Copy link
Member Author

I tried using this syntax in the 2.12 version of the community build, see scala/community-build#827

I forked 24 community projects that had literal symbols in their build. I added the new symbol syntax to these builds, and this resulted in 92 projects being built successfully.

  • acyclic
  • akka
  • base64
  • curryhoward
  • fansi
  • fastparse
  • geny
  • grizzled
  • jackson-module-scala
  • lift-json
  • magnolia
  • pcplod
  • pprint
  • scala-parser-combinators
  • scala-stm
  • scalamock
  • scalatags
  • scalatest
  • sourcecode
  • specs2
  • spray-json
  • twirl
  • utest

There was one project of the 24 that the new symbol syntax could not be made to work:

  • shapeless

Shapeless will either require some significant re-architecting to support symbols or dropping symbol literals entirely. I am not an expert, but I presume it is because Shapeless expects symbol literals to be available at the compiler/reflect level and not at runtime.

There were 85 builds that didn't run in the community build because a dependency failed to build or because shapeless can't build.

@smarter
Copy link
Member

smarter commented Jan 25, 2019

Shapeless will either require some significant re-architecting to support symbols or dropping symbol literals entirely. I am not an expert, but I presume it is because Shapeless expects symbol literals to be available at the compiler/reflect level and not at runtime.

/cc @milessabin

@ashawley
Copy link
Member Author

I may have overstated the situation in my last comment. There's evidence that Symbol.apply will work for Shapeless as an alternative to dropping symbol literals.

Copy link
Member

@SethTisue SethTisue left a comment

Choose a reason for hiding this comment

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

LGTM for merge after squash

@adriaanm

This comment has been minimized.

@SethTisue
Copy link
Member

thanks Aaron for your diligence on this. I think #7395 will be merged soon as well

@SethTisue SethTisue merged commit 700f842 into scala:2.13.x Feb 6, 2019
@ashawley
Copy link
Member Author

ashawley commented Feb 6, 2019

I am saddened that this feature of Lisp heritage will likely go away, but despite my best efforts I couldn't find a compelling reason to keep it. There's a chance something could still come up that would preclude it. I'm not an expert, but I would bet against such a possibility.

@SethTisue
Copy link
Member

SethTisue commented Feb 9, 2019

it's a bit sad we can't backport the new interpolator to 2.12.x, because bincompat. I guess cross-builders can use the Symbol constructor

@smarter
Copy link
Member

smarter commented Feb 9, 2019

It could also be implemented in a compat library.

@adriaanm
Copy link
Contributor

I find https://contributors.scala-lang.org/t/proposal-to-deprecate-and-remove-symbol-literals/2953/22 a pretty compelling argument against this PR (note the author on both ;-)). Should we revert this PR to avoid introducing too many ways of doing the same thing, especially since it likely won't help cross-building?

@SethTisue SethTisue removed the release-notes worth highlighting in next release notes label Mar 25, 2019
@SethTisue
Copy link
Member

reverted by #7917

@ashawley ashawley deleted the new-sym-syntax branch June 9, 2020 13:51
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.

6 participants