Skip to content

Commit a082b5a

Browse files
committed
Decouple source and TASTY frontend in dottydoc
1 parent 0f5b5ed commit a082b5a

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class ReadTastyTreesFromClasses extends FrontEnd {
4545
else {
4646
val unit = mkCompilationUnit(cls, cls.tree, forceTrees = true)
4747
unit.pickled += (cls -> unpickler.unpickler.bytes)
48+
if (ctx.settings.YcookComments.value) {
49+
ctx.typer.cookComments(cls.tree, cls)
50+
}
4851
Some(unit)
4952
}
5053
case tree: Tree[_] =>
@@ -72,5 +75,7 @@ class ReadTastyTreesFromClasses extends FrontEnd {
7275
case _ =>
7376
cannotUnpickle(s"no class file was found")
7477
}
78+
case unit =>
79+
Some(unit)
7580
}
7681
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import ast.tpd
88

99
trait Docstrings { self: Typer =>
1010

11+
/**
12+
* Expands or cooks the documentation for all members of `cdef`.
13+
*
14+
* @see Docstrings#cookComment
15+
*/
16+
def cookComments(cdef: tpd.Tree, cls: ClassSymbol)(implicit ctx: Context): Unit = {
17+
// val cls = cdef.symbol
18+
val cookingCtx = ctx.localContext(cdef, cls).setNewScope
19+
cls.info.allMembers.foreach { member =>
20+
cookComment(member.symbol, cls)(cookingCtx)
21+
}
22+
cookComment(cls, cls)(cookingCtx)
23+
}
24+
1125
/**
1226
* Expands or cooks the documentation for `sym` in class `owner`.
1327
* The expanded comment will directly replace the original comment in the doc context.

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,15 +1568,6 @@ class Typer extends Namer
15681568
val body1 = addAccessorDefs(cls,
15691569
typedStats(impl.body, dummy)(ctx.inClassContext(self1.symbol)))
15701570

1571-
// Expand comments and type usecases if `-Ycook-comments` is set.
1572-
if (ctx.settings.YcookComments.value) {
1573-
val cookingCtx = ctx.localContext(cdef, cls).setNewScope
1574-
body1.foreach { stat =>
1575-
cookComment(stat.symbol, self1.symbol)(cookingCtx)
1576-
}
1577-
cookComment(cls, cls)(cookingCtx)
1578-
}
1579-
15801571
checkNoDoubleDeclaration(cls)
15811572
val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1)
15821573
.withType(dummy.termRef)
@@ -1601,6 +1592,12 @@ class Typer extends Namer
16011592

16021593
if (ctx.settings.YretainTrees.value) cls.treeOrProvider = cdef1
16031594

1595+
// Expand comments and type usecases if `-Ycook-comments` is set.
1596+
if (ctx.settings.YcookComments.value) {
1597+
cookComments(cdef1, cls)
1598+
}
1599+
1600+
16041601
cdef1
16051602

16061603
// todo later: check that

doc-tool/src/dotty/tools/dottydoc/DocCompiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class DocCompiler extends Compiler {
3434
}
3535

3636
override protected def frontendPhases: List[List[Phase]] =
37-
List(new DocFrontEnd) :: Nil
37+
List(new ReadTastyTreesFromClasses) ::
38+
List(new DocFrontEnd) :: Nil
3839

3940
override protected def picklerPhases: List[List[Phase]] =
4041
Nil

doc-tool/src/dotty/tools/dottydoc/DocFrontEnd.scala

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,8 @@ import util.syntax.ContextWithContextDottydoc
2020
class DocFrontEnd extends FrontEnd {
2121

2222
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
23-
if (ctx.settings.fromTasty.value) {
24-
val fromTastyFrontend = new ReadTastyTreesFromClasses
25-
val unpickledUnits = fromTastyFrontend.runOn(units)
26-
27-
val typer = new Typer()
28-
if (ctx.settings.YcookComments.value) {
29-
ctx.docbase.docstrings.keys.foreach { sym =>
30-
val owner = sym.owner
31-
val cookingCtx = ctx.withOwner(owner)
32-
typer.cookComment(sym, owner)(cookingCtx)
33-
}
34-
}
35-
36-
unpickledUnits
37-
} else {
38-
super.runOn(units)
39-
}
23+
if (ctx.settings.fromTasty.value) units
24+
else super.runOn(units)
4025
}
4126

4227
override protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) =

0 commit comments

Comments
 (0)