From e12bc65f34b51d7d8a7eb510846e1b460d86f2af 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. --- .../src/dotty/tools/dotc/core/NameTags.scala | 3 +++ .../src/dotty/tools/dotc/sbt/ExtractAPI.scala | 3 +++ .../src/dotty/tools/dotc/sbt/package.scala | 18 ++++++++++++------ .../xsbt/ExtractUsedNamesSpecification.scala | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/NameTags.scala b/compiler/src/dotty/tools/dotc/core/NameTags.scala index 59dfaa3d437b..b8a264a7c256 100644 --- a/compiler/src/dotty/tools/dotc/core/NameTags.scala +++ b/compiler/src/dotty/tools/dotc/core/NameTags.scala @@ -40,6 +40,8 @@ object NameTags extends TastyFormat.NameTags { inline val EXPLICITFIELD = 38 // An explicitly named field, introduce to avoid a clash // with a regular field of the underlying name + inline val ZINCMANGLED = 39 // a reserved tag for use in Zinc name mangling (replace `.` by `::`) + def nameTagToString(tag: Int): String = tag match { case UTF8 => "UTF8" case QUALIFIED => "QUALIFIED" @@ -61,6 +63,7 @@ object NameTags extends TastyFormat.NameTags { case PARAMACC => "PARAMACC" case ADAPTEDCLOSURE => "ADAPTEDCLOSURE" case OBJECTCLASS => "OBJECTCLASS" + case ZINCMANGLED => "ZINCMANGLED" case SIGNED => "SIGNED" case TARGETSIGNED => "TARGETSIGNED" diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index dafb44d525e4..d591892982f2 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -79,6 +79,9 @@ class ExtractAPI extends Phase { val pw = new PrintWriter(File(sourceFile.file.jpath).changeExtension("inc").toFile .bufferedWriter(append = true), true) try { + pw.println() + pw.println("API:") + pw.println("====") classes.foreach(source => pw.println(DefaultShowAPI(source))) } finally pw.close() } diff --git a/compiler/src/dotty/tools/dotc/sbt/package.scala b/compiler/src/dotty/tools/dotc/sbt/package.scala index 7c24319005ed..17ef70a5f5bf 100644 --- a/compiler/src/dotty/tools/dotc/sbt/package.scala +++ b/compiler/src/dotty/tools/dotc/sbt/package.scala @@ -4,17 +4,23 @@ 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.NameKinds.QualifiedNameKind +import dotty.tools.dotc.core.NameTags.ZINCMANGLED inline val TermNameHash = 1987 // 300th prime inline val TypeNameHash = 1993 // 301st prime inline val InlineParamHash = 1997 // 302nd prime -extension (sym: Symbol) +private inline val ZINC_MANGLED_SEPARATOR = "::" + +/** Expanded names of the form `prefix :: name`. These only occur in zinc phases, and should not be written to TASTy */ +private[sbt] val ZincMangledName: QualifiedNameKind = new QualifiedNameKind(ZINCMANGLED, ZINC_MANGLED_SEPARATOR) - def constructorName(using Context) = - sym.owner.name ++ ";init;" +extension (sym: Symbol) - /** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */ - def zincMangledName(using Context): Name = - if (sym.isConstructor) constructorName + /** 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) sym.owner.fullNameSeparated(ZincMangledName) ++ ";init;" else sym.name.stripModuleClassSuffix diff --git a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala index d6cc3ac6339d..46f5a1941d11 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" )