diff options
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/transform/CheckReentrant.scala | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/transform/CheckReentrant.scala b/src/dotty/tools/dotc/transform/CheckReentrant.scala index 9fe569581..e9ddce3dd 100644 --- a/src/dotty/tools/dotc/transform/CheckReentrant.scala +++ b/src/dotty/tools/dotc/transform/CheckReentrant.scala @@ -22,10 +22,23 @@ import NameOps._ import StdNames._ -/** The first tree transform - * - ensures there are companion objects for all classes except module classes - * - eliminates some kinds of trees: Imports, NamedArgs - * - stubs out native methods +/** A no-op transform that checks whether the compiled sources are re-entrant. + * If -Ycheck:reentrant is set, the phase makes sure that there are no variables + * that are accessible from a global object. It excludes from checking paths that + * are labeled with one of the annotations + * + * @sharable Indicating a class or val can be safely shared + * @unshared Indicating an object will not be accessed from multiple threads + * + * Currently the analysis is only intended to check the dotty compiler itself. To make + * it generally useful we'd need to add at least the following: + * + * - Handle polymorphic instantiation: We might instantiate a generic class + * with a type that contains vars. If the class contains fields of the generic + * type, this may constitute a path to a shared var, which currently goes undetected. + * - Handle arrays: Array elements are currently ignored because they are often used + * in an immutable way anyway. To do better, it would be helpful to have a type + * for immutable array. */ class CheckReentrant extends MiniPhaseTransform { thisTransformer => import ast.tpd._ @@ -50,7 +63,7 @@ class CheckReentrant extends MiniPhaseTransform { thisTransformer => sym.hasAnnotation(unsharedAnnot()) def scanning(sym: Symbol)(op: => Unit)(implicit ctx: Context): Unit = { - println(i"${" " * indent}scanning $sym") + ctx.log(i"${" " * indent}scanning $sym") indent += 1 try op finally indent -= 1 @@ -63,7 +76,9 @@ class CheckReentrant extends MiniPhaseTransform { thisTransformer => for (sym <- cls.classInfo.decls) if (sym.isTerm && !sym.isSetter && !isIgnored(sym)) if (sym.is(Mutable)) { - println(i"GLOBAL ${sym.showLocated}: ${sym.info} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") + ctx.error( + i"""possible data race involving globally reachable ${sym.showLocated}: ${sym.info} + | use -Ylog:checkReentrant+ to find out more about why the variable is reachable.""".stripMargin) shared += sym } else if (!sym.is(Method) || sym.is(Accessor | ParamAccessor)) { scanning(sym) { |