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

Nondeterministic compiler crash on clean compile (ClassCastException: PolyType, CachedTermRef) #16884

Closed
hnaderi opened this issue Feb 10, 2023 · 8 comments · Fixed by #16901
Closed

Comments

@hnaderi
Copy link

hnaderi commented Feb 10, 2023

Compiler version

I tried with these versions
3.2.2 ,3.2.1, 3.2.0

Minimized code

I couldn't reproduce an independent minimized code yet, as it is hard to check whether the issue is gone or is not appearing due to some other change.

Output (click arrow to expand)

[error] java.lang.ClassCastException: dotty.tools.dotc.core.Types$CachedTermRef cannot be cast to dotty.tools.dotc.core.Types$PolyType [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:352) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:324) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507) [error] scala.collection.immutable.List.mapConserve(List.scala:472) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:323) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1406) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformSelect(PostTyper.scala:207) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:356) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:324) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1406) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformSelect(PostTyper.scala:207) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:356) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:324) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1434) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:283) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507) [error] scala.collection.immutable.List.mapConserve(List.scala:472) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformSub(Trees.scala:1511) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1432) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1478) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$5(PostTyper.scala:384) [error] dotty.tools.dotc.transform.SuperAccessors.wrapDefDef(SuperAccessors.scala:223) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:384) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1230) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507) [error] scala.collection.immutable.List.mapConserve(List.scala:472) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:323) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1478) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$5(PostTyper.scala:384) [error] dotty.tools.dotc.transform.SuperAccessors.wrapDefDef(SuperAccessors.scala:223) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:384) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1230) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507) [error] scala.collection.immutable.List.mapConserve(List.scala:472) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:323) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1478) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$5(PostTyper.scala:384) [error] dotty.tools.dotc.transform.SuperAccessors.wrapDefDef(SuperAccessors.scala:223) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:384) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1230) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507) [error] scala.collection.immutable.List.mapConserve(List.scala:472) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:323) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock$$anonfun$1$$anonfun$1(tpd.scala:1230) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1212) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformBlock(tpd.scala:1230) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1426) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:49) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$1(Trees.scala:1507) [error] scala.collection.immutable.List.mapConserve(List.scala:472) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1507) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:323) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.app1$1(PostTyper.scala:324) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:337) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1227) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:47) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$4$$anonfun$1(PostTyper.scala:371) [error] dotty.tools.dotc.transform.SuperAccessors.wrapTemplate(SuperAccessors.scala:208) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform$$anonfun$4(PostTyper.scala:371) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.withNoCheckNews(PostTyper.scala:104) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:373) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1480) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:411) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1227) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1488) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.loop$2(tpd.scala:1225) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1225) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transformStats(PostTyper.scala:474) [error] dotty.tools.dotc.ast.tpd$TreeMapWithPreciseStatContexts.transformStats(tpd.scala:1227) [error] dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1488) [error] dotty.tools.dotc.transform.MacroTransform$Transformer.transform(MacroTransform.scala:40) [error] dotty.tools.dotc.transform.PostTyper$PostTyperTransformer.transform(PostTyper.scala:465) [error] dotty.tools.dotc.transform.MacroTransform.run(MacroTransform.scala:18) [error] dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316) [error] scala.collection.immutable.List.map(List.scala:250) [error] dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:320) [error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:238) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15) [error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10) [error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321) [error] dotty.tools.dotc.Run.runPhases$1(Run.scala:249) [error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:257) [error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:266) [error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68) [error] dotty.tools.dotc.Run.compileUnits(Run.scala:266) [error] dotty.tools.dotc.Run.compileSources(Run.scala:190) [error] dotty.tools.dotc.Run.compile(Run.scala:174) [error] dotty.tools.dotc.Driver.doCompile(Driver.scala:35) [error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88) [error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22) [error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193) [error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) [error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183) [error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163) [error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239) [error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163) [error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:179) [error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:177) [error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:463) [error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56) [error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52) [error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263) [error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:418) [error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506) [error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:405) [error] sbt.internal.inc.Incremental$.apply(Incremental.scala:171) [error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534) [error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488) [error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332) [error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425) [error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137) [error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2363) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2313) [error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30) [error] sbt.internal.io.Retry$.apply(Retry.scala:46) [error] sbt.internal.io.Retry$.apply(Retry.scala:28) [error] sbt.internal.io.Retry$.apply(Retry.scala:23) [error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30) [error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2311) [error] scala.Function1.$anonfun$compose$1(Function1.scala:49) [error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62) [error] sbt.std.Transform$$anon$4.work(Transform.scala:68) [error] sbt.Execute.$anonfun$submit$2(Execute.scala:282) [error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23) [error] sbt.Execute.work(Execute.scala:291) [error] sbt.Execute.$anonfun$submit$1(Execute.scala:282) [error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265) [error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64) [error] java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [error] java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [error] java.lang.Thread.run(Thread.java:750) [error] (clientJS / Test / compileIncremental) java.lang.ClassCastException: dotty.tools.dotc.core.Types$CachedTermRef cannot be cast to dotty.tools.dotc.core.Types$PolyType
@hnaderi hnaderi added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 10, 2023
@SethTisue
Copy link
Member

