Skip to content

Scala3doc: fix issues with loading stdlib #10340

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

Merged
merged 5 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/scala3doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
- name: Generate Scala 3 documentation
run: ./project/scripts/sbt scala3doc/generateScala3Documentation

- name: Generate Scala 3 stdlib documentation
run: ./project/scripts/sbt scala3doc/generateScala3StdlibDocumentation

- name: Generate documentation for example project using dotty-sbt
run: ./project/scripts/sbt "sbt-dotty/scripted sbt-dotty/scala3doc"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2001,16 +2001,16 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl

object TypeBounds extends TypeBoundsModule:
def apply(low: TypeRepr, hi: TypeRepr): TypeBounds = Types.TypeBounds(low, hi)
def unapply(x: TypeBounds): Option[(TypeRepr, TypeRepr)] = Some((x.low, x.hi))
def unapply(x: TypeBounds): Option[(TypeRepr, TypeRepr)] = Some((x.low.stripLazyRef, x.hi.stripLazyRef))
def empty: TypeBounds = Types .TypeBounds.empty
def upper(hi: TypeRepr): TypeBounds = Types .TypeBounds.upper(hi)
def lower(lo: TypeRepr): TypeBounds = Types .TypeBounds.lower(lo)
end TypeBounds

object TypeBoundsMethodsImpl extends TypeBoundsMethods:
extension (self: TypeBounds):
def low: TypeRepr = self.lo
def hi: TypeRepr = self.hi
def low: TypeRepr = self.lo.stripLazyRef
def hi: TypeRepr = self.hi.stripLazyRef
end extension
end TypeBoundsMethodsImpl

Expand Down
15 changes: 13 additions & 2 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,9 @@ object Build {
val testcasesOutputDir = taskKey[String]("Root directory where tests classses are generated")
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated")
val generateSelfDocumentation = taskKey[Unit]("Generate example documentation")
// Note: the two tasks below should be one, but a bug in Tasty prevents that
val generateScala3Documentation = taskKey[Unit]("Generate documentation for dotty lib")
val generateScala3StdlibDocumentation = taskKey[Unit]("Generate documentation for Scala3 standard library")
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests")
lazy val `scala3doc` = project.in(file("scala3doc")).asScala3doc
lazy val `scala3doc-testcases` = project.in(file("scala3doc-testcases")).asScala3docTestcases
Expand Down Expand Up @@ -1506,15 +1508,24 @@ object Build {
(`scala3-interfaces`/Compile/products).value,
(`tasty-core-bootstrapped`/Compile/products).value,
(`scala3-library-bootstrapped`/Compile/products).value,
// TODO we can't load stdlib from Tasty
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO we should leave this here until we will be able to generate stdlib togeter with rest of Scala3 jars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a similar comment above, where we define generateScala3StdlibDocumentation.

// (`stdlib-bootstrapped`/Compile/products).value,
).flatten

val roots = joinProducts(dottyJars)

if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
else generateDocumentation(roots, "Scala 3", "scala3", "-p scala3doc/scala3-docs --projectLogo scala3doc/scala3-docs/logo.svg --revision master")
}.value,

generateScala3StdlibDocumentation:= Def.taskDyn {
val dottyJars: Seq[java.io.File] = Seq(
Copy link
Contributor

Choose a reason for hiding this comment

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

it should be stdLibJars

(`stdlib-bootstrapped`/Compile/products).value,
).flatten

val roots = joinProducts(dottyJars)

if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
else generateDocumentation(roots, "Scala 3", "scala3-stdlib", "-p scala3doc/scala3-docs --syntax wiki --projectLogo scala3doc/scala3-docs/logo.svg --revision master")
}.value,
generateTestcasesDocumentation := Def.taskDyn {
generateDocumentation(Build.testcasesOutputDir.in(Test).value, "Scala3doc testcases", "testcases", "--revision master")
}.value,
Expand Down
2 changes: 1 addition & 1 deletion scala3doc/src/dotty/dokka/tasty/TypesSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ trait TypesSupport:
case r: Refinement => { //(parent, name, info)
def getRefinementInformation(t: TypeRepr): List[TypeRepr] = t match {
case r: Refinement => getRefinementInformation(r.parent) :+ r
case tr: TypeRef => List(tr)
case t => List(t)
}

def getParamBounds(t: PolyType): List[JProjection] = commas(
Expand Down
12 changes: 10 additions & 2 deletions scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@ trait MemberLookup {
import dotty.tools.dotc
given dotc.core.Contexts.Context = rootContext.asInstanceOf
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
val members = sym.info.decls.iterator
val members = sym.info.decls.iterator.filter(_.isCompleted)
// println(s"members of ${sym.show} : ${members.map(_.show).mkString(", ")}")
members.asInstanceOf[Iterator[Symbol]]
}

private def hackIsNotAbsent(using QuoteContext)(rsym: qctx.reflect.Symbol) = {
import qctx.reflect._
import dotty.tools.dotc
given dotc.core.Contexts.Context = rootContext.asInstanceOf
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
sym.isCompleted
}

private def localLookup(using QuoteContext)(query: String, owner: qctx.reflect.Symbol): Option[qctx.reflect.Symbol] = {
import qctx.reflect._

Expand Down Expand Up @@ -116,7 +124,7 @@ trait MemberLookup {
else
owner.tree match {
case tree: ClassDef =>
findMatch(tree.body.iterator.collect { case t: Definition => t.symbol })
findMatch(tree.body.iterator.collect { case t: Definition if hackIsNotAbsent(t.symbol) => t.symbol })
case _ =>
findMatch(hackMembersOf(owner))
}
Expand Down
16 changes: 14 additions & 2 deletions scala3doc/src/dotty/dokka/tasty/comments/wiki/Converter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,20 @@ class Converter(val repr: Repr) extends BaseConverter {
resolveLinkQuery(target, Some(body).filter(!_.isEmpty))
})

case _: (Superscript | Subscript | RepresentationLink | HtmlTag) =>
sys.error("not yet supported: Superscript | Subscript | RepresentationLink | HtmlTag")
case Superscript(i) =>
def name = inl.getClass.getSimpleName
println(s"WARN: not yet supported: $name")
emitInline(i)

case Subscript(i) =>
def name = inl.getClass.getSimpleName
println(s"WARN: not yet supported: $name")
emitInline(i)

case _: (RepresentationLink | HtmlTag) =>
def name = inl.getClass.getSimpleName
println(s"WARN: not yet supported: $name")
name // doesn't compile if name is a val
}

def convertInline(inl: Inline): Seq[dkkd.DocTag] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class LookupTestCases[Q <: QuoteContext](val q: QuoteContext) {
)

cases.foreach { case (query, Sym(sym)) =>
val Some((lookedUp, _)) = MemberLookup.lookupOpt(parseQuery(query), None)
val lookupRes = MemberLookup.lookupOpt(parseQuery(query), None)
assertTrue(s"Couldn't look up: $query", lookupRes.nonEmpty)
val Some((lookedUp, _)) = lookupRes
assertSame(query, sym, lookedUp)
}
}
Expand Down