diff options
author | Martin Odersky <odersky@gmail.com> | 2015-07-01 18:09:41 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-07-06 17:46:48 +0200 |
commit | 4315ed21e564713e606c04eced62ddec2494183b (patch) | |
tree | dad24c735c6eb3534b110650e9cdd6243ac78a39 | |
parent | 7cdd006e25fecce309c5843721660b1de1827dba (diff) | |
download | dotty-4315ed21e564713e606c04eced62ddec2494183b.tar.gz dotty-4315ed21e564713e606c04eced62ddec2494183b.tar.bz2 dotty-4315ed21e564713e606c04eced62ddec2494183b.zip |
Make sharing violations errors
and use ctx.log for other output.
-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) { |