Skip to content

Commit 7f51b39

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 0a689f2 commit 7f51b39

File tree

5 files changed

+12
-61
lines changed

5 files changed

+12
-61
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,14 +2272,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
22722272
def fullName: String = self.denot.fullName.toString
22732273
def pos: Position = self.sourcePos
22742274

2275-
def documentation: Option[Documentation] =
2275+
def docstring: Option[String] =
22762276
import dotc.core.Comments.CommentsContext
22772277
val docCtx = ctx.docCtx.getOrElse {
22782278
throw new RuntimeException(
22792279
"DocCtx could not be found and documentations are unavailable. This is a compiler-internal error."
22802280
)
22812281
}
2282-
docCtx.docstring(self)
2282+
docCtx.docstring(self).map(_.raw)
22832283

22842284
def tree: Tree = FromSymbol.definitionFromSym(self)
22852285

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

25932593
end report
25942594

2595-
type Documentation = dotc.core.Comments.Comment
2596-
2597-
object Documentation extends DocumentationModule
2598-
2599-
object DocumentationMethodsImpl extends DocumentationMethods:
2600-
extension (self: Documentation):
2601-
def raw: String = self.raw
2602-
def expanded: Option[String] = self.expanded
2603-
def usecases: List[(String, Option[DefDef])] =
2604-
self.usecases.map { uc => (uc.code, uc.tpdCode) }
2605-
end extension
2606-
end DocumentationMethodsImpl
2607-
26082595
private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] =
26092596
if tree.isEmpty then None else Some(tree)
26102597

library/src/scala/quoted/Quotes.scala

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
167167
*
168168
* +- Position
169169
*
170-
* +- Documentation
171-
*
172170
* +- Constant
173171
*
174172
* +- Symbol
@@ -3519,7 +3517,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
35193517
def pos: Position
35203518

35213519
/** The documentation for this symbol, if any */
3522-
def documentation: Option[Documentation]
3520+
def docstring: Option[String]
35233521

35243522
/** Tree of this definition
35253523
*
@@ -4180,39 +4178,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41804178
}
41814179

41824180

4183-
///////////////////
4184-
// DOCUMENTATION //
4185-
///////////////////
4186-
4187-
/** Attachment representing the documentation of a definition */
4188-
type Documentation <: AnyRef
4189-
4190-
/** Module object of `type Documentation` */
4191-
val Documentation: DocumentationModule
4192-
4193-
/** Methods of the module object `val Documentation` */
4194-
trait DocumentationModule { this: Documentation.type => }
4195-
4196-
/** Makes extension methods on `Documentation` available without any imports */
4197-
given DocumentationMethods: DocumentationMethods = DocumentationMethodsImpl
4198-
4199-
/** Implementation of extension methods on `Documentation` */
4200-
protected val DocumentationMethodsImpl: DocumentationMethods
4201-
4202-
/** Extension methods of `Documentation` */
4203-
trait DocumentationMethods {
4204-
extension (self: Documentation):
4205-
/** Raw documentation string */
4206-
def raw: String
4207-
4208-
/** Expanded documentation string, if any */
4209-
def expanded: Option[String]
4210-
4211-
/** List of usecases and their corresponding trees, if any */
4212-
def usecases: List[(String, Option[DefDef])]
4213-
4214-
end extension
4215-
}
42164181

42174182
///////////////
42184183
// 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)