"ClassCastException: dotty.tools.dotc.core.Types$CachedTermRef cannot be cast to dotty.tools.dotc.core.Types$PolyType" isn't one I've seen before. at minimum, perhaps others who see the same error will search and land here and perhaps have some insight

you seem to have double-pasted the stack trace; mind cleaning that up?

@SethTisue SethTisue changed the title Nondeterministic compiler crash on clean compile Nondeterministic compiler crash on clean compile (ClassCastException: PolyType, CachedTermRef) Feb 10, 2023
@SethTisue
Copy link
Member

SethTisue commented Feb 10, 2023

perhaps once #16593 lands you'll be able to include more useful diagnostic information in the report (and that might help with minimizing, too... minimizing it is the usual path towards an actual fix)

@hnaderi
Copy link
Author

hnaderi commented Feb 10, 2023

you seem to have double-pasted the stack trace; mind cleaning that up?

Oops! thanks for pointing out that, just cleaned it up.

@smarter
Copy link
Member

smarter commented Feb 10, 2023

Is the crash happening on a public codebase you could link us to? That could help us investigate the issue without a minimization.

@hnaderi
Copy link
Author

hnaderi commented Feb 11, 2023

Yes, it's an opensource project.
I created a separate branch that contains the error here https://github.com/hnaderi/lepus/tree/compiler-crash
This issue was introduced here probably (9bf4a9f8584de525c602e980e3a7eec788f647b5)
The problem seems to be residing in this specific file https://github.com/hnaderi/lepus/blob/compiler-crash/modules/client/src/test/scala/internal/ChannelOutputSuite.scala

How to reproduce:

  • [project rootJVM]
  • clean
  • test

It might take a few retries to see the error happening.
The error can be seen on these CI jobs as well:
https://github.com/hnaderi/lepus/actions/runs/4142125900/jobs/7162428494#step:12:66
https://github.com/hnaderi/lepus/actions/runs/4150091032
https://github.com/hnaderi/lepus/actions/runs/4142125900
https://github.com/hnaderi/lepus/actions/runs/4142131777

@smarter
Copy link
Member

smarter commented Feb 11, 2023

Thanks, it seems that the issue is easier to reproduce if I reduce the size of the heap by setting -Xmx1G in the project .jvmopts, then it usually happens after a couple of call to clientJVM/clean;clientJVM/Test/compile.

The crash happens on https://github.com/hnaderi/lepus/blob/fecc7c7e793b98b9f9a85eac89856ee51baf2b6a/modules/client/src/test/scala/internal/ChannelOutputSuite.scala#L97 when PostTyper sees out.writeOne(1).timeout: sometimes the denotation of timeout is an overloaded denotation, which makes no sense since overloading should have been resolved in Typer.

This appears to be due to cache pollution: TermRef(..., timeout) is created/read from cache in https://github.com/lampepfl/dotty/blob/3d251d6fd1bb1e98d66760ee50b824861a87ca57/compiler/src/dotty/tools/dotc/typer/Typer.scala#L619 which delegates to https://github.com/lampepfl/dotty/blob/3d251d6fd1bb1e98d66760ee50b824861a87ca57/compiler/src/dotty/tools/dotc/core/Types.scala#L2921-L2922

