From e91006ae7b895df82d02fa0cc587682880d512c4 Mon Sep 17 00:00:00 2001 From: Dan13llljws Date: Wed, 13 Mar 2024 21:18:50 -0400 Subject: [PATCH 1/5] added Vector.emptyIterator to white list --- compiler/src/dotty/tools/dotc/transform/init/Objects.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 4b56a7c81ca4..061f7f902bbf 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -1683,10 +1683,12 @@ class Objects: end if // class body + val whiteList = Set("scala.collection.immutable.Vector.emptyIterator") tpl.body.foreach { case vdef : ValDef if !vdef.symbol.is(Flags.Lazy) && !vdef.rhs.isEmpty => - val res = eval(vdef.rhs, thisV, klass) + var res = eval(vdef.rhs, thisV, klass) val sym = vdef.symbol + if (whiteList.contains(sym.showFullName)) res = Bottom if sym.is(Flags.Mutable) then val addr = Heap.fieldVarAddr(summon[Regions.Data], sym, State.currentObject) thisV.initVar(sym, addr) From 8a5cf8b441b3d1fe09ad8e6a11e6c71dd0added3 Mon Sep 17 00:00:00 2001 From: Dan13llljws Date: Mon, 18 Mar 2024 10:01:37 -0400 Subject: [PATCH 2/5] changed plain string to Definitions --- .../src/dotty/tools/dotc/transform/init/Objects.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 061f7f902bbf..90df85b98ecf 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -66,7 +66,9 @@ import dotty.tools.dotc.core.Flags.AbstractOrTrait * whole-program analysis. However, the check is not modular in terms of project boundaries. * */ -class Objects: +class Objects(using Context @constructorOnly): + val immutableHashSetBuider: Symbol = requiredClass("scala.collection.immutable.HashSetBuilder") + val HashSetBuilder_rootNode: Symbol = immutableHashSetBuider.requiredValue("rootNode") // ----------------------------- abstract domain ----------------------------- @@ -1683,12 +1685,11 @@ class Objects: end if // class body - val whiteList = Set("scala.collection.immutable.Vector.emptyIterator") + val whiteList = Set(HashSetBuilder_rootNode) tpl.body.foreach { case vdef : ValDef if !vdef.symbol.is(Flags.Lazy) && !vdef.rhs.isEmpty => - var res = eval(vdef.rhs, thisV, klass) val sym = vdef.symbol - if (whiteList.contains(sym.showFullName)) res = Bottom + var res = if (whiteList.contains(sym)) Bottom else eval(vdef.rhs, thisV, klass) if sym.is(Flags.Mutable) then val addr = Heap.fieldVarAddr(summon[Regions.Data], sym, State.currentObject) thisV.initVar(sym, addr) From 8315f78f746ad7b7a9d73e9c40f3dc63602a3b94 Mon Sep 17 00:00:00 2001 From: Dan13llljws Date: Mon, 18 Mar 2024 14:39:17 -0400 Subject: [PATCH 3/5] changed to --- compiler/src/dotty/tools/dotc/transform/init/Objects.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 90df85b98ecf..28f4121d25e6 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -1689,7 +1689,7 @@ class Objects(using Context @constructorOnly): tpl.body.foreach { case vdef : ValDef if !vdef.symbol.is(Flags.Lazy) && !vdef.rhs.isEmpty => val sym = vdef.symbol - var res = if (whiteList.contains(sym)) Bottom else eval(vdef.rhs, thisV, klass) + val res = if (whiteList.contains(sym)) Bottom else eval(vdef.rhs, thisV, klass) if sym.is(Flags.Mutable) then val addr = Heap.fieldVarAddr(summon[Regions.Data], sym, State.currentObject) thisV.initVar(sym, addr) From 2a9f366f390da4ff986ff3ad9f5ed8034a450e05 Mon Sep 17 00:00:00 2001 From: Dan13llljws Date: Mon, 25 Mar 2024 09:19:38 -0400 Subject: [PATCH 4/5] finalized whiteList --- compiler/src/dotty/tools/dotc/transform/init/Objects.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 28f4121d25e6..0e91581d8cc9 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -66,9 +66,12 @@ import dotty.tools.dotc.core.Flags.AbstractOrTrait * whole-program analysis. However, the check is not modular in terms of project boundaries. * */ +import Decorators.* class Objects(using Context @constructorOnly): val immutableHashSetBuider: Symbol = requiredClass("scala.collection.immutable.HashSetBuilder") val HashSetBuilder_rootNode: Symbol = immutableHashSetBuider.requiredValue("rootNode") + + val whiteList = Set(HashSetBuilder_rootNode) // ----------------------------- abstract domain ----------------------------- @@ -1685,7 +1688,6 @@ class Objects(using Context @constructorOnly): end if // class body - val whiteList = Set(HashSetBuilder_rootNode) tpl.body.foreach { case vdef : ValDef if !vdef.symbol.is(Flags.Lazy) && !vdef.rhs.isEmpty => val sym = vdef.symbol From c2223811fc0da9f8e21c5cd9fb4a5f37bbb1ac17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lhot=C3=A1k?= Date: Mon, 25 Mar 2024 09:20:09 -0400 Subject: [PATCH 5/5] Update compiler/src/dotty/tools/dotc/transform/init/Objects.scala --- compiler/src/dotty/tools/dotc/transform/init/Objects.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 0e91581d8cc9..5301a654b82a 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -69,6 +69,7 @@ import dotty.tools.dotc.core.Flags.AbstractOrTrait import Decorators.* class Objects(using Context @constructorOnly): val immutableHashSetBuider: Symbol = requiredClass("scala.collection.immutable.HashSetBuilder") + // TODO: this should really be an annotation on the rhs of the field initializer rather than the field itself. val HashSetBuilder_rootNode: Symbol = immutableHashSetBuider.requiredValue("rootNode") val whiteList = Set(HashSetBuilder_rootNode)