From d8c78502b356256f9e098374f505fd883b6b84e2 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 29 Jan 2014 11:22:38 +0100 Subject: SI-8199 Account for module class suffix in -Xmax-classfile-name The class file name of an inner class is based on the flattened name of its owner chain. But, if this is going to be unreasonably long, it is shortened with the help of a MD5 hash. However, after this shortening takes place, we sneakily add one more character (the infamous '$') to the name when it is used for the module class. It is thus possible to exceed the limit by one. The enclosed test failed on Mac with "filename too long" because of this. I have also tested for trait implementatation classes, but these seem to be suffixed with "$class" before the name compactification runs, so they weren't actually a problem. This change is binary incompatible as separately compiled defintions and usages of named, inner classes need to agree on this setting. Most typically, however, these long names crop up for inner anonymous classes / functions, which are not prone to the binary incompatiblity, assuming that their creation hasn't be inlined to a separately compiled client. --- src/reflect/scala/reflect/internal/StdNames.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 7015105261..01881c6693 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -53,14 +53,17 @@ trait StdNames { * * We obtain the formula: * - * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6 + * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + suffixLength * - * (+6 for ".class"). MaxNameLength can therefore be computed as follows: + * (+suffixLength for ".class" and potential module class suffix that is added *after* this transform). + * + * MaxNameLength can therefore be computed as follows: */ val marker = "$$$$" + val maxSuffixLength = "$.class".length + 1 // potential module class suffix and file extension val MaxNameLength = math.min( - settings.maxClassfileName.value - 6, - 2 * (settings.maxClassfileName.value - 6 - 2*marker.length - 32) + settings.maxClassfileName.value - maxSuffixLength, + 2 * (settings.maxClassfileName.value - maxSuffixLength - 2*marker.length - 32) ) def toMD5(s: String, edge: Int): String = { val prefix = s take edge -- cgit v1.2.3