Skip to content
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

Deprecate early initializer #513

Closed
adriaanm opened this issue May 15, 2018 · 11 comments
Closed

Deprecate early initializer #513

adriaanm opened this issue May 15, 2018 · 11 comments
Milestone

Comments

@adriaanm
Copy link
Contributor

No description provided.

@adriaanm adriaanm added this to the 2.13.0-M5 milestone May 15, 2018
@adriaanm adriaanm changed the title deprecate early initializer Deprecate early initializer Jun 14, 2018
@som-snytt
Copy link

Even the label colors are better on scala-dev.

@eed3si9n
Copy link
Member

eed3si9n commented Jul 5, 2018

Is there a reason we are deprecating this before 2.14 when trait parameter is going to come? All warnings should be actionable such that the user can get rid of the warning somehow. In this case I'd get a warning saying "hey, this feature is going away." But then what am I supposed to do?

@som-snytt
Copy link

Yes, I agree, and Adriaan said on your PR, Even though, we must.

I think you're supposed to rearchitect your compiler so that you don't have early-initialized global all over the place.

How about, "early definitions are deprecated; Lightbend offers consulting services to help you rewrite your App; ask for Seth; also, App is going away too, so stop using that while you're at it."

Maybe emit the whole message only under -help or -verbose or -explain.

@adriaanm
Copy link
Contributor Author

adriaanm commented Jul 5, 2018 via email

@eed3si9n
Copy link
Member

eed3si9n commented Jul 5, 2018

If you have the cycle for it during 2.13.x, it would be cool to implement trait parameters too under -Xsource:2.14, which acts as a carrot. If you had that, you can remove early initializer under the flag as well. That might gives an opportunity to beta test the feature, and also encourage people to rip out other removals that we got into -Xsource:2.14.

@smarter
Copy link
Member

smarter commented Jul 5, 2018

Is there a reason we are deprecating this before 2.14 when trait parameter is going to come?

So far, it looks like Dotty (and by extension Tasty) will not support early initializers. If we want Tasty to be the one true backend of Scala 2.14, this means that early initializers need to be removed in 2.14 and so should be deprecated in 2.13. Alternatively we could tweak Tasty and Dotty to work with early initializers, but that will require some amount of work (and will need to be supported for a long time since Tasty should never break compatibility).

In this case I'd get a warning saying "hey, this feature is going away." But then what am I supposed to do?

Depending on what you used early initializers for, you may be able to rewrite your code without needing trait parameters, e.g in:

trait A {
  val x: Int
  println("A.x: " + x)
}

class B extends {
  val x: Int = 1
} with A

object Test {
  def main(args: Array[String]): Unit = {
    new B
  }
}

You can rewrite B as:

class B private (val x: Int) extends A {
  def this() = this(1)
}

@dwijnand
Copy link
Member

dwijnand commented Jul 5, 2018

It might be worth seeing how much code in the community build depends on early initialisers, and if it can be rewritten.

Either Martin or Adriaan asked at Scala Days NYC something along the lines of "Do you depend on early initialisers?" and no one raised their hand.

@som-snytt
Copy link

Thanks for the additional motivation on timing the deprecation.

I wish Adriaan had asked the crowd whether anyone pays attention to deprecations.

I just updated the check files in the PR, and I'm willing to tweak the 2.13 message to whatever is deemed useful.

I don't supposed anyone will come up with a Scalafix for the migration...

@dwijnand
Copy link
Member

dwijnand commented Jul 5, 2018

See scalacenter/scalafix#62

@som-snytt
Copy link

That was quite valiant.

@odersky
Copy link

odersky commented Jul 6, 2018 via email

ollyw added a commit to ollyw/docs.scala-lang that referenced this issue Aug 13, 2020
Document that early definitions are deprecated and going to be obsolete due to Tasty compatibly. See
scala/scala-dev#513 for more details
ollyw added a commit to ollyw/docs.scala-lang that referenced this issue Aug 14, 2020
Document that early definitions are deprecated and going to be obsolete due to Tasty compatibly. See
scala/scala-dev#513 for more details
ollyw added a commit to ollyw/docs.scala-lang that referenced this issue Aug 14, 2020
Document that early definitions are deprecated and going to be obsolete due to Tasty compatibly. See
scala/scala-dev#513 for more details
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

No branches or pull requests

6 participants