Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support -from-tasty in Dottydoc #4789

Merged
merged 16 commits into from
Sep 4, 2018

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Jul 13, 2018

It's not yet integrated with the doc task in sbt, but I think this can be reviewed independently first.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed only compiler and phases. Will do the rest later.

try fn(temp)
finally {
val allFiles = getAll(temp, "glob:**").sortBy(_.toAbsolutePath.toString).reverse
allFiles.foreach(Files.delete(_))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dotty.tools.io.Path.deleteRecursively, it does it more efficiently.

val paths = Files.walk(base)
val matcher = FileSystems.getDefault.getPathMatcher(pattern)
try paths.filter(matcher.matches).iterator().asScala.toList
finally paths.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotty.tools.io.Directory.walkFilter does something similar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may not need IOUtils at all


override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
if (ctx.settings.fromTasty.value) {
val fromTastyFrontend = new ReadTastyTreesFromClasses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A front end should probably not be in another frontend. DocCompiler should choose between DocFrontEnd or ReadTastyTreesFromClasses based on ctx.settings.fromTasty.value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wanted to decouple everything, but I ran into issues when cooking the comments. I'll investigate a bit more.


val typer = new Typer()
if (ctx.settings.YcookComments.value) {
ctx.docbase.docstrings.keys.foreach { sym =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this should probably be in it's own phase. Which would be added conditionally based on ctx.settings.YcookComments.value.

val fromTastyFrontend = new ReadTastyTreesFromClasses
val unpickledUnits = fromTastyFrontend.runOn(units)

val typer = new Typer()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to initialize Typer if ctx.settings.YcookComments.value is false

@@ -27,20 +24,20 @@ class DocASTPhase extends Phase {
def phaseName = "docASTPhase"

/** Build documentation hierarchy from existing tree */
def collect(tree: Tree)(implicit ctx: Context): Entity = {
def collect(tree: Tree)(implicit ctx: Context): List[Entity] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change Entity to List[Entity]?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see there are only lists of size 0 or 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's to support multiple @usecase. See the commit messages of c528d6a and f1da1e1

This is where longer lists may be created: https://github.com/lampepfl/dotty/pull/4789/files#diff-5a9874880800484ed4b082c8d776c661R30

@Duhemm Duhemm force-pushed the topic/dottydoc-from-tasty branch from 8411a66 to fb098d6 Compare August 2, 2018 14:23
@nicolasstucki
Copy link
Contributor

test performance please

@dottybot
Copy link
Member

dottybot commented Aug 6, 2018

performance test scheduled: 1 job(s) in queue, 0 running.

@nicolasstucki nicolasstucki dismissed their stale review August 6, 2018 08:19

The changes have been done

@nicolasstucki
Copy link
Contributor

@Duhemm is this still WIP?

@dottybot
Copy link
Member

dottybot commented Aug 6, 2018

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/4789/ to see the changes.

Benchmarks is based on merging with master (f39943d)

@Duhemm
Copy link
Contributor Author

Duhemm commented Aug 15, 2018

@nicolasstucki I think it's ready for another pass! Thanks for taking a look.

Dottydoc can now be used in one of two ways:

 - By receiving a list of source files that will be parsed, typed, and
   for which the documentation will be generated
 - When `-from-tasty` is set, by receiving a list of fully qualified
   class names. The trees will be unpickled and the documentation will
   be generated.
We're not reusing the PositionPickler for this task, because it is very
tied to pickling the positions of `Tree`s, which `Comment`s are not.

We simply pickle the coordinates of the comment, and reconstruct the
position from the coordinates when unpickling.
The comments are now always pickled as raw comments, as seen in the
source file. It's the job of Dotty doc to trigger expansion of the
comments after they are unpickled.

This approach simplifies incremental generation of the documentation, as
we don't need to teach Zinc how to extract dependencies in the
documentation.
The `@sourcefile` annotation is added to symbols when they're unpickled
from TASTY, and we need to remove them so that they do not appear when
generating the documentation.
This special entity was used to mean that an entity needs to be removed
from the doc AST after the transformation. Instead, we refactor the
DocMiniPhases to have them return a `List[Entity]` (rather than a single
`Entity`, as before).

It follows that removing an entity from the AST means returning an empty
list after transformation.

This change will be necessary to be able to support multiple `@usecase`
sections in the documentation, because it means that the transformation
has to introduce multiple `Entity`-es.
In the documentation, it is possible to have several `@usecase`
sections, which means that each of these section should be displayed as
a separate member in the documentation. So far, Dottydoc was only
considering the first `@usecase` section and was disregarding the
others.

This commit fixes that, and generates a new member for each of the
usecases.

Fixes scala#4752
This miniphase is used to cook the comments when `-Ycook-comments` is
set. This phase is used by the compiler, the REPL, Dotty IDE and
Dottydoc.
@Duhemm Duhemm force-pushed the topic/dottydoc-from-tasty branch from 6c4ea62 to 0cd20b4 Compare September 4, 2018 08:24
@Duhemm
Copy link
Contributor Author

Duhemm commented Sep 4, 2018

@nicolasstucki Rebased and ready for another round 😄

@nicolasstucki nicolasstucki assigned Duhemm and unassigned nicolasstucki Sep 4, 2018
@@ -42,7 +36,9 @@ object factories {
}

def annotations(sym: Symbol)(implicit ctx: Context): List[String] =
sym.annotations.map(_.symbol.showFullName)
sym.annotations.collect {
case ann if ann.symbol != ctx.definitions.SourceFileAnnot => ann.symbol.showFullName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is specific to SourceFileAnnot. We have a bunch of internal annotation that shouldn't be shown in the doc. Maybe !ann.symbol.is(Synthetic) would discard these annotations. Not sure...

@@ -196,13 +194,16 @@ class ReplCompiler extends Compiler {
val stat = stats.last.asInstanceOf[tpd.Tree]
if (stat.tpe.isError) stat.tpe.show
else {
val docCtx = ctx.docCtx.get
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docCtx is now optional in the REPL?

@@ -23,7 +23,7 @@ class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Option[Addr]
buf.writeAddr(addr)
buf.writeNat(length)
buf.writeBytes(bytes, length)
buf.writeByte(if (cmt.isExpanded) 1 else 0)
buf.writeLongInt(cmt.pos.coords)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarter TASTY version bump?

@Duhemm Duhemm merged commit e02c785 into scala:master Sep 4, 2018
@Blaisorblade Blaisorblade deleted the topic/dottydoc-from-tasty branch September 7, 2018 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants