Skip to content

Commit 4cc1e1d

Browse files
add TastyVersion to ClassSymbol
1 parent 9ad4f52 commit 4cc1e1d

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import ast.desugar
2424

2525
import parsing.JavaParsers.OutlineJavaParser
2626
import parsing.Parsers.OutlineParser
27-
import dotty.tools.tasty.TastyHeaderUnpickler
27+
import dotty.tools.tasty.{TastyHeaderUnpickler, TastyHeader}
28+
import dotty.tools.tasty.TastyFormat.TastyVersion
2829

2930

3031
object SymbolLoaders {
@@ -430,6 +431,11 @@ class TastyLoader(val tastyFile: AbstractFile) extends SymbolLoader {
430431
moduleRoot.classSymbol.rootTreeOrProvider = unpickler
431432
checkTastyUUID(tastyFile, tastyBytes)
432433

434+
// TODO move
435+
val TastyHeader(_, maj, min, exp, _) = new TastyHeaderUnpickler(tastyBytes).readFullHeader()
436+
classRoot.classSymbol.tastyVersion = TastyVersion(maj, min, exp)
437+
moduleRoot.classSymbol.tastyVersion = TastyVersion(maj, min, exp)
438+
433439

434440
private def checkTastyUUID(tastyFile: AbstractFile, tastyBytes: Array[Byte])(using Context): Unit =
435441
val classfile =

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import util.{SourceFile, NoSource, Property, SourcePosition, SrcPos, EqHashMap}
3232
import scala.annotation.internal.sharable
3333
import config.Printers.typr
3434
import dotty.tools.dotc.classpath.FileUtils.isScalaBinary
35+
import dotty.tools.tasty.TastyFormat.TastyVersion
3536

3637
object Symbols {
3738

@@ -403,6 +404,9 @@ object Symbols {
403404

404405
private var myTree: TreeOrProvider = tpd.EmptyTree
405406

407+
// TODO private and getter/setter
408+
var tastyVersion: TastyVersion = TastyVersion() // overwritten when loading from Tasty
409+
406410
/** If this is a top-level class and `-Yretain-trees` (or `-from-tasty`) is set.
407411
* Returns the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
408412
* This will force the info of the class.

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Synthesizer._
2222
import sbt.ExtractDependencies.*
2323
import sbt.ClassDependency
2424
import xsbti.api.DependencyContext._
25+
import dotty.tools.tasty.TastyFormat.TastyVersion
2526

2627
/** Synthesize terms for special classes */
2728
class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
@@ -415,7 +416,8 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
415416
val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString)))
416417
val elemsLabels = TypeOps.nestedPairs(elemLabels)
417418

418-
val elemHasDefaults = accessors.map(acc => ConstantType(Constant(acc.is(HasDefault))))
419+
val canSupportDefaults = cls.asClass.tastyVersion gteq TastyVersion(28, 4, 1) // TODO? cst
420+
val elemHasDefaults = accessors.map(acc => ConstantType(Constant(canSupportDefaults && acc.is(HasDefault))))
419421
val elemsHasDefaults = TypeOps.nestedPairs(elemHasDefaults)
420422

421423
val typeElems = tps.getOrElse(accessors.map(mirroredType.resultType.memberInfo(_).widenExpr))
@@ -474,7 +476,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
474476
// case class `cls` changes. See `sbt-test/source-dependencies/mirror-product`.
475477
val rec = ctx.compilationUnit.depRecorder
476478
rec.addClassDependency(cls, DependencyByMemberRef)
477-
rec.addUsedName(cls.primaryConstructor)
479+
rec.addUsedName(cls.primaryConstructor) // TODO test when only adding default
478480
makeProductMirror(pre, cls, None)
479481
else withErrors(i"$cls is not a generic product because ${cls.whyNotGenericProduct}")
480482
case Left(msg) =>

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,19 @@ Standard Section: "Comments" Comment*
271271

272272
object TastyFormat {
273273

274+
// TODO mv ?
275+
case class TastyVersion(
276+
majorVersion: Int = MajorVersion,
277+
minorVersion: Int = MinorVersion,
278+
experimentalVersion: Int = ExperimentalVersion
279+
) {
280+
def gteq(that: TastyVersion): Boolean = summon[Ordering[(Int, Int, Int)]].gteq(
281+
(this.majorVersion, this.minorVersion, this.experimentalVersion),
282+
(that.majorVersion, that.minorVersion, that.experimentalVersion)
283+
)
284+
}
285+
286+
274287
/** The first four bytes of a TASTy file, followed by four values:
275288
* - `MajorVersion: Int` - see definition in `TastyFormat`
276289
* - `MinorVersion: Int` - see definition in `TastyFormat`

0 commit comments

Comments
 (0)