Skip to content

Commit b77f54c

Browse files
committed
valsig infer, local lazy vals
1 parent 082e718 commit b77f54c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

hand-written.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ With [JEP-118](http://openjdk.java.net/jeps/118), parameter names can be stored
154154
scala> val paramNames = classOf[Person].getConstructors.head.getParameters.toList
155155
paramNames: List[java.lang.reflect.Parameter] = List(final java.lang.String name, final int age)
156156

157+
#### New representation and locking scope for local lazy vals
158+
159+
Local lazy vals and objects, i.e., those defined in methods, now use a more efficient representation (implemented in [#5294](https://github.com/scala/scala/pull/5294) and [#5374](https://github.com/scala/scala/pull/5374)).
160+
161+
In Scala 2.11, a local lazy val is encoded using two heap-allocated objects (one for the value, a second for the initialized flag), and initialization synchronizes on the enclosing class instance.
162+
163+
This has been cleaned up by creating a single heap-allocated object that holds both the value and the initialized flag, and is at the same time used as initialization lock. A similar implementation already existed in Dotty.
164+
157165
### Tooling improvements
158166

159167
#### New back end
@@ -346,18 +354,14 @@ While the adjustment to overloading resolution improves compatibility, there als
346354
<console>:13: error: ambiguous reference to overloaded definition
347355

348356

349-
### Inferred types for `val` (and `lazy val`)
357+
### Inferred types for fields
350358

351-
[#5141](https://github.com/scala/scala/pull/5141) and [#5294](https://github.com/scala/scala/pull/5294) align type inference for `def`, `val`, and `lazy val`, fixing assorted corner cases and inconsistencies. As a result, the inferred type of a `val` or `lazy val` may change.
359+
Type inference for `val`, and `lazy val` has been aligned with `def`, fixing assorted corner cases and inconsistencies ([#5141](https://github.com/scala/scala/pull/5141) and [#5294](https://github.com/scala/scala/pull/5294)). Concretely, when computing the type of an overriding field, the type of the overridden field is used used as expected type. As a result, the inferred type of a `val` or `lazy val` may change in Scala 2.12.
352360

353-
In particular, `implicit val`s that didn't need explicitly declared types before may need them now. (This is always good practice anyway.)
361+
In particular, an `implicit val` that did not need an explicitly declared type in 2.11 may need one now. (This is always good practice anyway.)
354362

355363
You can get the old behavior with `-Xsource:2.11`. This may be useful for testing whether these changes are responsible if your code fails to compile.
356364

357-
[Lazy vals and objects](https://github.com/scala/scala/pull/5294) have been reworked, and those defined in methods now use a [more efficient representation](https://github.com/scala/scala/pull/5374) that allows synchronization on the holder of the `lazy val`, instead of the surrounding class (as in Dotty).
358-
359-
-- TODO: why is this in the "inferred types" section, why under "breaking changes"? This should go somewhere else.
360-
361365
### Changed syntax trees (affects macro and compiler plugin authors)
362366

363367
PR [#4794](https://github.com/scala/scala/pull/4749) changed the syntax trees for selections of statically accessible symbols. For example, a selection of `Predef` no longer has the shape `q"scala.this.Predef"` but simply `q"scala.Predef"`. Macros and compiler plugins matching on the old tree shape need to be adjusted.

0 commit comments

Comments
 (0)