From 58b7f3c658bcd08a6e8dcc68937285f97e938e1b Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Wed, 13 Mar 2024 16:17:04 +0100 Subject: [PATCH] Partial revert of previous commit. Instead of avoiding fully qualified names, use a different separator in zincMangledName. [Cherry-picked 0f7de67245a8519842f2ef25b985fe967a24d561] --- .../src/dotty/tools/dotc/sbt/package.scala | 20 ++++++++++++------- .../xsbt/ExtractUsedNamesSpecification.scala | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/sbt/package.scala b/compiler/src/dotty/tools/dotc/sbt/package.scala index 7c24319005ed..dc0df381f08f 100644 --- a/compiler/src/dotty/tools/dotc/sbt/package.scala +++ b/compiler/src/dotty/tools/dotc/sbt/package.scala @@ -4,6 +4,7 @@ import dotty.tools.dotc.core.Contexts.Context import dotty.tools.dotc.core.Symbols.Symbol import dotty.tools.dotc.core.NameOps.stripModuleClassSuffix import dotty.tools.dotc.core.Names.Name +import dotty.tools.dotc.core.Names.termName inline val TermNameHash = 1987 // 300th prime inline val TypeNameHash = 1993 // 301st prime @@ -11,10 +12,15 @@ inline val InlineParamHash = 1997 // 302nd prime extension (sym: Symbol) - def constructorName(using Context) = - sym.owner.name ++ ";init;" - - /** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */ - def zincMangledName(using Context): Name = - if (sym.isConstructor) constructorName - else sym.name.stripModuleClassSuffix + /** Mangle a JVM symbol name in a format better suited for internal uses by sbt. + * WARNING: output must not be written to TASTy, as it is not a valid TASTy name. + */ + private[sbt] def zincMangledName(using Context): Name = + if sym.isConstructor then + // TODO: ideally we should avoid unnecessarily caching these Zinc specific + // names in the global chars array. But we would need to restructure + // ExtractDependencies caches to avoid expensive `toString` on + // each member reference. + termName(sym.owner.fullName.mangledString.replace(".", ";").nn ++ ";init;") + else + sym.name.stripModuleClassSuffix diff --git a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala index d6cc3ac6339d..e47371175de6 100644 --- a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala +++ b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala @@ -306,7 +306,7 @@ class ExtractUsedNamesSpecification { // All classes extend Object "Object", // All classes have a default constructor called - "Object;init;", + "java;lang;Object;init;", // the return type of the default constructor is Unit "Unit" )