summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-19 00:31:59 +0000
committerPaul Phillips <paulp@improving.org>2011-03-19 00:31:59 +0000
commite7c2ab469c44894a9523d9660fd5fe32147a8996 (patch)
treeca6bde9b6f478b23c3e30d1dc1526bd6bb5ae16b
parenta7d2d13732df77e67fad790d3df9674082e7169d (diff)
downloadscala-e7c2ab469c44894a9523d9660fd5fe32147a8996.tar.gz
scala-e7c2ab469c44894a9523d9660fd5fe32147a8996.tar.bz2
scala-e7c2ab469c44894a9523d9660fd5fe32147a8996.zip
rytz's patch for making our crazy long names a ...
rytz's patch for making our crazy long names a bit less crazy. You can now use -Xmax-classfile-name to limit your filenames to as few as 72 characters. Watch out, nanotube gardens, we'll be stepping on your tiny flowers before you know it. No review.
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala1
-rw-r--r--src/compiler/scala/tools/nsc/symtab/NameManglers.scala23
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Names.scala23
3 files changed, 19 insertions, 28 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 1670dfb94a..7405ca0b3d 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -57,6 +57,7 @@ trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings {
val future = BooleanSetting ("-Xfuture", "Turn on future language features.")
val genPhaseGraph = StringSetting ("-Xgenerate-phase-graph", "file", "Generate the phase graphs (outputs .dot files) to fileX.dot.", "")
val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more detail on why some implicits are not applicable.")
+ val maxClassfileName = IntSetting ("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, Some(72, 255), _ => None)
val Xmigration28 = BooleanSetting ("-Xmigration", "Warn about constructs whose behavior may have changed between 2.7 and 2.8.")
val nouescape = BooleanSetting ("-Xno-uescape", "Disable handling of \\u unicode escapes.")
val Xnojline = BooleanSetting ("-Xnojline", "Do not use JLine for editing.")
diff --git a/src/compiler/scala/tools/nsc/symtab/NameManglers.scala b/src/compiler/scala/tools/nsc/symtab/NameManglers.scala
index b24a064139..dae07a29d5 100644
--- a/src/compiler/scala/tools/nsc/symtab/NameManglers.scala
+++ b/src/compiler/scala/tools/nsc/symtab/NameManglers.scala
@@ -22,15 +22,28 @@ trait NameManglers {
def flattenedName(segments: Name*): NameType = compactedString(segments mkString "$")
- private final val MaxFileNameLength = 255
- private final val MaxNameLength = MaxFileNameLength - 6 // leave space for ".class"
-
- /** "COMPACTIFY" */
+ /**
+ * COMPACTIFY
+ *
+ * The hashed name has the form (prefix + marker + md5 + marker + suffix), where
+ * - prefix/suffix.length = MaxNameLength / 4
+ * - md5.length = 32
+ *
+ * We obtain the formula:
+ *
+ * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6
+ *
+ * (+6 for ".class"). MaxNameLength can therefore be computed as follows:
+ */
+ private final val marker = "$$$$"
+ private final val MaxNameLength = math.min(
+ settings.maxClassfileName.value - 6,
+ 2 * (settings.maxClassfileName.value - 6 - 2*marker.length - 32) + 6
+ )
private lazy val md5 = MessageDigest.getInstance("MD5")
private def toMD5(s: String, edge: Int) = {
val prefix = s take edge
val suffix = s takeRight edge
- val marker = "$$$$"
val cs = s.toArray
val bytes = Codec toUTF8 cs
diff --git a/src/compiler/scala/tools/nsc/symtab/Names.scala b/src/compiler/scala/tools/nsc/symtab/Names.scala
index 9e0348c2e3..a046058faf 100644
--- a/src/compiler/scala/tools/nsc/symtab/Names.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Names.scala
@@ -23,9 +23,6 @@ trait Names extends reflect.generic.Names {
private final val HASH_MASK = 0x7FFF
private final val NAME_SIZE = 0x20000
- private final val MaxFileNameLength = 255
- private final val MaxClassNameLength = MaxFileNameLength - 6 // leave space for ".class"
-
final val nameDebug = false
/** memory to store all names sequentially
@@ -78,26 +75,6 @@ trait Names extends reflect.generic.Names {
else nc = nc + len
}
- private lazy val md5 = MessageDigest.getInstance("MD5")
-
- /** "COMPACTIFY" */
- private def toMD5(s: String, edge: Int) = {
- val prefix = s take edge
- val suffix = s takeRight edge
- val marker = "$$$$"
-
- val cs = s.toArray
- val bytes = Codec toUTF8 cs
- md5 update bytes
- val md5chars = md5.digest() map (b => (b & 0xFF).toHexString) mkString
-
- prefix + marker + md5chars + marker + suffix
- }
-
- def compactify(s: String): String =
- if (s.length <= MaxClassNameLength) s
- else toMD5(s, MaxClassNameLength / 4)
-
/** Create a term name from the characters in cs[offset..offset+len-1].
*/
def newTermName(cs: Array[Char], offset: Int, len: Int): TermName = {