From d8985603b5d670414ea7844a628168f92a09c402 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 25 Jun 2015 09:39:15 +0200 Subject: SpecializeNames: Duplicate scalac behaviour, sort tparams --- src/dotty/tools/dotc/core/NameOps.scala | 9 ++++++--- src/dotty/tools/dotc/core/Names.scala | 23 +++++++++++++++++++++++ src/dotty/tools/dotc/core/StdNames.scala | 3 ++- 3 files changed, 31 insertions(+), 4 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 4d6cca61d..74555961e 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -236,7 +236,7 @@ object NameOps { case nme.clone_ => nme.clone_ } - def specializedFor(returnType: Types.Type, args: List[Types.Type])(implicit ctx: Context): name.ThisName = { + def specializedFor(classTargs: List[Types.Type], classTargsNames: List[Name], methodTargs: List[Types.Type], methodTarsNames: List[Name])(implicit ctx: Context): name.ThisName = { def typeToTag(tp: Types.Type): Name = { tp.classSymbol match { @@ -253,9 +253,12 @@ object NameOps { } } + val methodTags: Seq[Name] = (methodTargs zip methodTarsNames).sortBy(_._2).map(x => typeToTag(x._1)) + val classTags: Seq[Name] = (classTargs zip classTargsNames).sortBy(_._2).map(x => typeToTag(x._1)) + name.fromName(name ++ nme.specializedTypeNames.prefix ++ - args.map(typeToTag).foldRight(typeToTag(returnType))(_ ++ _) ++ - nme.specializedTypeNames.suffix) + methodTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.separator ++ + classTags.fold(nme.EMPTY)(_ ++ _) ++ nme.specializedTypeNames.suffix) } /** If name length exceeds allowable limit, replace part of it by hash */ diff --git a/src/dotty/tools/dotc/core/Names.scala b/src/dotty/tools/dotc/core/Names.scala index 1ee56fe1c..a09487280 100644 --- a/src/dotty/tools/dotc/core/Names.scala +++ b/src/dotty/tools/dotc/core/Names.scala @@ -347,4 +347,27 @@ object Names { StringBuilder.newBuilder.mapResult(s => from.fromChars(s.toCharArray, 0, s.length)) def apply(): Builder[Char, Name] = termNameBuilder } + + implicit val NameOrdering: Ordering[Name] = new Ordering[Name] { + def compare(x: Name, y: Name): Int = { + if (x.isTermName && y.isTypeName) 1 + else if (x.isTypeName && y.isTermName) -1 + else if (x.start == y.start && x.length == y.length) 0 + else { + val until = Math.min(x.length, y.length) + var i = 0 + + while (i < until && x(i) == y(i)) i = i + 1 + + if (i < until) { + if (x(i) < y(i)) -1 + else /*(x(i) > y(i))*/ 1 + } else { + if (x.length < y.length) 1 + else if (x.length > y.length) -1 + else 0 // shouldn't happen, but still + } + } + } + } } diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala index eb1a73625..577e1ebf3 100644 --- a/src/dotty/tools/dotc/core/StdNames.scala +++ b/src/dotty/tools/dotc/core/StdNames.scala @@ -559,7 +559,8 @@ object StdNames { final val Void: N = "V" final val Object: N = "L" - final val prefix: N = "$mc" + final val prefix: N = "$m" + final val separator: N = "c" final val suffix: N = "$sp" } -- cgit v1.2.3