diff options
author | Paul Phillips <paulp@improving.org> | 2012-12-10 00:27:21 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-12-12 10:57:48 -0800 |
commit | 4bc3fa102768e78b194fd6a594f4b87d29e4efbf (patch) | |
tree | f82e50f1370eee618ac44bd1e0afcb695c47aba4 /src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala | |
parent | b26f12d4b116799e8860ddfd27ad398bc0c80b6a (diff) | |
download | scala-4bc3fa102768e78b194fd6a594f4b87d29e4efbf.tar.gz scala-4bc3fa102768e78b194fd6a594f4b87d29e4efbf.tar.bz2 scala-4bc3fa102768e78b194fd6a594f4b87d29e4efbf.zip |
Eliminated some sources of tree sharing.
Tracking shared trees led to various perpetrators, the simplest of
which are addressed herein. More consideration will be required:
we need to approach the problem with sufficient command to assure
both that trees are only shared when safe (which might without
architectural changes be "never") but also that we do not
duplicate definition trees unless it is appropriate.
Why do we care about tree sharing? Sometimes, a lot of the time
even, you can get away with sharing trees - but that's also why
it's responsible for all kinds of trouble. If the compiler would
break obviously and immediately then we wouldn't be doing it.
The danger of sharing is that one piece of an AST may undergo a
transformation or mutation and an unrelated piece of the AST will
be partially dragged into the change. The danger has become more
urgent with the arrival of macros. The first step in preventing
tree sharing mishaps is to reduce the amount the compiler does so
whatever is left is a lot easier to see. As a happy accident, it
will also fix bugs.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index 717c4b627b..77e7e013ab 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -232,12 +232,13 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { override def transformStats(stats: List[Tree], exprOwner: Symbol): List[Tree] = super.transformStats(stats, exprOwner) map { - case md @ ModuleDef(_, _, _) if extensionDefs contains md.symbol => - val defns = extensionDefs(md.symbol).toList map (member => - atOwner(md.symbol)(localTyper.typedPos(md.pos.focus)(member)) - ) - extensionDefs -= md.symbol - deriveModuleDef(md)(tmpl => deriveTemplate(tmpl)(_ ++ defns)) + case md @ ModuleDef(_, _, _) => + val extraStats = extensionDefs remove md.symbol match { + case Some(defns) => defns.toList map (defn => atOwner(md.symbol)(localTyper.typedPos(md.pos.focus)(defn.duplicate))) + case _ => Nil + } + if (extraStats.isEmpty) md + else deriveModuleDef(md)(tmpl => deriveTemplate(tmpl)(_ ++ extraStats)) case stat => stat } |