Skip to content

Commit 0cf7a18

Browse files
authored
Use the new stdlib when generating scaladoc (#23744)
In this PR, we use the new stdlib project to generate the scaladoc and website of scala 3. The previous build used `scala2-library-bootstrapped` to fetch have tasty files available. We change this by now using the real, and to be, TASTy files for the stdlib. This changes will already take effect in the first run after the merge of this PR.
2 parents b768b22 + 30e6c3c commit 0cf7a18

File tree

4 files changed

+24
-90
lines changed

4 files changed

+24
-90
lines changed

.github/workflows/scaladoc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
- name: Compile and test
4545
run: |
4646
./project/scripts/sbt scaladoc/test
47+
./project/scripts/sbt dist/Universal/stage
4748
./project/scripts/cmdScaladocTests
4849
4950
- name: Locally publish self

project/Build.scala

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,7 @@ object Build {
31993199
}.value,
32003200

32013201
generateScalaDocumentation := Def.inputTaskDyn {
3202-
val majorVersion = (LocalProject("scala3-library-bootstrapped") / scalaBinaryVersion).value
3202+
val majorVersion = (`scala-library-bootstrapped` / scalaBinaryVersion).value
32033203

32043204
val extraArgs = spaceDelimited("[<output-dir>] [--justAPI]").parsed
32053205
val outputDirOverride = extraArgs.headOption.fold(identity[GenerationConfig](_))(newDir => {
@@ -3816,25 +3816,12 @@ object ScaladocConfigs {
38163816

38173817
def dottyExternalMapping = ".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/"
38183818
def javaExternalMapping = ".*java/.*::javadoc::https://docs.oracle.com/javase/8/docs/api/"
3819-
def scalaSrcLink(v: String, s: String) = s"${s}github://scala/scala/v$v#src/library"
3820-
def dottySrcLink(v: String, sourcesPrefix: String = "", outputPrefix: String = "") =
3821-
sys.env.get("GITHUB_SHA") match {
3822-
case Some(sha) =>
3823-
s"${sourcesPrefix}github://${sys.env("GITHUB_REPOSITORY")}/$sha$outputPrefix"
3824-
case None => s"${sourcesPrefix}github://scala/scala3/$v$outputPrefix"
3819+
def defaultSourceLinks(version: String) = {
3820+
def dottySrcLink(v: String) = sys.env.get("GITHUB_SHA") match {
3821+
case Some(sha) => s"github://scala/scala3/$sha"
3822+
case None => s"github://scala/scala3/$v"
38253823
}
3826-
3827-
def defaultSourceLinks(version: String = dottyNonBootstrappedVersion, refVersion: String = dottyVersion) = Def.task {
3828-
def stdLibVersion = stdlibVersion(NonBootstrapped)
3829-
def srcManaged(v: String, s: String) = s"out/bootstrap/scala2-library-bootstrapped/scala-$v/src_managed/main/$s-library-src"
3830-
SourceLinks(
3831-
List(
3832-
scalaSrcLink(stdLibVersion, srcManaged(version, "scala") + "="),
3833-
dottySrcLink(refVersion, "library/src=", "#library/src"),
3834-
dottySrcLink(refVersion),
3835-
"docs=github://scala/scala3/main#docs"
3836-
)
3837-
)
3824+
SourceLinks(List(dottySrcLink(version), "docs=github://scala/scala3/main#docs"))
38383825
}
38393826

38403827
lazy val DefaultGenerationSettings = Def.task {
@@ -3849,17 +3836,14 @@ object ScaladocConfigs {
38493836
def skipById = SkipById(List(
38503837
"scala.runtime.stdLibPatches",
38513838
"scala.runtime.MatchCase",
3852-
"dotty.tools.tasty",
3853-
"dotty.tools.tasty.util",
3854-
"dotty.tools.tasty.besteffort"
38553839
))
38563840
def projectFooter = ProjectFooter(s"Copyright (c) 2002-$currentYear, LAMP/EPFL")
38573841
def defaultTemplate = DefaultTemplate("static-site-main")
38583842
GenerationConfig(
38593843
List(),
38603844
ProjectVersion(projectVersion),
38613845
GenerateInkuire(true),
3862-
defaultSourceLinks().value,
3846+
defaultSourceLinks(version = dottyVersion),
38633847
skipByRegex,
38643848
skipById,
38653849
projectLogo,
@@ -3881,13 +3865,8 @@ object ScaladocConfigs {
38813865
)
38823866
}
38833867

3884-
lazy val DefaultGenerationConfig = Def.task {
3885-
def distLocation = (dist / Universal / stage).value
3886-
DefaultGenerationSettings.value
3887-
}
3888-
38893868
lazy val Scaladoc = Def.task {
3890-
DefaultGenerationConfig.value
3869+
DefaultGenerationSettings.value
38913870
.add(UseJavacp(true))
38923871
.add(ProjectName("scaladoc"))
38933872
.add(OutputDir("scaladoc/output/self"))
@@ -3898,7 +3877,7 @@ object ScaladocConfigs {
38983877

38993878
lazy val Testcases = Def.task {
39003879
val tastyRoots = (Test / Build.testcasesOutputDir).value
3901-
DefaultGenerationConfig.value
3880+
DefaultGenerationSettings.value
39023881
.add(UseJavacp(true))
39033882
.add(OutputDir("scaladoc/output/testcases"))
39043883
.add(ProjectName("scaladoc testcases"))
@@ -3914,56 +3893,35 @@ object ScaladocConfigs {
39143893
}
39153894

39163895
lazy val Scala3 = Def.task {
3917-
val dottyJars: Seq[java.io.File] = Seq(
3918-
(`scala2-library-bootstrapped`/Compile/products).value,
3919-
(`scala3-library-bootstrapped`/Compile/products).value,
3920-
(`scala3-interfaces`/Compile/products).value,
3921-
(`tasty-core-bootstrapped`/Compile/products).value,
3922-
).flatten
3923-
3924-
val roots = dottyJars.map(_.getAbsolutePath)
3925-
3926-
val managedSources =
3927-
(`scala2-library-bootstrapped`/Compile/sourceManaged).value / "scala-library-src"
3928-
val projectRoot = (ThisBuild/baseDirectory).value.toPath
3929-
val stdLibRoot = projectRoot.relativize(managedSources.toPath.normalize())
3930-
val docRootFile = stdLibRoot.resolve("rootdoc.txt")
3931-
3932-
val dottyManagesSources = (`scala3-library-bootstrapped`/Compile/baseDirectory).value
3933-
3934-
val tastyCoreSources = projectRoot.relativize((`tasty-core-bootstrapped`/Compile/scalaSource).value.toPath().normalize())
3935-
3936-
val dottyLibRoot = projectRoot.relativize(dottyManagesSources.toPath.normalize())
3937-
DefaultGenerationConfig.value
3896+
DefaultGenerationSettings.value
39383897
.add(ProjectName("Scala 3"))
39393898
.add(OutputDir(file("scaladoc/output/scala3").getAbsoluteFile.getAbsolutePath))
39403899
.add(Revision("main"))
39413900
.add(ExternalMappings(List(javaExternalMapping)))
3942-
.add(DocRootContent(docRootFile.toString))
3901+
.add(DocRootContent(((`scala-library-bootstrapped` / baseDirectory).value / "src" / "rootdoc.txt").toString))
39433902
.add(CommentSyntax(List(
3944-
s"${dottyLibRoot}=markdown",
3945-
s"${stdLibRoot}=wiki",
3946-
s"${tastyCoreSources}=markdown",
3903+
//s"${dottyLibRoot}=markdown",
3904+
//s"${stdLibRoot}=wiki",
39473905
"wiki"
39483906
)))
39493907
.add(VersionsDictionaryUrl("https://scala-lang.org/api/versions.json"))
39503908
.add(DocumentSyntheticTypes(true))
3951-
.add(SnippetCompiler(List(
3952-
s"$dottyLibRoot/src/scala=compile",
3953-
s"$dottyLibRoot/src/scala/compiletime=compile",
3954-
s"$dottyLibRoot/src/scala/util=compile",
3955-
s"$dottyLibRoot/src/scala/util/control=compile"
3956-
)))
3909+
//.add(SnippetCompiler(List(
3910+
//s"$dottyLibRoot/src/scala=compile",
3911+
//s"$dottyLibRoot/src/scala/compiletime=compile",
3912+
//s"$dottyLibRoot/src/scala/util=compile",
3913+
//s"$dottyLibRoot/src/scala/util/control=compile"
3914+
//)))
39573915
.add(SiteRoot("docs"))
39583916
.add(ApiSubdirectory(true))
3959-
.withTargets(roots)
3917+
.withTargets((`scala-library-bootstrapped` / Compile / products).value.map(_.getAbsolutePath))
39603918
}
39613919

39623920
def stableScala3(version: String) = Def.task {
39633921
val scalaLibrarySrc = s"out/bootstrap/scala2-library-bootstrapped/scala-$version-bin-SNAPSHOT-nonbootstrapped/src_managed"
39643922
val dottyLibrarySrc = "library/src"
39653923
Scala3.value
3966-
.add(defaultSourceLinks(version + "-bin-SNAPSHOT-nonbootstrapped", version).value)
3924+
.add(defaultSourceLinks(version = version))
39673925
.add(ProjectVersion(version))
39683926
.add(SnippetCompiler(
39693927
List(

scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ trait ClassLikeSupport:
140140
if summon[DocContext].args.generateInkuire then doInkuireStuff(classDef)
141141

142142
if signatureOnly then baseMember else baseMember.copy(
143-
members = classDef.extractPatchedMembers.sortBy(m => (m.name, m.kind.name)),
143+
members = classDef.extractMembers.sortBy(m => (m.name, m.kind.name)),
144144
selfType = selfType,
145145
companion = classDef.getCompanion
146146
)
@@ -278,31 +278,6 @@ trait ClassLikeSupport:
278278
inherited.flatMap(s => parseInheritedMember(c)(s))
279279
}
280280

281-
/** Extracts members while taking Dotty logic for patching the stdlib into account. */
282-
def extractPatchedMembers: Seq[Member] = {
283-
val ownMembers = c.extractMembers
284-
def extractPatchMembers(sym: Symbol) = {
285-
// NOTE for some reason scala.language$.experimental$ class doesn't show up here, so we manually add the name
286-
val ownMemberDRIs = ownMembers.iterator.map(_.name).toSet + "experimental$"
287-
sym.tree.asInstanceOf[ClassDef]
288-
.membersToDocument.filterNot(m => ownMemberDRIs.contains(m.symbol.name))
289-
.flatMap(parseMember(c))
290-
}
291-
c.symbol.fullName match {
292-
case "scala.Predef$" =>
293-
ownMembers ++
294-
extractPatchMembers(qctx.reflect.Symbol.requiredClass("scala.runtime.stdLibPatches.Predef$"))
295-
case "scala.language$" =>
296-
ownMembers ++
297-
extractPatchMembers(qctx.reflect.Symbol.requiredModule("scala.runtime.stdLibPatches.language").moduleClass)
298-
case "scala.language$.experimental$" =>
299-
ownMembers ++
300-
extractPatchMembers(qctx.reflect.Symbol.requiredModule("scala.runtime.stdLibPatches.language.experimental").moduleClass)
301-
case _ => ownMembers
302-
}
303-
304-
}
305-
306281
def getTreeOfFirstParent: Option[Tree] =
307282
c.getParentsAsTreeSymbolTuples.headOption.map(_._1)
308283

scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ case class ScaladocTastyInspector()(using ctx: DocContext) extends Inspector:
135135
def mergeAnyRefAliasAndObject(parser: TastyParser) =
136136
import parser.qctx.reflect._
137137
val javaLangObjectDef = defn.ObjectClass.tree.asInstanceOf[ClassDef]
138-
val objectMembers = parser.extractPatchedMembers(javaLangObjectDef)
138+
val objectMembers = javaLangObjectDef.extractMembers
139139
val aM = parser.parseTypeDef(
140140
defn.AnyRefClass.tree.asInstanceOf[TypeDef],
141141
defn.AnyClass.tree.asInstanceOf[ClassDef],

0 commit comments

Comments
 (0)