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

[WIP] Safe initialization for Scala #4543

Closed
wants to merge 83 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@liufengyun
Copy link
Contributor

liufengyun commented May 17, 2018

This is a joint attempt with @biboudis .

Currently, zero change to typer and types.

import scala.annotation.{ partial, init }


class Parent(x: Int) {
  var name: String = _
  var addr: String = _                       // warning: addr is not initialized

  val len = name.size                        // warning: name not initialized
  lazy val l1 = name.size                    // ok: l1 is lazy
  lazy val l2 = addr.size                    // warning: l2 is forced at L32 before `addr` is initialized

  val fun: Int => Int = n => n + list.size   // ok, fun is a partial value
  val bar = new Bar("bar", fun)              // ok, Bar accepts partial value
  bar.result                                 // warning: bar is a partial value

  val child = new Child(this)                // warning: `this` is partial, while full value expected
  List(5, 9).map(n => n + list.size)         // warning: partial value used as full value

  f(20)                                      // warning: list not initialized

  val list = List(1, 2, 3)

  if (x > 5) {
    name = "big"
    addr = "Lausanne"
  }
  else {
    name = "small"
  }

  val temp1 = l1                               // ok, name init
  val temp2 = l2                               // warning: addr not initialized

  // f is called during initialization, needs to be `private` or `final`.
  def f(m: Int) =
    m + list.size                              // warning: `f` is called at L19 before `list` is initialized

  List(1, 3, 5).map(n => n + list.size)        // ok, `this.list` already initialized
}


class Bar(val name: String, fun: (Int => Int) @partial) {
  def result = fun(20)
}

class Child(parent: Parent) {
  println(parent.name)
}

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch 2 times, most recently from 77dadc4 to ac95f8c May 22, 2018

@liufengyun liufengyun self-assigned this May 28, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch 4 times, most recently from b22d79e to dd2c805 Jun 4, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch 2 times, most recently from b0eb8ad to 487ec8a Aug 13, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch from 3ae677e to cc2b1c8 Aug 29, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch 2 times, most recently from 1b8fc07 to 75db73e Sep 20, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch 5 times, most recently from 8ed55bd to afa1048 Oct 4, 2018

@liufengyun

This comment has been minimized.

Copy link
Contributor Author

liufengyun commented Oct 4, 2018

test performance please

@dotty-bot

This comment has been minimized.

Copy link

dotty-bot commented Oct 4, 2018

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

@dotty-bot

This comment has been minimized.

Copy link

dotty-bot commented Oct 4, 2018

Performance test finished successfully:

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

Benchmarks is based on merging with master (42de57a)

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch 5 times, most recently from 436931e to 045f7f3 Oct 5, 2018

@liufengyun

This comment has been minimized.

Copy link
Contributor Author

liufengyun commented Oct 8, 2018

test performance please

@dotty-bot

This comment has been minimized.

Copy link

dotty-bot commented Oct 8, 2018

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

@dotty-bot

This comment has been minimized.

Copy link

dotty-bot commented Oct 8, 2018

Performance test finished successfully:

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

Benchmarks is based on merging with master (7463afe)

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch from 045f7f3 to 7852404 Nov 9, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch from 7852404 to b456c50 Nov 9, 2018

liufengyun added some commits Nov 9, 2018

@liufengyun liufengyun force-pushed the dotty-staging:safe-init branch from b456c50 to 2d90d74 Nov 9, 2018

@liufengyun

This comment has been minimized.

Copy link
Contributor Author

liufengyun commented Nov 9, 2018

test performance please

@dotty-bot

This comment has been minimized.

Copy link

dotty-bot commented Nov 9, 2018

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

@dotty-bot

This comment has been minimized.

Copy link

dotty-bot commented Nov 9, 2018

Performance test finished successfully:

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

Benchmarks is based on merging with master (a9029dc)

@liufengyun

This comment has been minimized.

Copy link
Contributor Author

liufengyun commented Jan 15, 2019

Close for now, more research is required to completely remove the annotation requirement.

@liufengyun liufengyun closed this Jan 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment