Skip to content

Commit 1b37761

Browse files
committed
Fixes to inlining untyped trees
1 parent 4624eb2 commit 1b37761

File tree

14 files changed

+187
-124
lines changed

14 files changed

+187
-124
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class TreeTypeMap(
126126
override def transformStats(trees: List[tpd.Tree])(implicit ctx: Context) =
127127
transformDefs(trees)._2
128128

129-
private def transformDefs[TT <: tpd.Tree](trees: List[TT])(implicit ctx: Context): (TreeTypeMap, List[TT]) = {
129+
def transformDefs[TT <: tpd.Tree](trees: List[TT])(implicit ctx: Context): (TreeTypeMap, List[TT]) = {
130130
val tmap = withMappedSyms(tpd.localSyms(trees))
131131
(tmap, tmap.transformSub(trees))
132132
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,9 @@ object Flags {
575575
/** An accessor or label */
576576
final val AccessorOrLabel = Accessor | Label
577577

578+
/** An accessor or a synthetic symbol */
579+
final val AccessorOrSynthetic = Accessor | Synthetic
580+
578581
/** A synthetic or private definition */
579582
final val SyntheticOrPrivate = Synthetic | Private
580583

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ object SymDenotations {
783783

784784
def isSkolem: Boolean = name == nme.SKOLEM
785785

786-
def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = Accessor)
786+
def isInlineMethod(implicit ctx: Context): Boolean = is(InlineMethod, butNot = AccessorOrSynthetic)
787787

788788
/** ()T and => T types should be treated as equivalent for this symbol.
789789
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ object Types {
18251825

18261826
private def setDenot(denot: Denotation)(implicit ctx: Context): Unit = {
18271827
if (ctx.isAfterTyper)
1828-
assert(!denot.isOverloaded, this)
1828+
assert(!denot.isOverloaded || ctx.mode.is(Mode.Printing), this)
18291829
if (Config.checkNoDoubleBindings)
18301830
if (ctx.settings.YnoDoubleBindings.value)
18311831
checkSymAssign(denot.symbol)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ object TastyFormat {
309309
final val MACRO = 33
310310
final val ERASED = 34
311311
final val PARAMsetter = 35
312+
final val EMPTYTREE = 36
312313

313314
// Cat. 2: tag Nat
314315

@@ -444,7 +445,7 @@ object TastyFormat {
444445

445446
/** Useful for debugging */
446447
def isLegalTag(tag: Int) =
447-
firstSimpleTreeTag <= tag && tag <= PARAMsetter ||
448+
firstSimpleTreeTag <= tag && tag <= EMPTYTREE ||
448449
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
449450
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
450451
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -539,6 +540,7 @@ object TastyFormat {
539540
case DEFAULTparameterized => "DEFAULTparameterized"
540541
case STABLE => "STABLE"
541542
case PARAMsetter => "PARAMsetter"
543+
case EMPTYTREE => "EMPTYTREE"
542544

543545
case SHAREDterm => "SHAREDterm"
544546
case SHAREDtype => "SHAREDtype"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ class TreePickler(pickler: TastyPickler) {
857857
writeByte(TYPEDSPLICE)
858858
withLength { pickleTree(splice) }
859859
case Thicket(trees) =>
860-
trees.foreach(pickleUntyped)
860+
if (trees.isEmpty) writeByte(EMPTYTREE)
861+
else trees.foreach(pickleUntyped)
861862
case _ =>
862863
pickleUntyped(desugar(tree))
863864
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,12 @@ class TreeUnpickler(reader: TastyReader,
627627
val end = readEnd()
628628
val tp = readType()
629629
val lazyAnnotTree = readLater(end, rdr => ctx => rdr.readTerm()(ctx))
630-
Annotation.deferredSymAndTree(
631-
implicit ctx => tp.typeSymbol,
632-
implicit ctx => lazyAnnotTree.complete)
630+
if (tp.isRef(defn.BodyAnnot))
631+
LazyBodyAnnotation(implicit ctx => lazyAnnotTree.complete)
632+
else
633+
Annotation.deferredSymAndTree(
634+
implicit ctx => tp.typeSymbol,
635+
implicit ctx => lazyAnnotTree.complete)
633636
}
634637

635638
/** Create symbols for the definitions in the statement sequence between
@@ -1239,8 +1242,11 @@ class TreeUnpickler(reader: TastyReader,
12391242
untpd.ByNameTypeTree(readUntyped())
12401243
case NAMEDARG =>
12411244
untpd.NamedArg(readName(), readUntyped())
1245+
case EMPTYTREE =>
1246+
untpd.EmptyTree
12421247
case SHAREDtype =>
1243-
assert(readNat() == 0)
1248+
val b = readNat()
1249+
assert(b == 0, i"bad shared type $b at $currentAddr when reading ${ctx.owner.ownersIterator.toList}%, %")
12441250
untpd.TypeTree()
12451251
case _ =>
12461252
untpd.Literal(readConstant(tag))
@@ -1275,7 +1281,7 @@ class TreeUnpickler(reader: TastyReader,
12751281
case ASSIGN =>
12761282
untpd.Assign(readUntyped(), readUntyped())
12771283
case BLOCK =>
1278-
val expr = ifBefore(end)(readUntyped(), untpd.EmptyTree)
1284+
val expr = readUntyped()
12791285
val stats = until(end)(readUntyped())
12801286
untpd.Block(stats, expr)
12811287
case IF =>
@@ -1346,7 +1352,11 @@ class TreeUnpickler(reader: TastyReader,
13461352
untpd.TypedSplice(readTerm())
13471353
case FUNCTION =>
13481354
val body = readUntyped()
1349-
val params = until(end)(readUntyped())
1355+
import untpd.modsDeco
1356+
val params = until(end)(readUntyped()).map {
1357+
case param: untpd.ValDef => param.withMods(param.mods | Param)
1358+
case param => param
1359+
}
13501360
untpd.Function(params, body)
13511361
case INFIXOP =>
13521362
untpd.InfixOp(readUntyped(), readIdent(), readUntyped())

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
169169
}
170170

171171
homogenize(tp) match {
172-
case x: ConstantType if homogenizedView =>
173-
return toText(x.widen)
174172
case AppliedType(tycon, args) =>
175173
val cls = tycon.typeSymbol
176174
if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ "*"
@@ -617,7 +615,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
617615
}
618616

619617
private def toTextOwner(tree: Tree[_]) =
620-
"[owner = " ~ tree.symbol.owner.show ~ "]" provided ctx.settings.YprintDebugOwners.value
618+
"[owner = " ~ tree.symbol.maybeOwner.show ~ "]" provided ctx.settings.YprintDebugOwners.value
621619

622620
protected def dclTextOr[T >: Untyped](tree: Tree[T])(treeText: => Text) =
623621
toTextOwner(tree) ~ {

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
597597
// tree of the method as part of the signature we send to sbt.
598598
// To do this properly we would need a way to hash trees and types in
599599
// dotty itself.
600-
annots += marker(Inliner.bodyToInline(s).show)
600+
val printTypesCtx = ctx.fresh.setSetting(ctx.settings.XprintTypes, true)
601+
annots += marker(Inliner.bodyToInline(s).show(printTypesCtx))
601602
}
602603

603604
// In the Scala2 ExtractAPI phase we only extract annotations that extend

0 commit comments

Comments
 (0)