Skip to content

Commit 4bbbcfc

Browse files
authored
Merge pull request #10340 from dotty-staging/load-stdlib
Scala3doc: fix issues with loading stdlib
2 parents 1fb2631 + 3f4b101 commit 4bbbcfc

File tree

7 files changed

+47
-11
lines changed

7 files changed

+47
-11
lines changed

.github/workflows/scala3doc.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
- name: Generate Scala 3 documentation
5858
run: ./project/scripts/sbt scala3doc/generateScala3Documentation
5959

60+
- name: Generate Scala 3 stdlib documentation
61+
run: ./project/scripts/sbt scala3doc/generateScala3StdlibDocumentation
62+
6063
- name: Generate documentation for example project using dotty-sbt
6164
run: ./project/scripts/sbt "sbt-dotty/scripted sbt-dotty/scala3doc"
6265

compiler/src/scala/quoted/internal/impl/QuoteContextImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,16 +2001,16 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, QuoteUnpickl
20012001

20022002
object TypeBounds extends TypeBoundsModule:
20032003
def apply(low: TypeRepr, hi: TypeRepr): TypeBounds = Types.TypeBounds(low, hi)
2004-
def unapply(x: TypeBounds): Option[(TypeRepr, TypeRepr)] = Some((x.low, x.hi))
2004+
def unapply(x: TypeBounds): Option[(TypeRepr, TypeRepr)] = Some((x.low.stripLazyRef, x.hi.stripLazyRef))
20052005
def empty: TypeBounds = Types .TypeBounds.empty
20062006
def upper(hi: TypeRepr): TypeBounds = Types .TypeBounds.upper(hi)
20072007
def lower(lo: TypeRepr): TypeBounds = Types .TypeBounds.lower(lo)
20082008
end TypeBounds
20092009

20102010
object TypeBoundsMethodsImpl extends TypeBoundsMethods:
20112011
extension (self: TypeBounds):
2012-
def low: TypeRepr = self.lo
2013-
def hi: TypeRepr = self.hi
2012+
def low: TypeRepr = self.lo.stripLazyRef
2013+
def hi: TypeRepr = self.hi.stripLazyRef
20142014
end extension
20152015
end TypeBoundsMethodsImpl
20162016

