diff options
author | Paul Phillips <paulp@improving.org> | 2011-11-21 03:24:51 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-11-21 03:24:51 +0000 |
commit | c6cc1bbafcd327daac9b77c2ea9476af4c3133ee (patch) | |
tree | eb27671d7ce0711ffaf635bb0d39a6242c1512bc /src/compiler | |
parent | 053e224677a4581c8b0721f42650003a27b2aaf3 (diff) | |
download | scala-c6cc1bbafcd327daac9b77c2ea9476af4c3133ee.tar.gz scala-c6cc1bbafcd327daac9b77c2ea9476af4c3133ee.tar.bz2 scala-c6cc1bbafcd327daac9b77c2ea9476af4c3133ee.zip |
Fix for what have been rather uncommon common o...
Fix for what have been rather uncommon common owners.
The complete histogram of results for "commonOwner" until this patch,
when building quick.lib and quick.comp:
Calculated common owner Occurrences
----------------------- -----------
NoSymbol 299,242
Everything Else 0
Since I'm always paranoid somebody will think I'm the one who broke
such things in the first place, I got in the gitmobile and fingered the
responsible party.
Looks OK when it was checked in: r3930, Feb 4 2005. And it was smooth
sailing until... r4026, Mar 22 2005. So 6 1/2 weeks of goodness for poor
commonOwnerMap, to be followed by 6 1/2 years of endless NoSymboldom. In
2005 I was still making a living grifting strangers in seedy gambling
halls, so I think I'm in the clear. Here's the exact spot.
https://github.com/scala/scala/commit/ae0da87d1aaeded9eb7f9c9ecbed8a31
3667757d#L12L991
I found this while trying to figure out why we are generating so many
refinements. This doesn't fix any of that, but maybe takes us a notch
closer. Review by odersky.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/internal/Types.scala | 70 |
1 files changed, 31 insertions, 39 deletions
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 85a12193a9..88019f51f7 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -4114,29 +4114,41 @@ A type's typeSymbol should never be inspected directly. } } - /** A map to compute the most deeply nested owner that contains all the symbols + /** The most deeply nested owner that contains all the symbols * of thistype or prefixless typerefs/singletype occurrences in given type. */ - object commonOwnerMap extends TypeMap { - var result: Symbol = _ - def init() = { result = NoSymbol } - def apply(tp: Type): Type = { - assert(tp ne null) - tp.normalize match { - case ThisType(sym) => - register(sym) - case TypeRef(NoPrefix, sym, args) => - register(sym.owner); args foreach apply - case SingleType(NoPrefix, sym) => - register(sym.owner) - case _ => - mapOver(tp) - } - tp + private def commonOwner(t: Type): Symbol = commonOwner(t :: Nil) + + /** The most deeply nested owner that contains all the symbols + * of thistype or prefixless typerefs/singletype occurrences in given list + * of types. + */ + private def commonOwner(tps: List[Type]): Symbol = { + if (tps.isEmpty) NoSymbol + else { + commonOwnerMap.result = null + tps foreach (commonOwnerMap traverse _) + val result = if (commonOwnerMap.result ne null) commonOwnerMap.result else NoSymbol + debuglog(tps.mkString("commonOwner(", ", ", ") == " + result)) + result } + } + private object commonOwnerMap extends TypeTraverser { + var result: Symbol = _ + private def register(sym: Symbol) { - while (result != NoSymbol && sym != result && !(sym isNestedIn result)) - result = result.owner; + // First considered type is the trivial result. + if ((result eq null) || (sym eq NoSymbol)) + result = sym + else + while ((result ne NoSymbol) && (result ne sym) && !(sym isNestedIn result)) + result = result.owner + } + def traverse(tp: Type) = tp.normalize match { + case ThisType(sym) => register(sym) + case TypeRef(NoPrefix, sym, args) => register(sym.owner) ; args foreach traverse + case SingleType(NoPrefix, sym) => register(sym.owner) + case _ => mapOver(tp) } } @@ -5813,26 +5825,6 @@ A type's typeSymbol should never be inspected directly. if (ts exists (_.isNotNull)) res.notNull else res } - /** The most deeply nested owner that contains all the symbols - * of thistype or prefixless typerefs/singletype occurrences in given type. - */ - private def commonOwner(t: Type): Symbol = { - commonOwnerMap.init - commonOwnerMap.apply(t) - commonOwnerMap.result - } - - /** The most deeply nested owner that contains all the symbols - * of thistype or prefixless typerefs/singletype occurrences in given list - * of types. - */ - private def commonOwner(tps: List[Type]): Symbol = { - // debuglog("computing common owner of types " + tps)//DEBUG - commonOwnerMap.init - tps foreach { tp => commonOwnerMap.apply(tp); () } - commonOwnerMap.result - } - /** Compute lub (if `variance == 1`) or glb (if `variance == -1`) of given list * of types `tps`. All types in `tps` are typerefs or singletypes * with the same symbol. |