Skip to content

Fix #10739: Make collecting nullable fields deterministic #10741

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 1 commit into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ class CollectNullableFields extends MiniPhase {
private case class Nullable(by: Symbol) extends FieldInfo

/** Whether or not a field is nullable */
private var nullability: IdentityHashMap[Symbol, FieldInfo] = _

override def prepareForUnit(tree: Tree)(using Context): Context = {
if (nullability == null) nullability = new IdentityHashMap
ctx
}
private val nullability = new mutable.LinkedHashMap[Symbol, FieldInfo]

private def recordUse(tree: Tree)(using Context): Tree = {
val sym = tree.symbol
Expand All @@ -71,9 +66,9 @@ class CollectNullableFields extends MiniPhase {

if (isNullablePrivateField)
nullability.get(sym) match {
case Nullable(from) if from != ctx.owner => // used in multiple lazy val initializers
case Some(Nullable(from)) if from != ctx.owner => // used in multiple lazy val initializers
nullability.put(sym, NotNullable)
case null => // not in the map
case None => // not in the map
val from = ctx.owner
val isNullable =
from.is(Lazy, butNot = Module) && // is lazy val
Expand All @@ -100,7 +95,7 @@ class CollectNullableFields extends MiniPhase {
def lazyValNullables(using Context): IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]] = {
val result = new IdentityHashMap[Symbol, mutable.ListBuffer[Symbol]]

nullability.forEach {
nullability.foreach {
case (sym, Nullable(from)) =>
val bldr = result.computeIfAbsent(from, _ => new mutable.ListBuffer)
bldr += sym
Expand Down