project/Build.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,9 @@ object Build {
11601160
val testcasesOutputDir = taskKey[String]("Root directory where tests classses are generated")
11611161
val testcasesSourceRoot = taskKey[String]("Root directory where tests sources are generated")
11621162
val generateSelfDocumentation = taskKey[Unit]("Generate example documentation")
1163+
// Note: the two tasks below should be one, but a bug in Tasty prevents that
11631164
val generateScala3Documentation = taskKey[Unit]("Generate documentation for dotty lib")
1165+
val generateScala3StdlibDocumentation = taskKey[Unit]("Generate documentation for Scala3 standard library")
11641166
val generateTestcasesDocumentation = taskKey[Unit]("Generate documentation for testcases, usefull for debugging tests")
11651167
lazy val `scala3doc` = project.in(file("scala3doc")).asScala3doc
11661168
lazy val `scala3doc-testcases` = project.in(file("scala3doc-testcases")).asScala3docTestcases
@@ -1506,15 +1508,24 @@ object Build {
15061508
(`scala3-interfaces`/Compile/products).value,
15071509
(`tasty-core-bootstrapped`/Compile/products).value,
15081510
(`scala3-library-bootstrapped`/Compile/products).value,
1509-
// TODO we can't load stdlib from Tasty
1510-
// (`stdlib-bootstrapped`/Compile/products).value,
15111511
).flatten
15121512

15131513
val roots = joinProducts(dottyJars)
15141514

15151515
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
15161516
else generateDocumentation(roots, "Scala 3", "scala3", "-p scala3doc/scala3-docs --projectLogo scala3doc/scala3-docs/logo.svg --revision master")
15171517
}.value,
1518+
1519+
generateScala3StdlibDocumentation:= Def.taskDyn {
1520+
val dottyJars: Seq[java.io.File] = Seq(
1521+
(`stdlib-bootstrapped`/Compile/products).value,
1522+
).flatten
1523+
1524+
val roots = joinProducts(dottyJars)
1525+
1526+
if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
1527+
else generateDocumentation(roots, "Scala 3", "scala3-stdlib", "-p scala3doc/scala3-docs --syntax wiki --projectLogo scala3doc/scala3-docs/logo.svg --revision master")
1528+
}.value,
15181529
generateTestcasesDocumentation := Def.taskDyn {
15191530
generateDocumentation(Build.testcasesOutputDir.in(Test).value, "Scala3doc testcases", "testcases", "--revision master")
15201531
}.value,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ trait TypesSupport:
104104
case r: Refinement => { //(parent, name, info)
105105
def getRefinementInformation(t: TypeRepr): List[TypeRepr] = t match {
106106
case r: Refinement => getRefinementInformation(r.parent) :+ r
107-
case tr: TypeRef => List(tr)
107+
case t => List(t)
108108
}
109109

110110
def getParamBounds(t: PolyType): List[JProjection] = commas(

scala3doc/src/dotty/dokka/tasty/comments/MemberLookup.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,19 @@ trait MemberLookup {
6464
import dotty.tools.dotc
6565
given dotc.core.Contexts.Context = rootContext.asInstanceOf
6666
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
67-
val members = sym.info.decls.iterator
67+
val members = sym.info.decls.iterator.filter(_.isCompleted)
6868
// println(s"members of ${sym.show} : ${members.map(_.show).mkString(", ")}")
6969
members.asInstanceOf[Iterator[Symbol]]
7070
}
7171

72+
private def hackIsNotAbsent(using QuoteContext)(rsym: qctx.reflect.Symbol) = {
73+
import qctx.reflect._
74+
import dotty.tools.dotc
75+
given dotc.core.Contexts.Context = rootContext.asInstanceOf
76+
val sym = rsym.asInstanceOf[dotc.core.Symbols.Symbol]
77+
sym.isCompleted
78+
}
79+
7280
private def localLookup(using QuoteContext)(query: String, owner: qctx.reflect.Symbol): Option[qctx.reflect.Symbol] = {
7381
import qctx.reflect._
7482

@@ -116,7 +124,7 @@ trait MemberLookup {
116124
else
117125
owner.tree match {
118126
case tree: ClassDef =>
119-
findMatch(tree.body.iterator.collect { case t: Definition => t.symbol })
127+
findMatch(tree.body.iterator.collect { case t: Definition if hackIsNotAbsent(t.symbol) => t.symbol })
120128
case _ =>
121129
findMatch(hackMembersOf(owner))
122130
}

scala3doc/src/dotty/dokka/tasty/comments/wiki/Converter.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,20 @@ class Converter(val repr: Repr) extends BaseConverter {
113113
resolveLinkQuery(target, Some(body).filter(!_.isEmpty))
114114
})
115115

116-
case _: (Superscript | Subscript | RepresentationLink | HtmlTag) =>
117-
sys.error("not yet supported: Superscript | Subscript | RepresentationLink | HtmlTag")
116+
case Superscript(i) =>
117+
def name = inl.getClass.getSimpleName
118+
println(s"WARN: not yet supported: $name")
119+
emitInline(i)
120+
121+
case Subscript(i) =>
122+
def name = inl.getClass.getSimpleName
123+
println(s"WARN: not yet supported: $name")
124+
emitInline(i)
125+
126+
case _: (RepresentationLink | HtmlTag) =>
127+
def name = inl.getClass.getSimpleName
128+
println(s"WARN: not yet supported: $name")
129+
name // doesn't compile if name is a val
118130
}
119131

120132
def convertInline(inl: Inline): Seq[dkkd.DocTag] =

scala3doc/test/dotty/dokka/tasty/comments/MemberLookupTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class LookupTestCases[Q <: QuoteContext](val q: QuoteContext) {
2222
)
2323

2424
cases.foreach { case (query, Sym(sym)) =>
25-
val Some((lookedUp, _)) = MemberLookup.lookupOpt(parseQuery(query), None)
25+
val lookupRes = MemberLookup.lookupOpt(parseQuery(query), None)
26+
assertTrue(s"Couldn't look up: $query", lookupRes.nonEmpty)
27+
val Some((lookedUp, _)) = lookupRes
2628
assertSame(query, sym, lookedUp)
2729
}
2830
}

0 commit comments

Comments
 (0)