Skip to content

Commit b57b358

Browse files
committed
Fix documentation generation from tasty with sourcepath
When running scaladoc with `-from-tasty` and `-sourcepath`, documentation generation failed with capture checking errors and ambiguous reference errors. Two issues were identified and fixed: 1. Capture checking was re-running on already capture-checked code from tasty, causing spurious errors. Now `ccEnabled` and `ccEnabledSomewhere` return false when `-from-tasty` is set. 2. Source files from the sourcepath were being loaded and their symbols entered, conflicting with symbols already loaded from tasty. Now `initializeFromClassPath` skips source file symbol loading when `-from-tasty` is set. Additionally, the `classExistsOnSelf` check in Typer is skipped when compiling from tasty to avoid false positives from re-typechecking.
1 parent 6462d7d commit b57b358

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,27 @@ object Feature:
140140
|| ctx.compilationUnit.knowsPureFuns
141141
|| ccEnabled
142142

143-
/** Is captureChecking enabled for this compilation unit? */
143+
/** Is captureChecking enabled for this compilation unit?
144+
* Disabled when compiling from tasty since capture checking was already performed.
145+
*/
144146
def ccEnabled(using Context) =
145-
enabledBySetting(captureChecking)
146-
|| ctx.originalCompilationUnit.needsCaptureChecking
147+
!ctx.settings.fromTasty.value
148+
&& (enabledBySetting(captureChecking)
149+
|| ctx.originalCompilationUnit.needsCaptureChecking)
147150

148151
/** Is pureFunctions enabled for any of the currently compiled compilation units? */
149152
def pureFunsEnabledSomewhere(using Context) =
150153
enabledBySetting(pureFunctions)
151154
|| ctx.run != null && ctx.run.nn.pureFunsImportEncountered
152155
|| ccEnabledSomewhere
153156

154-
/** Is captureChecking enabled for any of the currently compiled compilation units? */
157+
/** Is captureChecking enabled for any of the currently compiled compilation units?
158+
* Disabled when compiling from tasty since capture checking was already performed.
159+
*/
155160
def ccEnabledSomewhere(using Context) =
156-
if ctx.run != null then ctx.run.nn.ccEnabledSomewhere
157-
else enabledBySetting(captureChecking)
161+
!ctx.settings.fromTasty.value
162+
&& (if ctx.run != null then ctx.run.nn.ccEnabledSomewhere
163+
else enabledBySetting(captureChecking))
158164

159165
def sourceVersionSetting(using Context): SourceVersion =
160166
SourceVersion.valueOf(ctx.settings.source.value)

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,23 @@ object SymbolLoaders {
210210
/** Initialize toplevel class and module symbols in `owner` from class path representation `classRep`
211211
*/
212212
def initializeFromClassPath(owner: Symbol, classRep: ClassRepresentation)(using Context): Unit =
213+
// When compiling from tasty, don't enter symbols from source files - they would conflict
214+
// with symbols already loaded from tasty. Source files on the sourcepath are only used
215+
// for documentation comments, not for symbol loading.
216+
val skipSourceLoading = ctx.settings.fromTasty.value
213217
((classRep.binary, classRep.source): @unchecked) match {
214-
case (Some(bin), Some(src)) if needCompile(bin, src) && !binaryOnly(owner, nameOf(classRep)) =>
218+
case (Some(bin), Some(src)) if !skipSourceLoading && needCompile(bin, src) && !binaryOnly(owner, nameOf(classRep)) =>
215219
if (ctx.settings.verbose.value) report.inform("[symloader] picked up newer source file for " + src.path)
216220
enterToplevelsFromSource(owner, nameOf(classRep), src)
217-
case (None, Some(src)) =>
221+
case (None, Some(src)) if !skipSourceLoading =>
218222
if (ctx.settings.verbose.value) report.inform("[symloader] no class or tasty, picked up source file for " + src.path)
219223
enterToplevelsFromSource(owner, nameOf(classRep), src)
220224
case (Some(bin), _) =>
221225
val completer =
222226
if bin.hasTastyExtension || bin.hasBetastyExtension then ctx.platform.newTastyLoader(bin)
223227
else ctx.platform.newClassLoader(bin)
224228
enterClassAndModule(owner, nameOf(classRep), completer)
229+
case _ => // source-only when skipSourceLoading is true - skip
225230
}
226231

227232
def needCompile(bin: AbstractFile, src: AbstractFile): Boolean =

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
33983398
constr1.symbol.resetFlag(Private)
33993399

34003400
val self1 = typed(self)(using ctx.outer).asInstanceOf[ValDef] // outer context where class members are not visible
3401-
if (self1.tpt.tpe.isError || classExistsOnSelf(cls.unforcedDecls, self1))
3401+
// Skip classExistsOnSelf check when compiling from tasty - this check can produce
3402+
// false positives when re-typechecking code that was already validated
3403+
if (self1.tpt.tpe.isError || (!ctx.settings.fromTasty.value && classExistsOnSelf(cls.unforcedDecls, self1)))
34023404
// fail fast to avoid typing the body with an error type
34033405
cdef.withType(UnspecifiedErrorType)
34043406
else {

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ object Build {
13121312
lazy val `scala-library-bootstrapped` = project.in(file("library"))
13131313
.enablePlugins(ScalaLibraryPlugin)
13141314
.settings(publishSettings)
1315-
.settings(disableDocSetting) // TODO now produces empty JAR to satisfy Sonatype, see https://github.com/scala/scala3/issues/24434
1315+
//.settings(disableDocSetting) // TODO now produces empty JAR to satisfy Sonatype, see https://github.com/scala/scala3/issues/24434
13161316
.settings(
13171317
name := "scala-library-bootstrapped",
13181318
moduleName := "scala-library",

0 commit comments

Comments
 (0)