Skip to content
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

Fix links to unexisting types sites #13917

Merged
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
20 changes: 11 additions & 9 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,11 @@ object Build {

private lazy val currentYear: String = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR).toString

lazy val scalacOptionsDocSettings = Seq(
"-external-mappings:" +
".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," +
".*java/.*::javadoc::https://docs.oracle.com/javase/8/docs/api/",
def scalacOptionsDocSettings(includeExternalMappings: Boolean = true) = {
Copy link
Member

Choose a reason for hiding this comment

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

Is this part needed for this fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because by default we were adding a external mapping to dotty.epfl.ch in Scala documentation. Our mechanism to resolve links tries to match external mapping for symbols that are not present in docs. Since the private API was not present in docs, Scaladoc matched external mapping for it and generated unexisting link

Copy link
Member

Choose a reason for hiding this comment

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

ok, makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it a general problem? I mean, maybe we should not try to match any link for members that are private, not workaround it this way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's why I introduced changes with filtering symbols that shouldn't be visible. Maybe we should once more go through whole code that gathers symbols and check if we filter all symbols correctly.

I removed the external link to dotty because it was redundant and should never be there.

val extMap = Seq("-external-mappings:" +
(if (includeExternalMappings) ".*scala/.*::scaladoc3::https://dotty.epfl.ch/api/," else "") +
".*java/.*::javadoc::https://docs.oracle.com/javase/8/docs/api/")
Seq(
"-skip-by-regex:.+\\.internal($|\\..+)",
"-skip-by-regex:.+\\.impl($|\\..+)",
"-project-logo", "docs/logo.svg",
Expand All @@ -340,7 +341,8 @@ object Build {
"-project-footer", s"Copyright (c) 2002-$currentYear, LAMP/EPFL",
"-author",
"-groups"
)
) ++ extMap
}

// Settings used when compiling dotty with a non-bootstrapped dotty
lazy val commonBootstrappedSettings = commonDottySettings ++ NoBloopExport.settings ++ Seq(
Expand Down Expand Up @@ -423,7 +425,7 @@ object Build {
assert(docScalaInstance.loaderCompilerOnly == base.loaderCompilerOnly)
docScalaInstance
},
Compile / doc / scalacOptions ++= scalacOptionsDocSettings
Compile / doc / scalacOptions ++= scalacOptionsDocSettings()
)

lazy val commonBenchmarkSettings = Seq(
Expand Down Expand Up @@ -1266,7 +1268,7 @@ object Build {
libraryDependencies += ("org.scala-js" %%% "scalajs-dom" % "1.1.0").cross(CrossVersion.for3Use2_13)
)

def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil) =
def generateDocumentation(targets: Seq[String], name: String, outDir: String, ref: String, params: Seq[String] = Nil, includeExternalMappings: Boolean = true) =
Def.taskDyn {
val distLocation = (dist / pack).value
val projectVersion = version.value
Expand Down Expand Up @@ -1294,7 +1296,7 @@ object Build {
dottySrcLink(referenceVersion, srcManaged(dottyNonBootstrappedVersion, "dotty") + "=", "#library/src"),
dottySrcLink(referenceVersion),
"-Ygenerate-inkuire",
) ++ scalacOptionsDocSettings ++ revision ++ params ++ targets
) ++ scalacOptionsDocSettings(includeExternalMappings) ++ revision ++ params ++ targets
import _root_.scala.sys.process._
val escapedCmd = cmd.map(arg => if(arg.contains(" ")) s""""$arg"""" else arg)
Def.task {
Expand Down Expand Up @@ -1424,7 +1426,7 @@ object Build {
"https://scala-lang.org/api/versions.json",
"-Ydocument-synthetic-types",
s"-snippet-compiler:${dottyLibRoot}/scala/quoted=compile,${dottyLibRoot}/scala/compiletime=compile"
) ++ (if (justAPI) Nil else Seq("-siteroot", "docs-for-dotty-page", "-Yapi-subdirectory")))
) ++ (if (justAPI) Nil else Seq("-siteroot", "docs-for-dotty-page", "-Yapi-subdirectory")), includeExternalMappings = false)

