Skip to content

Commit eae6d18

Browse files
committed
Remove Documentation from Tasty Reflect
Nothing but the .raw field is set when we load documentation from Tasty. It doesn't make sense to expose Documentation as a separate data type.
1 parent e1166a0 commit eae6d18

File tree

5 files changed

+12
-58
lines changed

5 files changed

+12
-58
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,14 +2316,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
23162316
def pos: Option[Position] =
23172317
if self.exists then Some(self.sourcePos) else None
23182318

2319-
def documentation: Option[Documentation] =
2319+
def docstring: Option[String] =
23202320
import dotc.core.Comments.CommentsContext
23212321
val docCtx = ctx.docCtx.getOrElse {
23222322
throw new RuntimeException(
23232323
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
23242324
)
23252325
}
2326-
docCtx.docstring(self)
2326+
docCtx.docstring(self).map(_.raw)
23272327

23282328
def tree: Tree = FromSymbol.definitionFromSym(self)
23292329

@@ -2652,19 +2652,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26522652

26532653
end report
26542654

2655-
type Documentation = dotc.core.Comments.Comment
2656-
2657-
object Documentation extends DocumentationModule
2658-
2659-
given DocumentationMethods: DocumentationMethods with
2660-
extension (self: Documentation):
2661-
def raw: String = self.raw
2662-
def expanded: Option[String] = self.expanded
2663-
def usecases: List[(String, Option[DefDef])] =
2664-
self.usecases.map { uc => (uc.code, uc.tpdCode) }
2665-
end extension
2666-
end DocumentationMethods
2667-
26682655
private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
26692656
if tree.isEmpty then None else Some(tree)
26702657

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
174174
*
175175
* +- SourceFile
176176
*
177-
* +- Documentation
178-
*
179177
* +- Constant
180178
*
181179
* +- Symbol
@@ -3089,7 +3087,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
30893087
def pos: Option[Position]
30903088

30913089
/** The documentation for this symbol, if any */
3092-
def documentation: Option[Documentation]
3090+
def docstring: Option[String]
30933091

30943092
/** Tree of this definition
30953093
*
@@ -3752,36 +3750,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
37523750
}
37533751

37543752

3755-
///////////////////
3756-
// DOCUMENTATION //
3757-
///////////////////
3758-
3759-
/** Attachment representing the documentation of a definition */
3760-
type Documentation <: AnyRef
3761-
3762-
/** Module object of `type Documentation` */
3763-
val Documentation: DocumentationModule
3764-
3765-
/** Methods of the module object `val Documentation` */
3766-
trait DocumentationModule { this: Documentation.type => }
3767-
3768-
/** Makes extension methods on `Documentation` available without any imports */
3769-
given DocumentationMethods: DocumentationMethods
3770-
3771-
/** Extension methods of `Documentation` */
3772-
trait DocumentationMethods {
3773-
extension (self: Documentation):
3774-
/** Raw documentation string */
3775-
def raw: String
3776-
3777-
/** Expanded documentation string, if any */
3778-
def expanded: Option[String]
3779-
3780-
/** List of usecases and their corresponding trees, if any */
3781-
def usecases: List[(String, Option[DefDef])]
3782-
3783-
end extension
3784-
}
37853753

37863754
///////////////
37873755
// UTILS //

scala3doc/src/dotty/dokka/tasty/BasicSupport.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ trait BasicSupport:
3434

3535

3636
extension (sym: Symbol):
37-
def documentation = sym.documentation match
38-
case Some(comment) =>
39-
Map(ctx.sourceSet -> parseComment(comment, sym.tree))
37+
def documentation = sym.docstring match
38+
case Some(docstring) =>
39+
Map(ctx.sourceSet -> parseComment(docstring, sym.tree))
4040
case None =>
4141
Map.empty
4242

scala3doc/src/dotty/dokka/tasty/ScalaDocSupport.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ trait ScaladocSupport { self: TastyParser =>
1212
import qctx.reflect._
1313

1414
def parseComment(
15-
commentPre: Documentation,
15+
docstring: String,
1616
tree: Tree
1717
): dkkd.DocumentationNode = {
18-
val commentNode =
18+
val commentString: String =
1919
if tree.symbol.isClassDef || tree.symbol.owner.isClassDef then
2020
import dotty.tools.dotc
2121
given ctx: dotc.core.Contexts.Context = qctx.asInstanceOf[scala.quoted.runtime.impl.QuotesImpl].ctx
2222

2323
val sym = tree.symbol.asInstanceOf[dotc.core.Symbols.Symbol]
2424

2525
comments.CommentExpander.cookComment(sym)(using ctx)
26-
.get.asInstanceOf[Documentation]
26+
.get.expanded.get
2727
else
28-
commentPre
28+
docstring
2929

30-
val commentString = commentNode.expanded getOrElse commentNode.raw
3130
val preparsed =
3231
comments.Preparser.preparse(comments.Cleaner.clean(commentString))
3332

tests/run-custom-args/tasty-inspector/tasty-documentation-inspector/Test.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class DocumentationInspector extends TastyInspector {
2121

2222
override def traverseTree(tree: Tree)(owner: Symbol): Unit = tree match {
2323
case tree: Definition =>
24-
tree.symbol.documentation match {
25-
case Some(doc) => println(doc.raw)
24+
tree.symbol.docstring match {
25+
case Some(doc) => println(doc)
2626
case None => println()
2727
}
2828
super.traverseTree(tree)(owner)

0 commit comments

Comments
 (0)