Sometimes, the apply pulls a previous TermRef from cache which has a non-overloaded denotation and the call to withDenot overwrites it with an overloaded denotation. There are two overloads of timeout in IO, but only one is accessible. So our type's denotation gets fixed in typedSelect afterwards by:
https://github.com/lampepfl/dotty/blob/3d251d6fd1bb1e98d66760ee50b824861a87ca57/compiler/src/dotty/tools/dotc/typer/Typer.scala#L620
which delegates to:
https://github.com/lampepfl/dotty/blob/3d251d6fd1bb1e98d66760ee50b824861a87ca57/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala#L86
Usually, this second call to withDenot will overwrite the overloaded denotation in the TermRef we previously pulled from the cache, thus masking the issue, but I guess sometimes we instead end up copying the TermRef?

IMO, withDenot should never mutate types, the risk of cache pollution is too high and we end up with impossible to debug issues like this one, but short of changing that I don't know how to proceed /cc @odersky .

@smarter smarter added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 11, 2023
@smarter smarter added this to the 3.3.1-RC1 milestone Feb 11, 2023
@odersky
Copy link
Contributor

odersky commented Feb 11, 2023

IMO, withDenot should never mutate types, the risk of cache pollution is too high and we end up with impossible to debug issues like this one, but short of changing that I don't know how to proceed /cc @odersky .

That must have been hard to spot! But I am not sure it's the mutation itself which is to blame. If withDenot would not mutate the type but create a fresh copy instead, the end result would be the same. The fresh copy is hashed to be the same as the old one and the denotation will be overwritten. So I don't see how that should work.

@odersky
Copy link
Contributor

odersky commented Feb 11, 2023

One idea could be to copy the TermRef for a withDenot if the previous designator is a name and the denotation has a symbol.

EDIT: In fact, that happens already. But the opposite does not: If the previous designatore is a symbol and the denotation is overloaded, we keep the symbol. 16324c1 tries to use the name instead.

odersky added a commit to dotty-staging/dotty that referenced this issue Feb 13, 2023
When creating a NamedType with a given overloaded denotation, make sure that
the type has a Name as designator. This prevents accidentally overwriting a more
precise symbolic TermRef that refers to one specific alternative of the denotation.

This might be enough to fix scala#16884.

It would be great if we could maintain the general invariant that NamedTypes with
overloaded denotations always have names as designators. But that looks very hard
when we take into account that we need to update named types to new runs.
A type might have a single denotation in one round and an overloaded one in the
next.
odersky added a commit to dotty-staging/dotty that referenced this issue Feb 13, 2023
When creating a NamedType with a given overloaded denotation, make sure that
the type has a Name as designator. This prevents accidentally overwriting a more
precise symbolic TermRef that refers to one specific alternative of the denotation.

This might be enough to fix scala#16884.

It would be great if we could maintain the general invariant that NamedTypes with
overloaded denotations always have names as designators. But that looks very hard
when we take into account that we need to update named types to new runs.
A type might have a single denotation in one round and an overloaded one in the
next.
smarter added a commit that referenced this issue Feb 16, 2023
When creating a NamedType with a given overloaded denotation, make sure
that the type has a Name as designator. This prevents accidentally
overwriting a more precise symbolic TermRef that refers to one specific
alternative of the denotation.

This might be enough to fix #16884.

EDIT: It wasn't enough but the second commit
[46e82dd](46e82dd)
should fix it. The second commit never overwrites in `withDenot`. It can
do that because we fix `infoDependsOnPrefix` to work correctly for
abstract types that are refined in a self type. It turned out that
previously we needed some TypeRefs to keep their Name designators
because that way we would recompute their info with a `member`
operation. If these TypeRefs had a symbol designator they would be
recomputed wrongly by `symd.current` in `fromDesignator` because the
preceding `infoDependsOnPrefix` test was faulty.

It would be great if we could maintain the general invariant that
NamedTypes with overloaded denotations always have names as designators.
But that looks very hard when we take into account that we need to
update named types to new runs. A type might have a single denotation in
one round and an overloaded one in the next.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants