-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
5e37d73
to
8411a66
Compare
There was a problem hiding this 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(_)) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 => |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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] = { |
There was a problem hiding this comment.
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]
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
8411a66
to
fb098d6
Compare
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
@Duhemm is this still WIP? |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/4789/ to see the changes. Benchmarks is based on merging with master (f39943d) |
@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.
6c4ea62
to
0cd20b4
Compare
@nicolasstucki Rebased and ready for another round 😄 |
@@ -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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smarter TASTY version bump?
It's not yet integrated with the
doc
task in sbt, but I think this can be reviewed independently first.