Skip to content

Commit c7490a2

Browse files
committed
try always typecheck for SourcefileLoader
1 parent f176116 commit c7490a2

File tree

10 files changed

+34
-18
lines changed

10 files changed

+34
-18
lines changed

compiler/src-bootstrapped/b/Bar.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package b
2+
3+
object Bar:
4+
inline def bar = Foo.foo

compiler/src-bootstrapped/b/zz.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package b
2+
3+
object Foo:
4+
inline def foo =
5+
???

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object SymbolLoaders {
119119
* All entered symbols are given a source completer of `src` as info.
120120
*/
121121
def enterToplevelsFromSource(
122-
owner: Symbol, name: PreName, src: AbstractFile,
122+
owner: Symbol, src: AbstractFile,
123123
scope: Scope = EmptyScope)(using Context): Unit =
124124
if src.exists && !src.isDirectory then
125125
val completer = new SourcefileLoader(src)
@@ -193,10 +193,10 @@ object SymbolLoaders {
193193
((classRep.binary, classRep.source): @unchecked) match {
194194
case (Some(bin), Some(src)) if needCompile(bin, src) && !binaryOnly(owner, nameOf(classRep)) =>
195195
if (ctx.settings.verbose.value) report.inform("[symloader] picked up newer source file for " + src.path)
196-
enterToplevelsFromSource(owner, nameOf(classRep), src)
196+
enterToplevelsFromSource(owner, src)
197197
case (None, Some(src)) =>
198198
if (ctx.settings.verbose.value) report.inform("[symloader] no class, picked up source file for " + src.path)
199-
enterToplevelsFromSource(owner, nameOf(classRep), src)
199+
enterToplevelsFromSource(owner, src)
200200
case (Some(bin), _) =>
201201
enterClassAndModule(owner, nameOf(classRep), ctx.platform.newClassLoader(bin))
202202
}
@@ -271,8 +271,8 @@ object SymbolLoaders {
271271
for (classRep <- classReps)
272272
if (!maybeModuleClass(classRep) && hasFlatName(classRep) == flat &&
273273
(!flat || isAbsent(classRep))) // on 2nd enter of flat names, check that the name has not been entered before
274-
if packageName == "a" then
275-
report.echo(s"initialising ${classRep} for ${root.symbol} in package $packageName")
274+
if packageName == "a" || packageName == "b" then
275+
report.echo(s"initialising ${classRep} for ${root.symbol} [${root.symbol.id}] in package $packageName")
276276
initializeFromClassPath(root.symbol, classRep)
277277
for (classRep <- classReps)
278278
if (maybeModuleClass(classRep) && hasFlatName(classRep) == flat &&
@@ -431,7 +431,7 @@ class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader {
431431
def description(using Context): String = "source file " + srcfile.toString
432432
override def sourceFileOrNull: AbstractFile = srcfile
433433
def doComplete(root: SymDenotation)(using Context): Unit =
434-
ctx.run.lateCompile(srcfile, typeCheck = ctx.settings.YretainTrees.value)
434+
ctx.run.lateCompile(srcfile, typeCheck = true) // TODO: or if sourcePath is enabled?
435435
}
436436

437437
/** A NoCompleter which is also a SymbolLoader. */

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ import config.Printers.typr
3737

3838
object SymbolCapturing {
3939
def ids = Set(
40-
2844, // a.Foo$.foo (before)
41-
2756, // a.Foo (before)
42-
4949, // a.Foo$.foo (after)
43-
2756, // a.Foo (after)
40+
2757, // a.Foo$ (before (from source /library/src-bootstrapped/b/zz.scala))
41+
2758, // a.Foo (before (from source /library/src-bootstrapped/b/zz.scala))
42+
2845, // a.Foo$.foo (before (from source /library/src-bootstrapped/b/zz.scala))
43+
4947, // a.Foo$.foo (after)
44+
6464, // b.Foo.foo (after (from source /compiler/src-bootstrapped/b/zz.scala))
45+
6109, // b.Foo.foo (after (from tasty))
46+
2762, // b.Foo (after (from tasty))
4447
)
4548
def doCapture(sym: Symbol): Boolean = ids.contains(sym.id)
4649
}

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class TreeUnpickler(reader: TastyReader,
117117
val owner = ctx.owner
118118
val source = ctx.source
119119
def complete(denot: SymDenotation)(using Context): Unit =
120+
if SymbolCapturing.doCapture(denot.symbol) then
121+
val trace = if denot.symbol.tracer != null then s"created: ${denot.symbol.tracer}" else "no trace"
122+
report.echo(i"forcing ${denot.kindString} ${denot.symbol.fullName} from source ${denot.symbol.denot.fullName} [id? ${denot.symbol.id}, trace? $trace]")
120123
treeAtAddr(currentAddr) = atPhaseBeforeTransforms {
121124
new TreeReader(reader).readIndexedDef()(
122125
using ctx.withOwner(owner).withSource(source))

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

+3
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
719719
seenInlines += sym // dont re-enter hashing this ref
720720
sym.defTree match
721721
case defTree: ValOrDefDef =>
722+
val trace = if sym.tracer != null then s"created at: ${sym.tracer}" else "no tracer"
723+
val infoTrace = if sym.denot.infoTracer != null then s"info assigned at: ${sym.denot.infoTracer}" else "no info tracer"
724+
// h = err(i"#### FALSE ALARM `${ref.name}` [tree? ${tree.show}, symId? ${sym.id}, defined in ${sym.owner.id} [${sym.owner}], run? ${sym.runUUID}, $trace, $infoTrace]", ref.name, ref, h)
722725
h = inlineReferenceHash(sym, defTree.rhs, h)
723726
case tree =>
724727
val trace = if sym.tracer != null then s"created at: ${sym.tracer}" else "no tracer"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ class Namer { typer: Typer =>
12571257
override def completeInCreationContext(denot: SymDenotation): Unit = {
12581258
if SymbolCapturing.doCapture(cls) then
12591259
val trace = if cls.tracer != null then s"created: ${cls.tracer}" else "no trace"
1260-
report.echo(i"forcing class ${cls.denot.fullName} [id? ${cls.id}, trace? $trace]")
1260+
report.echo(i"forcing class from source ${cls.denot.fullName} [id? ${cls.id}, trace? $trace]")
12611261
val parents = impl.parents
12621262

12631263
/* The type of a parent constructor. Types constructor arguments

library/src-bootstrapped/a/Bar.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package a
2+
3+
object Bar:
4+
inline def bar = Foo.foo

library/src-bootstrapped/a/b/Bar.scala

-5
This file was deleted.

library/src-bootstrapped/a/zz.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package a
22

33
object Foo:
4-
inline def foo: Nothing =
5-
???
4+
inline def foo =
65
???
76
???

0 commit comments

Comments
 (0)