Skip to content

Commit

Permalink
Suppressing repetitive warnings in the global initialization checker (#…
Browse files Browse the repository at this point in the history
…19898)

This PR suppresses repetitive warnings in the global initialization
checker to make the warnings more manageable to analyze.
  • Loading branch information
olhotak authored Mar 10, 2024
2 parents a9bb881 + ac40aa6 commit 162b543
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class Checker extends Phase:
Semantic.checkClasses(classes)(using checkCtx)

if ctx.settings.YcheckInitGlobal.value then
Objects.checkClasses(classes)(using checkCtx)
val obj = new Objects
obj.checkClasses(classes)(using checkCtx)
}

units0
Expand Down
22 changes: 13 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import dotty.tools.dotc.core.Flags.AbstractOrTrait
* whole-program analysis. However, the check is not modular in terms of project boundaries.
*
*/
object Objects:
class Objects:

// ----------------------------- abstract domain -----------------------------

Expand Down Expand Up @@ -1757,16 +1757,20 @@ object Objects:
if cls.isAllOf(Flags.JavaInterface) then Bottom
else evalType(tref.prefix, thisV, klass, elideObjectAccess = cls.isStatic)

val mutateErrorSet: mutable.Set[(ClassSymbol, ClassSymbol)] = mutable.Set.empty
def errorMutateOtherStaticObject(currentObj: ClassSymbol, otherObj: ClassSymbol)(using Trace, Context) =
val msg =
s"Mutating ${otherObj.show} during initialization of ${currentObj.show}.\n" +
"Mutating other static objects during the initialization of one static object is forbidden. " + Trace.show
if mutateErrorSet.add((currentObj, otherObj)) then
val msg =
s"Mutating ${otherObj.show} during initialization of ${currentObj.show}.\n" +
"Mutating other static objects during the initialization of one static object is forbidden. " + Trace.show

report.warning(msg, Trace.position)
report.warning(msg, Trace.position)

val readErrorSet: mutable.Set[(ClassSymbol, ClassSymbol)] = mutable.Set.empty
def errorReadOtherStaticObject(currentObj: ClassSymbol, otherObj: ClassSymbol)(using Trace, Context) =
val msg =
"Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + ".\n" +
"Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace.show
if readErrorSet.add((currentObj, otherObj)) then
val msg =
"Reading mutable state of " + otherObj.show + " during initialization of " + currentObj.show + ".\n" +
"Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. " + Trace.show

report.warning(msg, Trace.position)
report.warning(msg, Trace.position)

0 comments on commit 162b543

Please sign in to comment.