if (dottyJars.isEmpty) Def.task { streams.value.log.error("Dotty lib wasn't found") }
else if (justAPI) generateDocTask
Expand Down
24 changes: 13 additions & 11 deletions scaladoc/src/dotty/tools/scaladoc/tasty/ClassLikeSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ trait ClassLikeSupport:
case tree: ClassDef => tree
case tt: TypeTree => unpackTreeToClassDef(tt.tpe.typeSymbol.tree)

def getSupertypesGraph(classDef: Tree, link: LinkToType): Seq[(LinkToType, LinkToType)] =
val smbl = classDef.symbol
val parents = unpackTreeToClassDef(classDef).parents
parents.flatMap { case tree =>
def getSupertypesGraph(link: LinkToType, to: Seq[Tree]): Seq[(LinkToType, LinkToType)] =
to.flatMap { case tree =>
val symbol = if tree.symbol.isClassConstructor then tree.symbol.owner else tree.symbol
val superLink = LinkToType(tree.asSignature, symbol.dri, bareClasslikeKind(symbol))
Seq(link -> superLink) ++ getSupertypesGraph(tree, superLink)
val nextTo = unpackTreeToClassDef(tree).parents
if symbol.isHiddenByVisibility then getSupertypesGraph(link, nextTo)
else Seq(link -> superLink) ++ getSupertypesGraph(superLink, nextTo)
}

val supertypes = getSupertypes(using qctx)(classDef).map {
case (symbol, tpe) =>
LinkToType(tpe.asSignature, symbol.dri, bareClasslikeKind(symbol))
}
val supertypes = getSupertypes(using qctx)(classDef)
.filterNot((s, t) => s.isHiddenByVisibility)
.map {
case (symbol, tpe) =>
LinkToType(tpe.asSignature, symbol.dri, bareClasslikeKind(symbol))
}
val selfType = classDef.self.map { (valdef: ValDef) =>
val symbol = valdef.symbol
val tpe = valdef.tpt.tpe
Expand All @@ -91,7 +93,7 @@ trait ClassLikeSupport:
val selfSignature: DSignature = typeForClass(classDef).asSignature

val graph = HierarchyGraph.withEdges(
getSupertypesGraph(classDef, LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)))
getSupertypesGraph(LinkToType(selfSignature, classDef.symbol.dri, bareClasslikeKind(classDef.symbol)), unpackTreeToClassDef(classDef).parents)
)

val baseMember = mkMember(classDef.symbol, kindForClasslike(classDef), selfSignature)(
Expand Down Expand Up @@ -255,7 +257,7 @@ trait ClassLikeSupport:
case t: TypeTree => t.tpe.typeSymbol
case tree if tree.symbol.isClassConstructor => tree.symbol.owner
case tree => tree.symbol
if parentSymbol != defn.ObjectClass && parentSymbol != defn.AnyClass
if parentSymbol != defn.ObjectClass && parentSymbol != defn.AnyClass && !parentSymbol.isHiddenByVisibility
yield (parentTree, parentSymbol)

def getConstructors: List[Symbol] = c.membersToDocument.collect {
Expand Down
4 changes: 3 additions & 1 deletion scaladoc/src/dotty/tools/scaladoc/tasty/TypesSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ trait TypesSupport:
extension (on: SignaturePart) def l: List[SignaturePart] = List(on)

private def tpe(using Quotes)(symbol: reflect.Symbol): SSignature =
import SymOps._
val suffix = if symbol.isValDef || symbol.flags.is(reflect.Flags.Module) then plain(".type").l else Nil
dotty.tools.scaladoc.Type(symbol.normalizedName, Some(symbol.dri)) :: suffix
val dri: Option[DRI] = Option(symbol).filterNot(_.isHiddenByVisibility).map(_.dri)
dotty.tools.scaladoc.Type(symbol.normalizedName, dri) :: suffix

private def commas(lists: List[SSignature]) = lists match
case List(single) => single
Expand Down