Skip to content

Commit 7993b29

Browse files
committed
move scala3Compiler config to compiler module
1 parent 67351cb commit 7993b29

File tree

6 files changed

+54
-44
lines changed

6 files changed

+54
-44
lines changed

compiler/src/dotty/tools/backend/jvm/CodeGen.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import StdNames.nme
2424
import java.io.DataOutputStream
2525
import java.nio.channels.ClosedByInterruptException
2626

27-
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler, UnpicklerConfig }
27+
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler }
28+
import dotty.tools.dotc.core.tasty.TastyUnpickler
2829

2930
import scala.tools.asm
3031
import scala.tools.asm.tree._
@@ -94,7 +95,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
9495
for (binary <- unit.pickled.get(claszSymbol.asClass)) {
9596
generatedTasty += GeneratedTasty(store, binary)
9697
val tasty =
97-
val uuid = new TastyHeaderUnpickler(UnpicklerConfig.scala3Compiler, binary()).readHeader()
98+
val uuid = new TastyHeaderUnpickler(TastyUnpickler.scala3CompilerConfig, binary()).readHeader()
9899
val lo = uuid.getMostSignificantBits
99100
val hi = uuid.getLeastSignificantBits
100101

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import ast.desugar
2525
import parsing.JavaParsers.OutlineJavaParser
2626
import parsing.Parsers.OutlineParser
2727
import dotty.tools.tasty.{TastyHeaderUnpickler, UnpickleException, UnpicklerConfig}
28+
import dotty.tools.dotc.core.tasty.TastyUnpickler
2829

2930

3031
object SymbolLoaders {
@@ -447,7 +448,7 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
447448
val className = tastyFile.name.stripSuffix(".tasty")
448449
tastyFile.resolveSibling(className + ".class")
449450
if classfile != null then
450-
val tastyUUID = new TastyHeaderUnpickler(UnpicklerConfig.scala3Compiler, tastyBytes).readHeader()
451+
val tastyUUID = new TastyHeaderUnpickler(TastyUnpickler.scala3CompilerConfig, tastyBytes).readHeader()
451452
new ClassfileTastyUUIDParser(classfile)(ctx).checkTastyUUID(tastyUUID)
452453
else
453454
// This will be the case in any of our tests that compile with `-Youtput-only-tasty`

compiler/src/dotty/tools/dotc/core/tasty/TastyUnpickler.scala

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package tasty
55
import scala.language.unsafeNulls
66

77
import dotty.tools.tasty.{TastyFormat, TastyBuffer, TastyReader, TastyHeaderUnpickler, UnpicklerConfig}
8+
import TastyHeaderUnpickler.TastyVersion
89
import TastyFormat.NameTags._, TastyFormat.nameTagToString
910
import TastyBuffer.NameRef
1011

@@ -24,6 +25,39 @@ object TastyUnpickler {
2425
def apply(ref: NameRef): TermName = names(ref.index)
2526
def contents: Iterable[TermName] = names
2627
}
28+
29+
trait Scala3CompilerConfig extends UnpicklerConfig:
30+
private def asScala3Compiler(version: TastyVersion): String =
31+
if (version.major == 28) {
32+
// scala 3.x.y series
33+
if (version.experimental > 0)
34+
// scenario here is someone using 3.4.0 to read 3.4.1-RC1-NIGHTLY, in this case, we should show 3.4 nightly.
35+
s"the same nightly or snapshot Scala 3.${version.minor - 1} compiler"
36+
else s"a Scala 3.${version.minor}.0 compiler or newer"
37+
}
38+
else if (version.experimental > 0) "the same Scala compiler" // unknown major version, just say same
39+
else "a more recent Scala compiler" // unknown major version, just say later
40+
41+
/** The description of the upgraded scala compiler that can read the given TASTy version */
42+
final def upgradedReaderTool(version: TastyVersion): String = asScala3Compiler(version)
43+
44+
/** The description of the upgraded scala compiler that can produce the given TASTy version */
45+
final def upgradedProducerTool(version: TastyVersion): String = asScala3Compiler(version)
46+
47+
final def recompileAdditionalInfo: String = """
48+
| Usually this means that the library dependency containing this file should be updated.""".stripMargin
49+
50+
final def upgradeAdditionalInfo(fileVersion: TastyVersion): String =
51+
if (fileVersion.isExperimental && experimentalVersion == 0) {
52+
"""
53+
| Note that you are using a stable compiler, which can not read experimental TASTy.""".stripMargin
54+
}
55+
else ""
56+
end Scala3CompilerConfig
57+
58+
/** A config for the TASTy reader of a scala 3 compiler */
59+
val scala3CompilerConfig = new Scala3CompilerConfig with UnpicklerConfig.DefaultTastyVersion {}
60+
2761
}
2862

2963
import TastyUnpickler._
@@ -88,7 +122,7 @@ class TastyUnpickler(reader: TastyReader) {
88122
result
89123
}
90124

91-
new TastyHeaderUnpickler(UnpicklerConfig.scala3Compiler, reader).readHeader()
125+
new TastyHeaderUnpickler(scala3CompilerConfig, reader).readHeader()
92126

93127
locally {
94128
until(readEnd()) { nameAtRef.add(readNameContents()) }

tasty/test/dotty/tools/tasty/TastyHeaderUnpicklerTest.scala renamed to compiler/test/dotty/tools/dotc/core/tasty/TastyHeaderUnpicklerTest.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
package dotty.tools.tasty
1+
package dotty.tools.dotc.core.tasty
22

33
import org.junit.Assert._
44
import org.junit.{Test, Ignore}
55

6-
import TastyFormat._
7-
import TastyBuffer._
8-
import TastyHeaderUnpickler.TastyVersion
6+
import dotty.tools.tasty.TastyFormat._
7+
import dotty.tools.tasty.TastyBuffer._
8+
import dotty.tools.tasty.TastyBuffer
9+
import dotty.tools.tasty.TastyReader
10+
import dotty.tools.tasty.UnpickleException
11+
import dotty.tools.tasty.TastyHeaderUnpickler
12+
import dotty.tools.tasty.TastyHeaderUnpickler.TastyVersion
13+
import dotty.tools.tasty.UnpicklerConfig
914

1015
class TastyHeaderUnpicklerTest {
1116

@@ -260,7 +265,7 @@ class TastyHeaderUnpicklerTest {
260265
object TastyHeaderUnpicklerTest {
261266

262267
def fillHeader(maj: Int, min: Int, exp: Int, compiler: String): TastyBuffer = {
263-
val compilerBytes = compiler.getBytes(java.nio.charset.StandardCharsets.UTF_8)
268+
val compilerBytes = compiler.getBytes(java.nio.charset.StandardCharsets.UTF_8).nn
264269
val buf = new TastyBuffer(header.length + 32 + compilerBytes.length)
265270
for (ch <- header) buf.writeByte(ch.toByte)
266271
buf.writeNat(maj)
@@ -273,7 +278,7 @@ object TastyHeaderUnpicklerTest {
273278
buf
274279
}
275280

276-
case class CustomScalaConfig(compilerVersion: TastyVersion) extends UnpicklerConfig.Scala3Compiler {
281+
case class CustomScalaConfig(compilerVersion: TastyVersion) extends TastyUnpickler.Scala3CompilerConfig {
277282
override def majorVersion: Int = compilerVersion.major
278283
override def minorVersion: Int = compilerVersion.minor
279284
override def experimentalVersion: Int = compilerVersion.experimental
@@ -299,7 +304,7 @@ object TastyHeaderUnpicklerTest {
299304
fail()
300305
}
301306
catch {
302-
case err: UnpickleException => assert(err.getMessage.contains(message))
307+
case err: UnpickleException => assert(err.getMessage.nn.contains(message))
303308
}
304309
}
305310

tasty/src/dotty/tools/tasty/TastyHeaderUnpickler.scala

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,6 @@ object UnpicklerConfig {
5454
override final def experimentalVersion: Int = ExperimentalVersion
5555
}
5656

57-
trait Scala3Compiler extends UnpicklerConfig {
58-
private def asScala3Compiler(version: TastyVersion): String =
59-
if (version.major == 28) {
60-
// scala 3.x.y series
61-
if (version.experimental > 0)
62-
// scenario here is someone using 3.4.0 to read 3.4.1-RC1-NIGHTLY, in this case, we should show 3.4 nightly.
63-
s"the same nightly or snapshot Scala 3.${version.minor - 1} compiler"
64-
else s"a Scala 3.${version.minor}.0 compiler or newer"
65-
}
66-
else if (version.experimental > 0) "the same Scala compiler" // unknown major version, just say same
67-
else "a more recent Scala compiler" // unknown major version, just say later
68-
69-
/** The description of the upgraded scala compiler that can read the given TASTy version */
70-
final def upgradedReaderTool(version: TastyVersion): String = asScala3Compiler(version)
71-
72-
/** The description of the upgraded scala compiler that can produce the given TASTy version */
73-
final def upgradedProducerTool(version: TastyVersion): String = asScala3Compiler(version)
74-
75-
final def recompileAdditionalInfo: String = """
76-
| Usually this means that the library dependency containing this file should be updated.""".stripMargin
77-
78-
final def upgradeAdditionalInfo(fileVersion: TastyVersion): String =
79-
if (fileVersion.isExperimental && experimentalVersion == 0) {
80-
"""
81-
| Note that you are using a stable compiler, which can not read experimental TASTy.""".stripMargin
82-
}
83-
else ""
84-
}
85-
8657
trait Generic extends UnpicklerConfig {
8758
final def upgradedProducerTool(version: TastyVersion): String =
8859
"a later version"
@@ -102,9 +73,6 @@ object UnpicklerConfig {
10273
else ""
10374
}
10475

105-
/** A config for the TASTy reader of a scala 3 compiler */
106-
val scala3Compiler = new UnpicklerConfig with Scala3Compiler with DefaultTastyVersion {}
107-
10876
/** A config for the TASTy reader of a generic tool */
10977
val generic = new UnpicklerConfig with Generic with DefaultTastyVersion {}
11078
}

tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import java.io.DataOutputStream
2727
import java.nio.channels.ClosedByInterruptException
2828

2929
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler, UnpicklerConfig }
30+
import dotty.tools.tasty.core.TastyUnpickler
3031

3132
import scala.tools.asm
3233
import scala.tools.asm.Handle
@@ -285,7 +286,7 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim
285286
throw ex
286287
finally outstream.close()
287288

288-
val uuid = new TastyHeaderUnpickler(UnpicklerConfig.scala3Compiler, binary()).readHeader()
289+
val uuid = new TastyHeaderUnpickler(TastyUnpickler.scala3CompilerConfig, binary()).readHeader()
289290
val lo = uuid.getMostSignificantBits
290291
val hi = uuid.getLeastSignificantBits
291292

0 commit comments

Comments
 (0)