Skip to content

Commit fb098d6

Browse files
committed
Decouple source and TASTY frontend in dottydoc
1 parent 3691edb commit fb098d6

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
@@ -1563,15 +1563,6 @@ class Typer extends Namer
15631563
val body1 = addAccessorDefs(cls,
15641564
typedStats(impl.body, dummy)(ctx.inClassContext(self1.symbol)))
15651565

1566-
// Expand comments and type usecases if `-Ycook-comments` is set.
1567-
if (ctx.settings.YcookComments.value) {
1568-
val cookingCtx = ctx.localContext(cdef, cls).setNewScope
1569-
body1.foreach { stat =>
1570-
cookComment(stat.symbol, self1.symbol)(cookingCtx)
1571-
}
1572-
cookComment(cls, cls)(cookingCtx)
1573-
}
1574-
15751566
checkNoDoubleDeclaration(cls)
15761567
val impl1 = cpy.Template(impl)(constr1, parents1, self1, body1)
15771568
.withType(dummy.termRef)
@@ -1593,6 +1584,12 @@ class Typer extends Namer
15931584

15941585
if (ctx.settings.YretainTrees.value) cls.treeOrProvider = cdef1
15951586

1587+
// Expand comments and type usecases if `-Ycook-comments` is set.
1588+
if (ctx.settings.YcookComments.value) {
1589+
cookComments(cdef1, cls)
1590+
}
1591+
1592+
15961593
cdef1
15971594

15981595
// 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)